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
|
|---|---|---|---|---|---|---|---|---|---|---|
LSN
|
import torch
from torch import Tensor
import torch.nn as nn
import torch.utils.data
import torch.nn.parallel
import torch.nn.functional as F
class LSN(nn.Module):
""" Custom Linear layer that modifies standard ReLU layer"""
__constants__ = ['inplace']
inplace: 'bool'
def __init__(self, scale: 'int'=20000, inplace: 'bool'=False):
super(LSN, self).__init__()
self.inplace = inplace
self.scale = scale
def forward(self, input: 'Tensor') ->Tensor:
y_relu = F.relu(input, inplace=self.inplace)
num = y_relu * self.scale
denom = torch.sum(y_relu)
return num / (denom + 1e-08)
def extra_repr(self) ->str:
inplace_str = 'inplace=True' if self.inplace else ''
return inplace_str
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
import torch.utils.data
import torch.nn.parallel
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_add_div_mul_relu_sum_0(in_ptr0, out_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.full([1], 0, tl.int32)
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp3 = tl.broadcast_to(tmp2, [RBLOCK])
tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0))
tmp6 = 20000.0
tmp7 = tmp2 * tmp6
tmp8 = 1e-08
tmp9 = tmp5 + tmp8
tmp10 = tmp7 / tmp9
tl.store(out_ptr1 + tl.broadcast_to(r0, [RBLOCK]), tmp10, 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)
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_per_fused_add_div_mul_relu_sum_0[grid(1)](arg0_1, buf1, 1,
256, num_warps=2, num_stages=1)
del arg0_1
return buf1,
class LSNNew(nn.Module):
""" Custom Linear layer that modifies standard ReLU layer"""
__constants__ = ['inplace']
inplace: 'bool'
def __init__(self, scale: 'int'=20000, inplace: 'bool'=False):
super(LSNNew, self).__init__()
self.inplace = inplace
self.scale = scale
def extra_repr(self) ->str:
inplace_str = 'inplace=True' if self.inplace else ''
return inplace_str
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
SindiLab/ACTIVA
|
LSN
| false
| 17,923
|
[
"MIT"
] | 6
|
599f57478c5e13868d27879632c54964bf7b02ad
|
https://github.com/SindiLab/ACTIVA/tree/599f57478c5e13868d27879632c54964bf7b02ad
|
EncoderImagePrecomp
|
import torch
import numpy as np
from torch import nn
from collections import OrderedDict
import torch.nn.init
def l2norm(X):
"""L2-normalize columns of X
"""
norm = torch.pow(X, 2).sum(dim=1, keepdim=True).sqrt()
X = torch.div(X, norm)
return X
class EncoderImagePrecomp(nn.Module):
def __init__(self, img_dim, embed_size, use_abs=False, no_imgnorm=False):
super(EncoderImagePrecomp, self).__init__()
self.embed_size = embed_size
self.no_imgnorm = no_imgnorm
self.use_abs = use_abs
self.fc = nn.Linear(img_dim, embed_size)
self.init_weights()
def init_weights(self):
"""Xavier initialization for the fully connected layer
"""
r = np.sqrt(6.0) / np.sqrt(self.fc.in_features + self.fc.out_features)
self.fc.weight.data.uniform_(-r, r)
self.fc.bias.data.fill_(0)
def forward(self, images):
"""Extract image feature vectors."""
features = self.fc(images)
if not self.no_imgnorm:
features = l2norm(features)
if self.use_abs:
features = torch.abs(features)
return features
def load_state_dict(self, state_dict):
"""Copies parameters. overwritting the default one to
accept state_dict from Full model
"""
own_state = self.state_dict()
new_state = OrderedDict()
for name, param in state_dict.items():
if name in own_state:
new_state[name] = param
super(EncoderImagePrecomp, self).load_state_dict(new_state)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'img_dim': 4, 'embed_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
import numpy as np
from torch import nn
from collections import OrderedDict
import torch.nn.init
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_div_pow_sqrt_sum_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = tmp0 / tmp12
tl.store(out_ptr0 + x3, tmp13, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64,
4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0
), alpha=1, beta=1, out=buf0)
del primals_1
del primals_2
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_div_pow_sqrt_sum_0[grid(256)](buf0, buf1, 256,
XBLOCK=256, num_warps=4, num_stages=1)
return buf1, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf0
def l2norm(X):
"""L2-normalize columns of X
"""
norm = torch.pow(X, 2).sum(dim=1, keepdim=True).sqrt()
X = torch.div(X, norm)
return X
class EncoderImagePrecompNew(nn.Module):
def __init__(self, img_dim, embed_size, use_abs=False, no_imgnorm=False):
super(EncoderImagePrecompNew, self).__init__()
self.embed_size = embed_size
self.no_imgnorm = no_imgnorm
self.use_abs = use_abs
self.fc = nn.Linear(img_dim, embed_size)
self.init_weights()
def init_weights(self):
"""Xavier initialization for the fully connected layer
"""
r = np.sqrt(6.0) / np.sqrt(self.fc.in_features + self.fc.out_features)
self.fc.weight.data.uniform_(-r, r)
self.fc.bias.data.fill_(0)
def load_state_dict(self, state_dict):
"""Copies parameters. overwritting the default one to
accept state_dict from Full model
"""
own_state = self.state_dict()
new_state = OrderedDict()
for name, param in state_dict.items():
if name in own_state:
new_state[name] = param
super(EncoderImagePrecompNew, self).load_state_dict(new_state)
def forward(self, input_0):
primals_1 = self.fc.weight
primals_2 = self.fc.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
Shiyang-Yan/Discrete-continous-PG-for-Retrieval
|
EncoderImagePrecomp
| false
| 17,924
|
[
"Apache-2.0"
] | 8
|
39fd7a81f732ae043c2ea20352a0c55b72834639
|
https://github.com/Shiyang-Yan/Discrete-continous-PG-for-Retrieval/tree/39fd7a81f732ae043c2ea20352a0c55b72834639
|
SSSNET
|
import torch
from typing import Optional
from typing import Tuple
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.parameter import Parameter
from typing import Union
class SIMPA(nn.Module):
"""The signed mixed-path aggregation model.
Args:
hop (int): Number of hops to consider.
directed (bool, optional): Whether the input network is directed or not. (default: :obj:`False`)
"""
def __init__(self, hop: 'int', directed: 'bool'=False):
super(SIMPA, self).__init__()
self._hop_p = hop + 1
self._hop_n = int((1 + hop) * hop / 2)
self._undirected = not directed
if self._undirected:
self._w_p = Parameter(torch.FloatTensor(self._hop_p, 1))
self._w_n = Parameter(torch.FloatTensor(self._hop_n, 1))
self._reset_parameters_undirected()
else:
self._w_sp = Parameter(torch.FloatTensor(self._hop_p, 1))
self._w_sn = Parameter(torch.FloatTensor(self._hop_n, 1))
self._w_tp = Parameter(torch.FloatTensor(self._hop_p, 1))
self._w_tn = Parameter(torch.FloatTensor(self._hop_n, 1))
self._reset_parameters_directed()
def _reset_parameters_undirected(self):
self._w_p.data.fill_(1.0)
self._w_n.data.fill_(1.0)
def _reset_parameters_directed(self):
self._w_sp.data.fill_(1.0)
self._w_sn.data.fill_(1.0)
self._w_tp.data.fill_(1.0)
self._w_tn.data.fill_(1.0)
def forward(self, A_p:
'Union[torch.FloatTensor, torch.sparse_coo_tensor]', A_n:
'Union[torch.FloatTensor, torch.sparse_coo_tensor]', x_p:
'torch.FloatTensor', x_n: 'torch.FloatTensor', x_pt:
'Optional[torch.FloatTensor]'=None, x_nt:
'Optional[torch.FloatTensor]'=None, A_pt:
'Optional[Union[torch.FloatTensor, torch.sparse_coo_tensor]]'=None,
A_nt: 'Optional[Union[torch.FloatTensor, torch.sparse_coo_tensor]]'
=None) ->Tuple[torch.FloatTensor, torch.FloatTensor, torch.
LongTensor, torch.FloatTensor]:
"""
Making a forward pass of SIMPA.
Arg types:
* **A_p** (PyTorch FloatTensor or PyTorch sparse_coo_tensor) - Row-normalized positive part of the adjacency matrix.
* **A_n** (PyTorch FloatTensor or PyTorch sparse_coo_tensor) - Row-normalized negative part of the adjacency matrix.
* **x_p** (PyTorch FloatTensor) - Souce positive hidden representations.
* **x_n** (PyTorch FloatTensor) - Souce negative hidden representations.
* **x_pt** (PyTorch FloatTensor, optional) - Target positive hidden representations. Default: None.
* **x_nt** (PyTorch FloatTensor, optional) - Target negative hidden representations. Default: None.
* **A_pt** (PyTorch FloatTensor or PyTorch sparse_coo_tensor, optional) - Transpose of column-normalized
positive part of the adjacency matrix. Default: None.
* **A_nt** (PyTorch FloatTensor or PyTorch sparse_coo_tensor, optional) - Transpose of column-normalized
negative part of the adjacency matrix. Default: None.
Return types:
* **feat** (PyTorch FloatTensor) - Embedding matrix, with shape (num_nodes, 2*input_dim) for undirected graphs
and (num_nodes, 4*input_dim) for directed graphs.
"""
if self._undirected:
feat_p = self._w_p[0] * x_p
feat_n = torch.zeros_like(feat_p)
curr_p = x_p.clone()
curr_n_aux = x_n.clone()
j = 0
for h in range(0, self._hop_p):
if h > 0:
curr_p = torch.matmul(A_p, curr_p)
curr_n_aux = torch.matmul(A_p, curr_n_aux)
feat_p += self._w_p[h] * curr_p
if h != self._hop_p - 1:
curr_n = torch.matmul(A_n, curr_n_aux)
feat_n += self._w_n[j] * curr_n
j += 1
for _ in range(self._hop_p - 2 - h):
curr_n = torch.matmul(A_p, curr_n)
feat_n += self._w_n[j] * curr_n
j += 1
feat = torch.cat([feat_p, feat_n], dim=1)
else:
A_sp = A_p
A_sn = A_n
A_tp = A_pt
A_tn = A_nt
x_sp = x_p
x_sn = x_n
feat_sp = self._w_sp[0] * x_sp
feat_sn = torch.zeros_like(feat_sp)
feat_tp = self._w_tp[0] * x_pt
feat_tn = torch.zeros_like(feat_tp)
curr_sp = x_sp.clone()
curr_sn_aux = x_sn.clone()
curr_tp = x_pt.clone()
curr_tn_aux = x_nt.clone()
j = 0
for h in range(0, self._hop_p):
if h > 0:
curr_sp = torch.matmul(A_sp, curr_sp)
curr_sn_aux = torch.matmul(A_sp, curr_sn_aux)
curr_tp = torch.matmul(A_tp, curr_tp)
curr_tn_aux = torch.matmul(A_tp, curr_tn_aux)
feat_sp += self._w_sp[h] * curr_sp
feat_tp += self._w_tp[h] * curr_tp
if h != self._hop_p - 1:
curr_sn = torch.matmul(A_sn, curr_sn_aux)
curr_tn = torch.matmul(A_tn, curr_tn_aux)
feat_sn += self._w_sn[j] * curr_sn
feat_tn += self._w_tn[j] * curr_tn
j += 1
for _ in range(self._hop_p - 2 - h):
curr_sn = torch.matmul(A_sp, curr_sn)
curr_tn = torch.matmul(A_tp, curr_tn)
feat_sn += self._w_sn[j] * curr_sn
feat_tn += self._w_tn[j] * curr_tn
j += 1
feat = torch.cat([feat_sp, feat_sn, feat_tp, feat_tn], dim=1)
return feat
class SSSNET(nn.Module):
"""The signed graph clustering model.
Args:
nfeat (int): Number of features.
hidden (int): Hidden dimensions of the initial MLP.
nclass (int): Number of clusters.
dropout (float): Dropout probability.
hop (int): Number of hops to consider.
directed (bool, optional): Whether the input network is directed or not. (default: :obj:`False`)
bias (bool, optional): If set to :obj:`False`, the layer will not learn
an additive bias. (default: :obj:`True`)
"""
def __init__(self, nfeat: 'int', hidden: 'int', nclass: 'int', dropout:
'float', hop: 'int', directed: 'bool'=False, bias: 'bool'=True):
super(SSSNET, self).__init__()
nh1 = hidden
nh2 = hidden
self._num_clusters = int(nclass)
self._simpa = SIMPA(hop, directed)
if bias:
self._bias = Parameter(torch.FloatTensor(self._num_clusters))
else:
self.register_parameter('_bias', None)
self._relu = nn.ReLU()
self._dropout = nn.Dropout(p=dropout)
self._undirected = not directed
if self._undirected:
self._w_p0 = Parameter(torch.FloatTensor(nfeat, nh1))
self._w_p1 = Parameter(torch.FloatTensor(nh1, nh2))
self._w_n0 = Parameter(torch.FloatTensor(nfeat, nh1))
self._w_n1 = Parameter(torch.FloatTensor(nh1, nh2))
self._W_prob = Parameter(torch.FloatTensor(2 * nh2, self.
_num_clusters))
self._reset_parameters_undirected()
else:
self._w_sp0 = Parameter(torch.FloatTensor(nfeat, nh1))
self._w_sp1 = Parameter(torch.FloatTensor(nh1, nh2))
self._w_sn0 = Parameter(torch.FloatTensor(nfeat, nh1))
self._w_sn1 = Parameter(torch.FloatTensor(nh1, nh2))
self._w_tp0 = Parameter(torch.FloatTensor(nfeat, nh1))
self._w_tp1 = Parameter(torch.FloatTensor(nh1, nh2))
self._w_tn0 = Parameter(torch.FloatTensor(nfeat, nh1))
self._w_tn1 = Parameter(torch.FloatTensor(nh1, nh2))
self._W_prob = Parameter(torch.FloatTensor(4 * nh2, self.
_num_clusters))
self._reset_parameters_directed()
def _reset_parameters_undirected(self):
nn.init.xavier_uniform_(self._w_p0, gain=1.414)
nn.init.xavier_uniform_(self._w_p1, gain=1.414)
nn.init.xavier_uniform_(self._w_n0, gain=1.414)
nn.init.xavier_uniform_(self._w_n1, gain=1.414)
if self._bias is not None:
self._bias.data.fill_(0.0)
nn.init.xavier_uniform_(self._W_prob, gain=1.414)
def _reset_parameters_directed(self):
nn.init.xavier_uniform_(self._w_sp0, gain=1.414)
nn.init.xavier_uniform_(self._w_sp1, gain=1.414)
nn.init.xavier_uniform_(self._w_sn0, gain=1.414)
nn.init.xavier_uniform_(self._w_sn1, gain=1.414)
nn.init.xavier_uniform_(self._w_tp0, gain=1.414)
nn.init.xavier_uniform_(self._w_tp1, gain=1.414)
nn.init.xavier_uniform_(self._w_tn0, gain=1.414)
nn.init.xavier_uniform_(self._w_tn1, gain=1.414)
if self._bias is not None:
self._bias.data.fill_(0.0)
nn.init.xavier_uniform_(self._W_prob, gain=1.414)
def forward(self, A_p:
'Union[torch.FloatTensor, torch.sparse_coo_tensor]', A_n:
'Union[torch.FloatTensor, torch.sparse_coo_tensor]', features:
'torch.FloatTensor', A_pt:
'Optional[Union[torch.FloatTensor, torch.sparse_coo_tensor]]'=None,
A_nt: 'Optional[Union[torch.FloatTensor, torch.sparse_coo_tensor]]'
=None) ->Tuple[torch.FloatTensor, torch.FloatTensor, torch.
LongTensor, torch.FloatTensor]:
"""
Making a forward pass of the SSSNET.
Arg types:
* **A_p** (PyTorch FloatTensor or PyTorch sparse_coo_tensor) - Row-normalized positive part of the adjacency matrix.
* **A_n** (PyTorch FloatTensor or PyTorch sparse_coo_tensor) - Row-normalized negative part of the adjacency matrix.
* **features** (PyTorch FloatTensor) - Input node features, with shape (num_nodes, num_features).
* **A_pt** (PyTorch FloatTensor or PyTorch sparse_coo_tensor, optional) - Transpose of column-normalized
positive part of the adjacency matrix. Default: None.
* **A_nt** (PyTorch FloatTensor or PyTorch sparse_coo_tensor, optional) - Transpose of column-normalized
negative part of the adjacency matrix. Default: None.
Return types:
* **z** (PyTorch FloatTensor) - Embedding matrix, with shape (num_nodes, 2*hidden) for undirected graphs
and (num_nodes, 4*hidden) for directed graphs.
* **output** (PyTorch FloatTensor) - Log of prob, with shape (num_nodes, num_clusters).
* **predictions_cluster** (PyTorch LongTensor) - Predicted labels.
* **prob** (PyTorch FloatTensor) - Probability assignment matrix of different clusters, with shape (num_nodes, num_clusters).
"""
if self._undirected:
x_p = torch.mm(features, self._w_p0)
x_p = self._relu(x_p)
x_p = self._dropout(x_p)
x_p = torch.mm(x_p, self._w_p1)
x_n = torch.mm(features, self._w_n0)
x_n = self._relu(x_n)
x_n = self._dropout(x_n)
x_n = torch.mm(x_n, self._w_n1)
z = self._simpa(A_p, A_n, x_p, x_n)
else:
x_sp = torch.mm(features, self._w_sp0)
x_sp = self._relu(x_sp)
x_sp = self._dropout(x_sp)
x_sp = torch.mm(x_sp, self._w_sp1)
x_sn = torch.mm(features, self._w_sn0)
x_sn = self._relu(x_sn)
x_sn = self._dropout(x_sn)
x_sn = torch.mm(x_sn, self._w_sn1)
x_tp = torch.mm(features, self._w_tp0)
x_tp = self._relu(x_tp)
x_tp = self._dropout(x_tp)
x_tp = torch.mm(x_tp, self._w_tp1)
x_tn = torch.mm(features, self._w_tn0)
x_tn = self._relu(x_tn)
x_tn = self._dropout(x_tn)
x_tn = torch.mm(x_tn, self._w_tn1)
z = self._simpa(A_p, A_n, x_sp, x_sn, x_tp, x_tn, A_pt, A_nt)
output = torch.mm(z, self._W_prob)
if self._bias is not None:
output = output + self._bias
predictions_cluster = torch.argmax(output, dim=1)
prob = F.softmax(output, dim=1)
output = F.log_softmax(output, dim=1)
return F.normalize(z), output, predictions_cluster, prob
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4]), torch.rand([4, 4])]
def get_init_inputs():
return [[], {'nfeat': 4, 'hidden': 4, 'nclass': 4, 'dropout': 0.5,
'hop': 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
from typing import Optional
from typing import Tuple
import torch.nn as nn
from torch.nn.parameter import Parameter
from typing import Union
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_relu_0(in_out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.full([1], 0, tl.int32)
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tl.store(in_out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused_add_mul_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
in_ptr5, in_ptr6, in_ptr7, in_ptr8, in_ptr9, in_ptr10, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
x1 = xindex % 4
x2 = xindex // 4
tmp0 = tl.load(in_ptr0 + 0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
tmp2 = tl.load(in_ptr1 + x0, xmask)
tmp4 = tl.load(in_ptr0 + 1)
tmp5 = tl.broadcast_to(tmp4, [XBLOCK])
tmp6 = tl.load(in_ptr2 + x0, xmask)
tmp9 = tl.load(in_ptr0 + 2)
tmp10 = tl.broadcast_to(tmp9, [XBLOCK])
tmp11 = tl.load(in_ptr3 + x0, xmask)
tmp14 = tl.load(in_ptr0 + 3)
tmp15 = tl.broadcast_to(tmp14, [XBLOCK])
tmp16 = tl.load(in_ptr4 + x0, xmask)
tmp19 = tl.load(in_ptr0 + 4)
tmp20 = tl.broadcast_to(tmp19, [XBLOCK])
tmp21 = tl.load(in_ptr5 + x0, xmask)
tmp24 = tl.load(in_ptr0 + 5)
tmp25 = tl.broadcast_to(tmp24, [XBLOCK])
tmp26 = tl.load(in_ptr6 + x0, xmask)
tmp29 = tl.load(in_ptr0 + 6)
tmp30 = tl.broadcast_to(tmp29, [XBLOCK])
tmp31 = tl.load(in_ptr7 + x0, xmask)
tmp34 = tl.load(in_ptr0 + 7)
tmp35 = tl.broadcast_to(tmp34, [XBLOCK])
tmp36 = tl.load(in_ptr8 + x0, xmask)
tmp39 = tl.load(in_ptr0 + 8)
tmp40 = tl.broadcast_to(tmp39, [XBLOCK])
tmp41 = tl.load(in_ptr9 + x0, xmask)
tmp44 = tl.load(in_ptr0 + 9)
tmp45 = tl.broadcast_to(tmp44, [XBLOCK])
tmp46 = tl.load(in_ptr10 + x0, xmask)
tmp3 = tmp1 * tmp2
tmp7 = tmp5 * tmp6
tmp8 = tmp3 + tmp7
tmp12 = tmp10 * tmp11
tmp13 = tmp8 + tmp12
tmp17 = tmp15 * tmp16
tmp18 = tmp13 + tmp17
tmp22 = tmp20 * tmp21
tmp23 = tmp18 + tmp22
tmp27 = tmp25 * tmp26
tmp28 = tmp23 + tmp27
tmp32 = tmp30 * tmp31
tmp33 = tmp28 + tmp32
tmp37 = tmp35 * tmp36
tmp38 = tmp33 + tmp37
tmp42 = tmp40 * tmp41
tmp43 = tmp38 + tmp42
tmp47 = tmp45 * tmp46
tmp48 = tmp43 + tmp47
tl.store(out_ptr0 + (x1 + 8 * x2), tmp48, xmask)
@triton.jit
def triton_poi_fused_add_mul_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
in_ptr5, 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
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + 0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
tmp2 = tl.load(in_ptr1 + x2, xmask)
tmp4 = tl.load(in_ptr0 + 1)
tmp5 = tl.broadcast_to(tmp4, [XBLOCK])
tmp6 = tl.load(in_ptr2 + x2, xmask)
tmp9 = tl.load(in_ptr0 + 2)
tmp10 = tl.broadcast_to(tmp9, [XBLOCK])
tmp11 = tl.load(in_ptr3 + x2, xmask)
tmp14 = tl.load(in_ptr0 + 3)
tmp15 = tl.broadcast_to(tmp14, [XBLOCK])
tmp16 = tl.load(in_ptr4 + x2, xmask)
tmp19 = tl.load(in_ptr0 + 4)
tmp20 = tl.broadcast_to(tmp19, [XBLOCK])
tmp21 = tl.load(in_ptr5 + x2, xmask)
tmp3 = tmp1 * tmp2
tmp7 = tmp5 * tmp6
tmp8 = tmp3 + tmp7
tmp12 = tmp10 * tmp11
tmp13 = tmp8 + tmp12
tmp17 = tmp15 * tmp16
tmp18 = tmp13 + tmp17
tmp22 = tmp20 * tmp21
tmp23 = tmp18 + tmp22
tl.store(out_ptr0 + (x0 + 8 * x1), tmp23, xmask)
@triton.jit
def triton_poi_fused_argmax_3(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')
tmp17 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp32 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
)
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)
@triton.jit
def triton_poi_fused__softmax_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = 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__softmax_5(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp2 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last'
)
tmp1 = tl_math.exp(tmp0)
tmp3 = tl_math.exp(tmp2)
tmp5 = tl_math.exp(tmp4)
tmp6 = tmp3 + tmp5
tmp8 = tl_math.exp(tmp7)
tmp9 = tmp6 + tmp8
tmp11 = tl_math.exp(tmp10)
tmp12 = tmp9 + tmp11
tmp13 = tmp1 / tmp12
tmp14 = tl_math.log(tmp12)
tmp15 = tmp0 - tmp14
tl.store(out_ptr0 + x2, tmp13, xmask)
tl.store(out_ptr1 + x2, tmp15, xmask)
@triton.jit
def triton_per_fused_div_linalg_vector_norm_6(in_out_ptr0, in_ptr0,
out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 4
RBLOCK: tl.constexpr = 8
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 + 8 * x0), xmask, other=0.0)
tmp1 = tmp0 * tmp0
tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp4 = tl.where(xmask, tmp2, 0)
tmp5 = tl.sum(tmp4, 1)[:, None]
tmp6 = libdevice.sqrt(tmp5)
tmp7 = 1e-12
tmp8 = triton_helpers.maximum(tmp6, tmp7)
tmp9 = tmp0 / tmp8
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp6, xmask)
tl.store(out_ptr0 + (r1 + 8 * x0), tmp9, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11) = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4, 4), (4, 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, 4), (4, 1))
assert_size_stride(primals_6, (5, 1), (1, 1))
assert_size_stride(primals_7, (4, 4), (4, 1))
assert_size_stride(primals_8, (10, 1), (1, 1))
assert_size_stride(primals_9, (4, 4), (4, 1))
assert_size_stride(primals_10, (8, 4), (4, 1))
assert_size_stride(primals_11, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_2, primals_1, out=buf0)
del primals_1
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_relu_0[grid(16)](buf1, 16, XBLOCK=16, num_warps=1,
num_stages=1)
buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf1, primals_3, out=buf2)
buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_2, primals_4, out=buf3)
del primals_4
buf4 = buf3
del buf3
triton_poi_fused_relu_0[grid(16)](buf4, 16, XBLOCK=16, num_warps=1,
num_stages=1)
buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf4, primals_5, out=buf5)
buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_7, buf5, out=buf6)
buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_9, buf6, out=buf7)
buf8 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_9, buf7, out=buf8)
buf9 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_9, buf8, out=buf9)
buf10 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_9, buf2, out=buf10)
buf11 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_9, buf5, out=buf11)
buf12 = buf5
del buf5
extern_kernels.mm(primals_7, buf11, out=buf12)
buf14 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_9, buf12, out=buf14)
buf15 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_9, buf14, out=buf15)
buf17 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_9, buf11, out=buf17)
buf18 = buf11
del buf11
extern_kernels.mm(primals_7, buf17, out=buf18)
buf19 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_9, buf18, out=buf19)
buf22 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_9, buf17, out=buf22)
buf23 = buf17
del buf17
extern_kernels.mm(primals_7, buf22, out=buf23)
buf27 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
buf26 = reinterpret_tensor(buf27, (4, 4), (8, 1), 4)
triton_poi_fused_add_mul_1[grid(16)](primals_8, buf6, buf7, buf8,
buf9, buf12, buf14, buf15, buf18, buf19, buf23, buf26, 16,
XBLOCK=16, num_warps=1, num_stages=1)
buf16 = buf22
del buf22
extern_kernels.mm(primals_9, buf10, out=buf16)
buf21 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_9, buf16, out=buf21)
buf24 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_9, buf21, out=buf24)
buf25 = reinterpret_tensor(buf27, (4, 4), (8, 1), 0)
triton_poi_fused_add_mul_2[grid(16)](primals_6, buf2, buf10, buf16,
buf21, buf24, buf25, 16, XBLOCK=16, num_warps=1, num_stages=1)
buf28 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_11, buf27, primals_10, alpha=1, beta=1,
out=buf28)
del primals_11
buf29 = empty_strided_cuda((4,), (1,), torch.int64)
triton_poi_fused_argmax_3[grid(4)](buf28, buf29, 4, XBLOCK=4,
num_warps=1, num_stages=1)
buf30 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused__softmax_4[grid(16)](buf28, buf30, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf31 = buf28
del buf28
buf32 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused__log_softmax__softmax_5[grid(16)](buf30, buf31,
buf32, 16, XBLOCK=16, num_warps=1, num_stages=1)
del buf30
buf33 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
buf34 = reinterpret_tensor(buf33, (4, 1), (1, 1), 0)
del buf33
buf35 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
triton_per_fused_div_linalg_vector_norm_6[grid(4)](buf34, buf27,
buf35, 4, 8, XBLOCK=1, num_warps=2, num_stages=1)
return buf35, buf32, buf29, buf31, buf1, buf2, buf4, reinterpret_tensor(
primals_6, (1,), (1,), 0), buf6, reinterpret_tensor(primals_8, (1,),
(1,), 0), buf7, reinterpret_tensor(primals_8, (1,), (1,), 1
), buf8, reinterpret_tensor(primals_8, (1,), (1,), 2
), buf9, reinterpret_tensor(primals_8, (1,), (1,), 3
), buf10, reinterpret_tensor(primals_6, (1,), (1,), 1
), buf12, reinterpret_tensor(primals_8, (1,), (1,), 4
), buf14, reinterpret_tensor(primals_8, (1,), (1,), 5
), buf15, reinterpret_tensor(primals_8, (1,), (1,), 6
), buf16, reinterpret_tensor(primals_6, (1,), (1,), 2
), buf18, reinterpret_tensor(primals_8, (1,), (1,), 7
), buf19, reinterpret_tensor(primals_8, (1,), (1,), 8
), buf21, reinterpret_tensor(primals_6, (1,), (1,), 3
), buf23, reinterpret_tensor(primals_8, (1,), (1,), 9
), buf24, reinterpret_tensor(primals_6, (1,), (1,), 4
), buf27, buf31, buf32, buf34, reinterpret_tensor(primals_10, (4, 8
), (1, 4), 0), reinterpret_tensor(primals_9, (4, 4), (1, 4), 0
), reinterpret_tensor(primals_7, (4, 4), (1, 4), 0
), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0
), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0
), reinterpret_tensor(primals_3, (4, 4), (1, 4), 0)
class SIMPA(nn.Module):
"""The signed mixed-path aggregation model.
Args:
hop (int): Number of hops to consider.
directed (bool, optional): Whether the input network is directed or not. (default: :obj:`False`)
"""
def __init__(self, hop: 'int', directed: 'bool'=False):
super(SIMPA, self).__init__()
self._hop_p = hop + 1
self._hop_n = int((1 + hop) * hop / 2)
self._undirected = not directed
if self._undirected:
self._w_p = Parameter(torch.FloatTensor(self._hop_p, 1))
self._w_n = Parameter(torch.FloatTensor(self._hop_n, 1))
self._reset_parameters_undirected()
else:
self._w_sp = Parameter(torch.FloatTensor(self._hop_p, 1))
self._w_sn = Parameter(torch.FloatTensor(self._hop_n, 1))
self._w_tp = Parameter(torch.FloatTensor(self._hop_p, 1))
self._w_tn = Parameter(torch.FloatTensor(self._hop_n, 1))
self._reset_parameters_directed()
def _reset_parameters_undirected(self):
self._w_p.data.fill_(1.0)
self._w_n.data.fill_(1.0)
def _reset_parameters_directed(self):
self._w_sp.data.fill_(1.0)
self._w_sn.data.fill_(1.0)
self._w_tp.data.fill_(1.0)
self._w_tn.data.fill_(1.0)
def forward(self, A_p:
'Union[torch.FloatTensor, torch.sparse_coo_tensor]', A_n:
'Union[torch.FloatTensor, torch.sparse_coo_tensor]', x_p:
'torch.FloatTensor', x_n: 'torch.FloatTensor', x_pt:
'Optional[torch.FloatTensor]'=None, x_nt:
'Optional[torch.FloatTensor]'=None, A_pt:
'Optional[Union[torch.FloatTensor, torch.sparse_coo_tensor]]'=None,
A_nt: 'Optional[Union[torch.FloatTensor, torch.sparse_coo_tensor]]'
=None) ->Tuple[torch.FloatTensor, torch.FloatTensor, torch.
LongTensor, torch.FloatTensor]:
"""
Making a forward pass of SIMPA.
Arg types:
* **A_p** (PyTorch FloatTensor or PyTorch sparse_coo_tensor) - Row-normalized positive part of the adjacency matrix.
* **A_n** (PyTorch FloatTensor or PyTorch sparse_coo_tensor) - Row-normalized negative part of the adjacency matrix.
* **x_p** (PyTorch FloatTensor) - Souce positive hidden representations.
* **x_n** (PyTorch FloatTensor) - Souce negative hidden representations.
* **x_pt** (PyTorch FloatTensor, optional) - Target positive hidden representations. Default: None.
* **x_nt** (PyTorch FloatTensor, optional) - Target negative hidden representations. Default: None.
* **A_pt** (PyTorch FloatTensor or PyTorch sparse_coo_tensor, optional) - Transpose of column-normalized
positive part of the adjacency matrix. Default: None.
* **A_nt** (PyTorch FloatTensor or PyTorch sparse_coo_tensor, optional) - Transpose of column-normalized
negative part of the adjacency matrix. Default: None.
Return types:
* **feat** (PyTorch FloatTensor) - Embedding matrix, with shape (num_nodes, 2*input_dim) for undirected graphs
and (num_nodes, 4*input_dim) for directed graphs.
"""
if self._undirected:
feat_p = self._w_p[0] * x_p
feat_n = torch.zeros_like(feat_p)
curr_p = x_p.clone()
curr_n_aux = x_n.clone()
j = 0
for h in range(0, self._hop_p):
if h > 0:
curr_p = torch.matmul(A_p, curr_p)
curr_n_aux = torch.matmul(A_p, curr_n_aux)
feat_p += self._w_p[h] * curr_p
if h != self._hop_p - 1:
curr_n = torch.matmul(A_n, curr_n_aux)
feat_n += self._w_n[j] * curr_n
j += 1
for _ in range(self._hop_p - 2 - h):
curr_n = torch.matmul(A_p, curr_n)
feat_n += self._w_n[j] * curr_n
j += 1
feat = torch.cat([feat_p, feat_n], dim=1)
else:
A_sp = A_p
A_sn = A_n
A_tp = A_pt
A_tn = A_nt
x_sp = x_p
x_sn = x_n
feat_sp = self._w_sp[0] * x_sp
feat_sn = torch.zeros_like(feat_sp)
feat_tp = self._w_tp[0] * x_pt
feat_tn = torch.zeros_like(feat_tp)
curr_sp = x_sp.clone()
curr_sn_aux = x_sn.clone()
curr_tp = x_pt.clone()
curr_tn_aux = x_nt.clone()
j = 0
for h in range(0, self._hop_p):
if h > 0:
curr_sp = torch.matmul(A_sp, curr_sp)
curr_sn_aux = torch.matmul(A_sp, curr_sn_aux)
curr_tp = torch.matmul(A_tp, curr_tp)
curr_tn_aux = torch.matmul(A_tp, curr_tn_aux)
feat_sp += self._w_sp[h] * curr_sp
feat_tp += self._w_tp[h] * curr_tp
if h != self._hop_p - 1:
curr_sn = torch.matmul(A_sn, curr_sn_aux)
curr_tn = torch.matmul(A_tn, curr_tn_aux)
feat_sn += self._w_sn[j] * curr_sn
feat_tn += self._w_tn[j] * curr_tn
j += 1
for _ in range(self._hop_p - 2 - h):
curr_sn = torch.matmul(A_sp, curr_sn)
curr_tn = torch.matmul(A_tp, curr_tn)
feat_sn += self._w_sn[j] * curr_sn
feat_tn += self._w_tn[j] * curr_tn
j += 1
feat = torch.cat([feat_sp, feat_sn, feat_tp, feat_tn], dim=1)
return feat
class SSSNETNew(nn.Module):
"""The signed graph clustering model.
Args:
nfeat (int): Number of features.
hidden (int): Hidden dimensions of the initial MLP.
nclass (int): Number of clusters.
dropout (float): Dropout probability.
hop (int): Number of hops to consider.
directed (bool, optional): Whether the input network is directed or not. (default: :obj:`False`)
bias (bool, optional): If set to :obj:`False`, the layer will not learn
an additive bias. (default: :obj:`True`)
"""
def __init__(self, nfeat: 'int', hidden: 'int', nclass: 'int', dropout:
'float', hop: 'int', directed: 'bool'=False, bias: 'bool'=True):
super(SSSNETNew, self).__init__()
nh1 = hidden
nh2 = hidden
self._num_clusters = int(nclass)
self._simpa = SIMPA(hop, directed)
if bias:
self._bias = Parameter(torch.FloatTensor(self._num_clusters))
else:
self.register_parameter('_bias', None)
self._relu = nn.ReLU()
self._dropout = nn.Dropout(p=dropout)
self._undirected = not directed
if self._undirected:
self._w_p0 = Parameter(torch.FloatTensor(nfeat, nh1))
self._w_p1 = Parameter(torch.FloatTensor(nh1, nh2))
self._w_n0 = Parameter(torch.FloatTensor(nfeat, nh1))
self._w_n1 = Parameter(torch.FloatTensor(nh1, nh2))
self._W_prob = Parameter(torch.FloatTensor(2 * nh2, self.
_num_clusters))
self._reset_parameters_undirected()
else:
self._w_sp0 = Parameter(torch.FloatTensor(nfeat, nh1))
self._w_sp1 = Parameter(torch.FloatTensor(nh1, nh2))
self._w_sn0 = Parameter(torch.FloatTensor(nfeat, nh1))
self._w_sn1 = Parameter(torch.FloatTensor(nh1, nh2))
self._w_tp0 = Parameter(torch.FloatTensor(nfeat, nh1))
self._w_tp1 = Parameter(torch.FloatTensor(nh1, nh2))
self._w_tn0 = Parameter(torch.FloatTensor(nfeat, nh1))
self._w_tn1 = Parameter(torch.FloatTensor(nh1, nh2))
self._W_prob = Parameter(torch.FloatTensor(4 * nh2, self.
_num_clusters))
self._reset_parameters_directed()
def _reset_parameters_undirected(self):
nn.init.xavier_uniform_(self._w_p0, gain=1.414)
nn.init.xavier_uniform_(self._w_p1, gain=1.414)
nn.init.xavier_uniform_(self._w_n0, gain=1.414)
nn.init.xavier_uniform_(self._w_n1, gain=1.414)
if self._bias is not None:
self._bias.data.fill_(0.0)
nn.init.xavier_uniform_(self._W_prob, gain=1.414)
def _reset_parameters_directed(self):
nn.init.xavier_uniform_(self._w_sp0, gain=1.414)
nn.init.xavier_uniform_(self._w_sp1, gain=1.414)
nn.init.xavier_uniform_(self._w_sn0, gain=1.414)
nn.init.xavier_uniform_(self._w_sn1, gain=1.414)
nn.init.xavier_uniform_(self._w_tp0, gain=1.414)
nn.init.xavier_uniform_(self._w_tp1, gain=1.414)
nn.init.xavier_uniform_(self._w_tn0, gain=1.414)
nn.init.xavier_uniform_(self._w_tn1, gain=1.414)
if self._bias is not None:
self._bias.data.fill_(0.0)
nn.init.xavier_uniform_(self._W_prob, gain=1.414)
def forward(self, input_0, input_1, input_2):
primals_11 = self._bias
primals_1 = self._w_p0
primals_2 = self._w_p1
primals_3 = self._w_n0
primals_4 = self._w_n1
primals_10 = self._W_prob
primals_6 = self._simpa._w_p
primals_8 = self._simpa._w_n
primals_5 = input_0
primals_7 = input_1
primals_9 = input_2
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11])
return output[0], output[1], output[2], output[3]
|
SherylHYX/SSSNET_Signed_Clustering
|
SSSNET
| false
| 17,925
|
[
"MIT"
] | 5
|
85736c18e86b396d64177d22b8c7f9859dfd794c
|
https://github.com/SherylHYX/SSSNET_Signed_Clustering/tree/85736c18e86b396d64177d22b8c7f9859dfd794c
|
DenseNet_conv
|
import torch
import torch.nn as nn
def xavier_init(module, gain=1, bias=0, distribution='normal'):
assert distribution in ['uniform', 'normal']
if distribution == 'uniform':
nn.init.xavier_uniform_(module.weight, gain=gain)
else:
nn.init.xavier_normal_(module.weight, gain=gain)
if hasattr(module, 'bias') and module.bias is not None:
nn.init.constant_(module.bias, bias)
class DenseNet_conv(nn.Module):
"""
doc
"""
def __init__(self, in_c, L=5, k=12, bn=False):
"""
dense block
:param in_c: input channel number
:param L: layer number in dense block
:param k: output channels of each layer in dense block
:param bn: using bn or not
"""
super(DenseNet_conv, self).__init__()
self.L = L
self.k = k
self.bn = bn
self.conv1s = []
self.conv2s = []
self.bn1s = []
self.bn2s = []
for i in range(self.L):
channel_in = i * self.k + in_c + 2
conv1 = nn.Conv2d(channel_in, self.k * 4, kernel_size=1, stride=1)
setattr(self, 'conv1_%i' % i, conv1)
xavier_init(conv1)
self.conv1s.append(conv1)
if self.bn:
bn1 = nn.BatchNorm2d(num_features=self.k * 4)
setattr(self, 'bn1_%i' % i, bn1)
self.bn1s.append(bn1)
conv2 = nn.Conv2d(self.k * 4, self.k, kernel_size=3, stride=1,
padding=1)
setattr(self, 'conv2_%i' % i, conv2)
xavier_init(conv2)
self.conv2s.append(conv2)
if self.bn:
bn2 = nn.BatchNorm2d(num_features=self.k)
setattr(self, 'bn2_%i' % i, bn2)
self.bn2s.append(bn2)
def forward(self, x, sparse_inputs):
"""
dense block
:param x: x
:param sparse_inputs: sparse image (s1,s2), 2 channels
:return:
"""
hs = []
h = torch.cat((x, sparse_inputs), 1)
hs.append(h)
for i in range(self.L):
if i != 0:
h = torch.cat(hs, 1)
h = self.conv1s[i](h)
if self.bn:
h = self.bn1s[i](h)
h = torch.relu(h)
h = self.conv2s[i](h)
if self.bn:
h = self.bn2s[i](h)
h = torch.relu(h)
if i != self.L - 1:
hs.append(h)
return h
def get_inputs():
return [torch.rand([4, 2, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_c': 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_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 384
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16 % 6
x0 = xindex % 16
x2 = xindex // 96
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 2, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 32 * x2), tmp4 & xmask, other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 6, tl.int64)
tmp9 = tl.load(in_ptr1 + (x0 + 16 * (-2 + x1) + 64 * x2), tmp6 & xmask,
other=0.0)
tmp10 = tl.where(tmp4, tmp5, tmp9)
tl.store(out_ptr0 + x3, tmp10, xmask)
@triton.jit
def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 3072
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 48
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_cat_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 1152
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16 % 18
x0 = xindex % 16
x2 = xindex // 288
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 6, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 96 * x2), tmp4 & xmask, other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 18, tl.int64)
tmp9 = tl.load(in_ptr1 + (x0 + 16 * (-6 + x1) + 192 * x2), tmp6 & xmask,
other=0.0)
tmp10 = tl.load(in_ptr2 + (-6 + x1), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp11 = tmp9 + tmp10
tmp12 = tl.full([1], 0, tl.int32)
tmp13 = triton_helpers.maximum(tmp12, tmp11)
tmp14 = tl.full(tmp13.shape, 0.0, tmp13.dtype)
tmp15 = tl.where(tmp6, tmp13, tmp14)
tmp16 = tl.where(tmp4, tmp5, tmp15)
tl.store(out_ptr0 + x3, tmp16, xmask)
@triton.jit
def triton_poi_fused_cat_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 1920
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16 % 30
x0 = xindex % 16
x2 = xindex // 480
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 6, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 96 * x2), tmp4 & xmask, other=0.0)
tmp6 = tmp0 >= tmp3
tmp7 = tl.full([1], 18, tl.int64)
tmp8 = tmp0 < tmp7
tmp9 = tmp6 & tmp8
tmp10 = tl.load(in_ptr1 + (x0 + 16 * (-6 + x1) + 192 * x2), tmp9 &
xmask, other=0.0)
tmp11 = tl.load(in_ptr2 + (-6 + x1), tmp9 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp12 = tmp10 + tmp11
tmp13 = tl.full([1], 0, tl.int32)
tmp14 = triton_helpers.maximum(tmp13, tmp12)
tmp15 = tl.full(tmp14.shape, 0.0, tmp14.dtype)
tmp16 = tl.where(tmp9, tmp14, tmp15)
tmp17 = tmp0 >= tmp7
tl.full([1], 30, tl.int64)
tmp20 = tl.load(in_ptr3 + (x0 + 16 * (-18 + x1) + 192 * x2), tmp17 &
xmask, other=0.0)
tmp21 = tl.load(in_ptr4 + (-18 + x1), tmp17 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp22 = tmp20 + tmp21
tmp23 = triton_helpers.maximum(tmp13, tmp22)
tmp24 = tl.full(tmp23.shape, 0.0, tmp23.dtype)
tmp25 = tl.where(tmp17, tmp23, tmp24)
tmp26 = tl.where(tmp9, tmp16, tmp25)
tmp27 = tl.where(tmp4, tmp5, tmp26)
tl.store(out_ptr0 + x3, tmp27, xmask)
@triton.jit
def triton_poi_fused_cat_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
in_ptr5, in_ptr6, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 2688
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16 % 42
x0 = xindex % 16
x2 = xindex // 672
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 6, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 96 * x2), tmp4 & xmask, other=0.0)
tmp6 = tmp0 >= tmp3
tmp7 = tl.full([1], 18, tl.int64)
tmp8 = tmp0 < tmp7
tmp9 = tmp6 & tmp8
tmp10 = tl.load(in_ptr1 + (x0 + 16 * (-6 + x1) + 192 * x2), tmp9 &
xmask, other=0.0)
tmp11 = tl.load(in_ptr2 + (-6 + x1), tmp9 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp12 = tmp10 + tmp11
tmp13 = tl.full([1], 0, tl.int32)
tmp14 = triton_helpers.maximum(tmp13, tmp12)
tmp15 = tl.full(tmp14.shape, 0.0, tmp14.dtype)
tmp16 = tl.where(tmp9, tmp14, tmp15)
tmp17 = tmp0 >= tmp7
tmp18 = tl.full([1], 30, tl.int64)
tmp19 = tmp0 < tmp18
tmp20 = tmp17 & tmp19
tmp21 = tl.load(in_ptr3 + (x0 + 16 * (-18 + x1) + 192 * x2), tmp20 &
xmask, other=0.0)
tmp22 = tl.load(in_ptr4 + (-18 + x1), tmp20 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp23 = tmp21 + tmp22
tmp24 = triton_helpers.maximum(tmp13, tmp23)
tmp25 = tl.full(tmp24.shape, 0.0, tmp24.dtype)
tmp26 = tl.where(tmp20, tmp24, tmp25)
tmp27 = tmp0 >= tmp18
tl.full([1], 42, tl.int64)
tmp30 = tl.load(in_ptr5 + (x0 + 16 * (-30 + x1) + 192 * x2), tmp27 &
xmask, other=0.0)
tmp31 = tl.load(in_ptr6 + (-30 + x1), tmp27 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp32 = tmp30 + tmp31
tmp33 = triton_helpers.maximum(tmp13, tmp32)
tmp34 = tl.full(tmp33.shape, 0.0, tmp33.dtype)
tmp35 = tl.where(tmp27, tmp33, tmp34)
tmp36 = tl.where(tmp20, tmp26, tmp35)
tmp37 = tl.where(tmp9, tmp16, tmp36)
tmp38 = tl.where(tmp4, tmp5, tmp37)
tl.store(out_ptr0 + x3, tmp38, xmask)
@triton.jit
def triton_poi_fused_cat_5(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
in_ptr5, in_ptr6, in_ptr7, in_ptr8, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 3456
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16 % 54
x0 = xindex % 16
x2 = xindex // 864
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 6, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 96 * x2), tmp4 & xmask, other=0.0)
tmp6 = tmp0 >= tmp3
tmp7 = tl.full([1], 18, tl.int64)
tmp8 = tmp0 < tmp7
tmp9 = tmp6 & tmp8
tmp10 = tl.load(in_ptr1 + (x0 + 16 * (-6 + x1) + 192 * x2), tmp9 &
xmask, other=0.0)
tmp11 = tl.load(in_ptr2 + (-6 + x1), tmp9 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp12 = tmp10 + tmp11
tmp13 = tl.full([1], 0, tl.int32)
tmp14 = triton_helpers.maximum(tmp13, tmp12)
tmp15 = tl.full(tmp14.shape, 0.0, tmp14.dtype)
tmp16 = tl.where(tmp9, tmp14, tmp15)
tmp17 = tmp0 >= tmp7
tmp18 = tl.full([1], 30, tl.int64)
tmp19 = tmp0 < tmp18
tmp20 = tmp17 & tmp19
tmp21 = tl.load(in_ptr3 + (x0 + 16 * (-18 + x1) + 192 * x2), tmp20 &
xmask, other=0.0)
tmp22 = tl.load(in_ptr4 + (-18 + x1), tmp20 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp23 = tmp21 + tmp22
tmp24 = triton_helpers.maximum(tmp13, tmp23)
tmp25 = tl.full(tmp24.shape, 0.0, tmp24.dtype)
tmp26 = tl.where(tmp20, tmp24, tmp25)
tmp27 = tmp0 >= tmp18
tmp28 = tl.full([1], 42, tl.int64)
tmp29 = tmp0 < tmp28
tmp30 = tmp27 & tmp29
tmp31 = tl.load(in_ptr5 + (x0 + 16 * (-30 + x1) + 192 * x2), tmp30 &
xmask, other=0.0)
tmp32 = tl.load(in_ptr6 + (-30 + x1), tmp30 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp33 = tmp31 + tmp32
tmp34 = triton_helpers.maximum(tmp13, tmp33)
tmp35 = tl.full(tmp34.shape, 0.0, tmp34.dtype)
tmp36 = tl.where(tmp30, tmp34, tmp35)
tmp37 = tmp0 >= tmp28
tl.full([1], 54, tl.int64)
tmp40 = tl.load(in_ptr7 + (x0 + 16 * (-42 + x1) + 192 * x2), tmp37 &
xmask, other=0.0)
tmp41 = tl.load(in_ptr8 + (-42 + x1), tmp37 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp42 = tmp40 + tmp41
tmp43 = triton_helpers.maximum(tmp13, tmp42)
tmp44 = tl.full(tmp43.shape, 0.0, tmp43.dtype)
tmp45 = tl.where(tmp37, tmp43, tmp44)
tmp46 = tl.where(tmp30, tmp36, tmp45)
tmp47 = tl.where(tmp20, tmp26, tmp46)
tmp48 = tl.where(tmp9, tmp16, tmp47)
tmp49 = tl.where(tmp4, tmp5, tmp48)
tl.store(out_ptr0 + x3, tmp49, xmask)
@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_6(in_out_ptr0,
in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 768
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 12
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x3, tmp4, xmask)
tl.store(out_ptr0 + x3, tmp6, xmask)
@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_7(in_ptr0, in_ptr1,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 768
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 12
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(out_ptr0 + x3, tmp6, xmask)
def call(args):
(primals_1, primals_2, primals_3, 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, 2, 4, 4), (32, 16, 4, 1))
assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_3, (48, 6, 1, 1), (6, 1, 1, 1))
assert_size_stride(primals_4, (48,), (1,))
assert_size_stride(primals_5, (12, 48, 3, 3), (432, 9, 3, 1))
assert_size_stride(primals_6, (12,), (1,))
assert_size_stride(primals_7, (48, 18, 1, 1), (18, 1, 1, 1))
assert_size_stride(primals_8, (48,), (1,))
assert_size_stride(primals_9, (12, 48, 3, 3), (432, 9, 3, 1))
assert_size_stride(primals_10, (12,), (1,))
assert_size_stride(primals_11, (48, 30, 1, 1), (30, 1, 1, 1))
assert_size_stride(primals_12, (48,), (1,))
assert_size_stride(primals_13, (12, 48, 3, 3), (432, 9, 3, 1))
assert_size_stride(primals_14, (12,), (1,))
assert_size_stride(primals_15, (48, 42, 1, 1), (42, 1, 1, 1))
assert_size_stride(primals_16, (48,), (1,))
assert_size_stride(primals_17, (12, 48, 3, 3), (432, 9, 3, 1))
assert_size_stride(primals_18, (12,), (1,))
assert_size_stride(primals_19, (48, 54, 1, 1), (54, 1, 1, 1))
assert_size_stride(primals_20, (48,), (1,))
assert_size_stride(primals_21, (12, 48, 3, 3), (432, 9, 3, 1))
assert_size_stride(primals_22, (12,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 6, 4, 4), (96, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(384)](primals_1, primals_2, buf0, 384,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_1
del primals_2
buf1 = extern_kernels.convolution(buf0, primals_3, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf1, (4, 48, 4, 4), (768, 16, 4, 1))
buf2 = buf1
del buf1
triton_poi_fused_convolution_relu_1[grid(3072)](buf2, primals_4,
3072, XBLOCK=128, num_warps=4, num_stages=1)
del primals_4
buf3 = extern_kernels.convolution(buf2, primals_5, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf3, (4, 12, 4, 4), (192, 16, 4, 1))
buf4 = empty_strided_cuda((4, 18, 4, 4), (288, 16, 4, 1), torch.float32
)
triton_poi_fused_cat_2[grid(1152)](buf0, buf3, primals_6, buf4,
1152, XBLOCK=128, num_warps=4, num_stages=1)
buf5 = extern_kernels.convolution(buf4, primals_7, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf5, (4, 48, 4, 4), (768, 16, 4, 1))
buf6 = buf5
del buf5
triton_poi_fused_convolution_relu_1[grid(3072)](buf6, primals_8,
3072, XBLOCK=128, num_warps=4, num_stages=1)
del primals_8
buf7 = extern_kernels.convolution(buf6, primals_9, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf7, (4, 12, 4, 4), (192, 16, 4, 1))
buf8 = empty_strided_cuda((4, 30, 4, 4), (480, 16, 4, 1), torch.float32
)
triton_poi_fused_cat_3[grid(1920)](buf0, buf3, primals_6, buf7,
primals_10, buf8, 1920, XBLOCK=256, num_warps=4, num_stages=1)
buf9 = extern_kernels.convolution(buf8, primals_11, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf9, (4, 48, 4, 4), (768, 16, 4, 1))
buf10 = buf9
del buf9
triton_poi_fused_convolution_relu_1[grid(3072)](buf10, primals_12,
3072, XBLOCK=128, num_warps=4, num_stages=1)
del primals_12
buf11 = extern_kernels.convolution(buf10, primals_13, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf11, (4, 12, 4, 4), (192, 16, 4, 1))
buf12 = empty_strided_cuda((4, 42, 4, 4), (672, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_4[grid(2688)](buf0, buf3, primals_6, buf7,
primals_10, buf11, primals_14, buf12, 2688, XBLOCK=128,
num_warps=4, num_stages=1)
buf13 = extern_kernels.convolution(buf12, primals_15, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf13, (4, 48, 4, 4), (768, 16, 4, 1))
buf14 = buf13
del buf13
triton_poi_fused_convolution_relu_1[grid(3072)](buf14, primals_16,
3072, XBLOCK=128, num_warps=4, num_stages=1)
del primals_16
buf15 = extern_kernels.convolution(buf14, primals_17, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf15, (4, 12, 4, 4), (192, 16, 4, 1))
buf16 = empty_strided_cuda((4, 54, 4, 4), (864, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_5[grid(3456)](buf0, buf3, primals_6, buf7,
primals_10, buf11, primals_14, buf15, primals_18, buf16, 3456,
XBLOCK=128, num_warps=4, num_stages=1)
buf17 = extern_kernels.convolution(buf16, primals_19, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf17, (4, 48, 4, 4), (768, 16, 4, 1))
buf18 = buf17
del buf17
triton_poi_fused_convolution_relu_1[grid(3072)](buf18, primals_20,
3072, XBLOCK=128, num_warps=4, num_stages=1)
del primals_20
buf19 = extern_kernels.convolution(buf18, primals_21, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf19, (4, 12, 4, 4), (192, 16, 4, 1))
buf20 = buf19
del buf19
buf21 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.bool)
triton_poi_fused_convolution_relu_threshold_backward_6[grid(768)](buf20
, primals_22, buf21, 768, XBLOCK=128, num_warps=4, num_stages=1)
del primals_22
buf22 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.bool)
triton_poi_fused_convolution_relu_threshold_backward_7[grid(768)](buf15
, primals_18, buf22, 768, XBLOCK=128, num_warps=4, num_stages=1)
del buf15
del primals_18
buf23 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.bool)
triton_poi_fused_convolution_relu_threshold_backward_7[grid(768)](buf11
, primals_14, buf23, 768, XBLOCK=128, num_warps=4, num_stages=1)
del buf11
del primals_14
buf24 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.bool)
triton_poi_fused_convolution_relu_threshold_backward_7[grid(768)](buf7,
primals_10, buf24, 768, XBLOCK=128, num_warps=4, num_stages=1)
del buf7
del primals_10
buf25 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.bool)
triton_poi_fused_convolution_relu_threshold_backward_7[grid(768)](buf3,
primals_6, buf25, 768, XBLOCK=128, num_warps=4, num_stages=1)
del buf3
del primals_6
return (buf20, primals_3, primals_5, primals_7, primals_9, primals_11,
primals_13, primals_15, primals_17, primals_19, primals_21, buf0,
buf2, buf4, buf6, buf8, buf10, buf12, buf14, buf16, buf18, buf21,
buf22, buf23, buf24, buf25)
def xavier_init(module, gain=1, bias=0, distribution='normal'):
assert distribution in ['uniform', 'normal']
if distribution == 'uniform':
nn.init.xavier_uniform_(module.weight, gain=gain)
else:
nn.init.xavier_normal_(module.weight, gain=gain)
if hasattr(module, 'bias') and module.bias is not None:
nn.init.constant_(module.bias, bias)
class DenseNet_convNew(nn.Module):
"""
doc
"""
def __init__(self, in_c, L=5, k=12, bn=False):
"""
dense block
:param in_c: input channel number
:param L: layer number in dense block
:param k: output channels of each layer in dense block
:param bn: using bn or not
"""
super(DenseNet_convNew, self).__init__()
self.L = L
self.k = k
self.bn = bn
self.conv1s = []
self.conv2s = []
self.bn1s = []
self.bn2s = []
for i in range(self.L):
channel_in = i * self.k + in_c + 2
conv1 = nn.Conv2d(channel_in, self.k * 4, kernel_size=1, stride=1)
setattr(self, 'conv1_%i' % i, conv1)
xavier_init(conv1)
self.conv1s.append(conv1)
if self.bn:
bn1 = nn.BatchNorm2d(num_features=self.k * 4)
setattr(self, 'bn1_%i' % i, bn1)
self.bn1s.append(bn1)
conv2 = nn.Conv2d(self.k * 4, self.k, kernel_size=3, stride=1,
padding=1)
setattr(self, 'conv2_%i' % i, conv2)
xavier_init(conv2)
self.conv2s.append(conv2)
if self.bn:
bn2 = nn.BatchNorm2d(num_features=self.k)
setattr(self, 'bn2_%i' % i, bn2)
self.bn2s.append(bn2)
def forward(self, input_0, input_1):
primals_3 = self.conv1_0.weight
primals_4 = self.conv1_0.bias
primals_5 = self.conv2_0.weight
primals_6 = self.conv2_0.bias
primals_7 = self.conv1_1.weight
primals_8 = self.conv1_1.bias
primals_9 = self.conv2_1.weight
primals_10 = self.conv2_1.bias
primals_11 = self.conv1_2.weight
primals_12 = self.conv1_2.bias
primals_13 = self.conv2_2.weight
primals_14 = self.conv2_2.bias
primals_15 = self.conv1_3.weight
primals_16 = self.conv1_3.bias
primals_17 = self.conv2_3.weight
primals_18 = self.conv2_3.bias
primals_19 = self.conv1_4.weight
primals_20 = self.conv1_4.bias
primals_21 = self.conv2_4.weight
primals_22 = self.conv2_4.bias
primals_1 = input_0
primals_2 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, 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]
|
Shiaoming/DensefromRGBS
|
DenseNet_conv
| false
| 17,926
|
[
"MIT"
] | 7
|
d69f5f60c5512da876b002a2007ec42d4a3fbb8e
|
https://github.com/Shiaoming/DensefromRGBS/tree/d69f5f60c5512da876b002a2007ec42d4a3fbb8e
|
TripletLoss
|
import torch
from torchvision.transforms import functional as F
import torch.utils.data
from torch import nn
import torch.nn.functional as F
class TripletLoss(nn.Module):
"""
Triplet loss
Takes embeddings [N*dim_embed] of an anchor sample, a positive sample and a negative sample
"""
def __init__(self, margin):
super(TripletLoss, self).__init__()
self.margin = margin
def forward(self, anchor, positive, negative, size_average=True):
distance_positive = (anchor - positive).pow(2).sum(1)
distance_negative = (anchor - negative).pow(2).sum(1)
losses = F.relu(distance_positive - distance_negative + self.margin)
if size_average:
loss = losses.mean()
else:
loss = losses.sum()
return loss
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand(
[4, 4, 4, 4])]
def get_init_inputs():
return [[], {'margin': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.utils.data
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_add_mean_pow_relu_sub_sum_0(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)
tmp19 = tl.load(in_ptr2 + (r0 + 64 * r1), None)
tmp22 = tl.load(in_ptr2 + (16 + r0 + 64 * r1), None)
tmp26 = tl.load(in_ptr2 + (32 + r0 + 64 * r1), None)
tmp30 = 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
tmp20 = tmp0 - tmp19
tmp21 = tmp20 * tmp20
tmp23 = tmp4 - tmp22
tmp24 = tmp23 * tmp23
tmp25 = tmp21 + tmp24
tmp27 = tmp9 - tmp26
tmp28 = tmp27 * tmp27
tmp29 = tmp25 + tmp28
tmp31 = tmp14 - tmp30
tmp32 = tmp31 * tmp31
tmp33 = tmp29 + tmp32
tmp34 = tmp18 - tmp33
tmp35 = 4.0
tmp36 = tmp34 + tmp35
tmp37 = tl.full([1, 1], 0, tl.int32)
tmp38 = triton_helpers.maximum(tmp37, tmp36)
tmp39 = tl.broadcast_to(tmp38, [XBLOCK, RBLOCK])
tmp41 = tl.sum(tmp39, 1)[:, None]
tmp42 = 64.0
tmp43 = tmp41 / tmp42
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp43, None)
def call(args):
arg0_1, arg1_1, 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)
buf1 = empty_strided_cuda((), (), torch.float32)
buf2 = buf1
del buf1
get_raw_stream(0)
triton_per_fused_add_mean_pow_relu_sub_sum_0[grid(1)](buf2, arg0_1,
arg1_1, arg2_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
del arg2_1
return buf2,
class TripletLossNew(nn.Module):
"""
Triplet loss
Takes embeddings [N*dim_embed] of an anchor sample, a positive sample and a negative sample
"""
def __init__(self, margin):
super(TripletLossNew, self).__init__()
self.margin = margin
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]
|
Sigma10010/nuclei_cells_det
|
TripletLoss
| false
| 17,927
|
[
"MIT"
] | 4
|
c074175fec8938472bb4cddabd83d1d0ea78f230
|
https://github.com/Sigma10010/nuclei_cells_det/tree/c074175fec8938472bb4cddabd83d1d0ea78f230
|
CPULayerNorm
|
import torch
import torch.nn as nn
class CPULayerNorm(nn.Module):
def __init__(self, features, eps=1e-06):
super().__init__()
self.features = features
self.eps = eps
def forward(self, x, gamma, beta):
mean = x.mean(-1, keepdim=True)
std = x.std(-1, keepdim=True)
return gamma * ((x - mean) / (std + self.eps)) + beta
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 [[], {'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_mean_mul_std_sub_0(in_ptr0, in_ptr1, in_ptr2,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x2, xmask)
tmp2 = tl.load(in_ptr1 + 4 * x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr1 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp30 = tl.load(in_ptr2 + x2, xmask)
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp8 = tmp6 + tmp7
tmp9 = 4.0
tmp10 = tmp8 / tmp9
tmp11 = tmp1 - tmp10
tmp12 = tmp2 - tmp10
tmp13 = tmp12 * tmp12
tmp14 = tmp3 - tmp10
tmp15 = tmp14 * tmp14
tmp16 = tmp13 + tmp15
tmp17 = tmp5 - tmp10
tmp18 = tmp17 * tmp17
tmp19 = tmp16 + tmp18
tmp20 = tmp7 - tmp10
tmp21 = tmp20 * tmp20
tmp22 = tmp19 + tmp21
tmp23 = 3.0
tmp24 = tmp22 / tmp23
tmp25 = libdevice.sqrt(tmp24)
tmp26 = 1e-06
tmp27 = tmp25 + tmp26
tmp28 = tmp11 / tmp27
tmp29 = tmp0 * tmp28
tmp31 = tmp29 + tmp30
tl.store(out_ptr0 + x2, tmp31, 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, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_add_div_mean_mul_std_sub_0[grid(256)](arg1_1,
arg0_1, arg2_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1)
del arg0_1
del arg1_1
del arg2_1
return buf0,
class CPULayerNormNew(nn.Module):
def __init__(self, features, eps=1e-06):
super().__init__()
self.features = features
self.eps = eps
def forward(self, input_0, input_1, input_2):
arg0_1 = input_0
arg1_1 = input_1
arg2_1 = input_2
output = call([arg0_1, arg1_1, arg2_1])
return output[0]
|
Smerity/pytorch-qrnn
|
CPULayerNorm
| false
| 17,928
|
[
"BSD-3-Clause"
] | 4
|
907c8ea53f689136fcc50996b6474de967745202
|
https://github.com/Smerity/pytorch-qrnn/tree/907c8ea53f689136fcc50996b6474de967745202
|
MixerBlock
|
import torch
import torch.nn as nn
def drop_path(x, drop_prob: 'float'=0.0, training: 'bool'=False):
"""Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
This is the same as the DropConnect impl I created for EfficientNet, etc networks, however,
the original name is misleading as 'Drop Connect' is a different form of dropout in a separate paper...
See discussion: https://github.com/tensorflow/tpu/issues/494#issuecomment-532968956 ... I've opted for
changing the layer and argument names to 'drop path' rather than mix DropConnect as a layer name and use
'survival rate' as the argument.
"""
if drop_prob == 0.0 or not training:
return x
keep_prob = 1 - drop_prob
shape = (x.shape[0],) + (1,) * (x.ndim - 1)
random_tensor = keep_prob + torch.rand(shape, dtype=x.dtype, device=x.
device)
random_tensor.floor_()
output = x.div(keep_prob) * random_tensor
return output
class DropPath(nn.Module):
"""Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
"""
def __init__(self, drop_prob=None):
super(DropPath, self).__init__()
self.drop_prob = drop_prob
def forward(self, x):
return drop_path(x, self.drop_prob, self.training)
class VanillaMlp(nn.Module):
""" MLP as used in Vision Transformer, MLP-Mixer and related networks
"""
def __init__(self, in_features, hidden_features=None, out_features=None,
act_layer=nn.GELU, drop=0.0):
super().__init__()
out_features = out_features or in_features
hidden_features = hidden_features or in_features
self.fc1 = nn.Linear(in_features, hidden_features)
self.act = act_layer()
self.fc2 = nn.Linear(hidden_features, out_features)
self.drop = nn.Dropout(drop)
def forward(self, x):
x = self.fc1(x)
x = self.act(x)
x = self.drop(x)
x = self.fc2(x)
x = self.drop(x)
return x
class MixerBlock(nn.Module):
def __init__(self, num_patch, dim, token_mlp_ratio, channel_mlp_ratio,
drop=0.0, drop_path=0.0, norm_layer=nn.LayerNorm, act_layer=nn.GELU):
super().__init__()
self.norm1 = norm_layer(dim)
self.norm2 = norm_layer(dim)
token_mlp_dim = round(dim * token_mlp_ratio)
channel_mlp_dim = round(dim * channel_mlp_ratio)
self.drop_path = DropPath(drop_path
) if drop_path > 0.0 else nn.Identity()
self.token_mix = VanillaMlp(num_patch, token_mlp_dim, num_patch,
act_layer, drop)
self.channel_mix = VanillaMlp(dim, channel_mlp_dim, dim, act_layer,
drop)
def forward(self, x):
y = self.norm1(x).transpose(1, 2)
y = self.drop_path(self.token_mix(y)).transpose(1, 2)
x = x + y
y = self.norm2(x)
x = x + self.drop_path(self.channel_mix(y))
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'num_patch': 4, 'dim': 4, 'token_mlp_ratio': 4,
'channel_mlp_ratio': 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_native_layer_norm_0(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp7 = 4.0
tmp8 = tmp6 / tmp7
tmp9 = tmp0 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tmp1 - tmp8
tmp12 = tmp11 * tmp11
tmp13 = tmp10 + tmp12
tmp14 = tmp3 - tmp8
tmp15 = tmp14 * tmp14
tmp16 = tmp13 + tmp15
tmp17 = tmp5 - tmp8
tmp18 = tmp17 * tmp17
tmp19 = tmp16 + tmp18
tmp20 = tmp19 / tmp7
tmp21 = 1e-05
tmp22 = tmp20 + tmp21
tmp23 = libdevice.rsqrt(tmp22)
tl.store(out_ptr0 + x0, tmp8, xmask)
tl.store(out_ptr1 + x0, tmp23, xmask)
@triton.jit
def triton_poi_fused_clone_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x4 = xindex
x5 = xindex // 4
x0 = xindex % 4
x1 = xindex // 4 % 4
x2 = xindex // 16 % 4
x3 = xindex // 64
tmp0 = tl.load(in_ptr0 + x4, xmask)
tmp1 = tl.load(in_ptr1 + x5, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + x5, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = tmp2 * tmp3
tmp6 = tmp4 * tmp5
tmp8 = tmp6 + tmp7
tl.store(out_ptr0 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), tmp8, xmask)
@triton.jit
def triton_poi_fused_add_gelu_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 16
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.5
tmp4 = tmp2 * tmp3
tmp5 = 0.7071067811865476
tmp6 = tmp2 * tmp5
tmp7 = libdevice.erf(tmp6)
tmp8 = 1.0
tmp9 = tmp7 + tmp8
tmp10 = tmp4 * tmp9
tl.store(out_ptr0 + x2, tmp10, xmask)
@triton.jit
def triton_poi_fused_add_native_layer_norm_3(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 4
x1 = xindex // 4 % 4
x2 = xindex // 16
tmp0 = tl.load(in_ptr0 + 4 * x3, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + (4 * x1 + 16 * x0 + 64 * x2), xmask,
eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (1 + 4 * x3), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr1 + (1 + 4 * x1 + 16 * x0 + 64 * x2), xmask,
eviction_policy='evict_last')
tmp7 = tl.load(in_ptr0 + (2 + 4 * x3), xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr1 + (2 + 4 * x1 + 16 * x0 + 64 * x2), xmask,
eviction_policy='evict_last')
tmp11 = tl.load(in_ptr0 + (3 + 4 * x3), xmask, eviction_policy='evict_last'
)
tmp12 = tl.load(in_ptr1 + (3 + 4 * x1 + 16 * x0 + 64 * x2), xmask,
eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp5 = tmp3 + tmp4
tmp6 = tmp2 + tmp5
tmp9 = tmp7 + tmp8
tmp10 = tmp6 + tmp9
tmp13 = tmp11 + tmp12
tmp14 = tmp10 + tmp13
tmp15 = 4.0
tmp16 = tmp14 / tmp15
tmp17 = tmp2 - tmp16
tmp18 = tmp17 * tmp17
tmp19 = tmp5 - tmp16
tmp20 = tmp19 * tmp19
tmp21 = tmp18 + tmp20
tmp22 = tmp9 - tmp16
tmp23 = tmp22 * tmp22
tmp24 = tmp21 + tmp23
tmp25 = tmp13 - tmp16
tmp26 = tmp25 * tmp25
tmp27 = tmp24 + tmp26
tmp28 = tmp27 / tmp15
tl.store(out_ptr0 + x3, tmp16, xmask)
tl.store(out_ptr1 + x3, tmp28, xmask)
@triton.jit
def triton_poi_fused_add_native_layer_norm_4(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x4 = xindex
x0 = xindex % 4
x1 = xindex // 4 % 4
x2 = xindex // 16 % 4
x3 = xindex // 64
x5 = xindex // 4
tmp0 = tl.load(in_ptr0 + x4, xmask)
tmp1 = tl.load(in_ptr1 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), xmask)
tmp3 = tl.load(in_ptr2 + x5, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr3 + x5, xmask, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp4 = tmp2 - tmp3
tmp6 = 1e-05
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp4 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tl.store(out_ptr0 + x4, tmp13, xmask)
@triton.jit
def triton_poi_fused_gelu_5(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 0.5
tmp2 = tmp0 * tmp1
tmp3 = 0.7071067811865476
tmp4 = tmp0 * tmp3
tmp5 = libdevice.erf(tmp4)
tmp6 = 1.0
tmp7 = tmp5 + tmp6
tmp8 = tmp2 * tmp7
tl.store(out_ptr0 + x0, tmp8, xmask)
@triton.jit
def triton_poi_fused_add_6(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel,
XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x4 = xindex
x0 = xindex % 4
x1 = xindex // 4 % 4
x2 = xindex // 16 % 4
x3 = xindex // 64
tmp0 = tl.load(in_ptr0 + x4, xmask)
tmp1 = tl.load(in_ptr1 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), xmask)
tmp3 = tl.load(in_out_ptr0 + x4, xmask)
tmp4 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp5 = tmp3 + tmp4
tmp6 = tmp2 + tmp5
tl.store(in_out_ptr0 + x4, tmp6, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
primals_13) = args
args.clear()
assert_size_stride(primals_1, (4,), (1,))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (16, 4), (4, 1))
assert_size_stride(primals_5, (16,), (1,))
assert_size_stride(primals_6, (4, 16), (16, 1))
assert_size_stride(primals_7, (4,), (1,))
assert_size_stride(primals_8, (4,), (1,))
assert_size_stride(primals_9, (4,), (1,))
assert_size_stride(primals_10, (16, 4), (4, 1))
assert_size_stride(primals_11, (16,), (1,))
assert_size_stride(primals_12, (4, 16), (16, 1))
assert_size_stride(primals_13, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 1), (16, 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_clone_1[grid(256)](primals_3, buf0, buf1,
primals_1, primals_2, buf2, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_1
del primals_2
buf3 = empty_strided_cuda((64, 16), (16, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf2, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_4, (4, 16), (1, 4), 0), out=buf3)
buf4 = empty_strided_cuda((4, 4, 4, 16), (256, 64, 16, 1), torch.
float32)
triton_poi_fused_add_gelu_2[grid(1024)](buf3, primals_5, buf4, 1024,
XBLOCK=128, num_warps=4, num_stages=1)
buf5 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_7, reinterpret_tensor(buf4, (64, 16),
(16, 1), 0), reinterpret_tensor(primals_6, (16, 4), (1, 16), 0),
alpha=1, beta=1, out=buf5)
del primals_7
buf6 = buf1
del buf1
buf7 = buf0
del buf0
triton_poi_fused_add_native_layer_norm_3[grid(64)](primals_3, buf5,
buf6, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_add_native_layer_norm_4[grid(256)](primals_3, buf5,
buf6, buf7, primals_8, primals_9, buf8, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del buf6
del buf7
del primals_9
buf9 = empty_strided_cuda((64, 16), (16, 1), torch.float32)
extern_kernels.addmm(primals_11, reinterpret_tensor(buf8, (64, 4),
(4, 1), 0), reinterpret_tensor(primals_10, (4, 16), (1, 4), 0),
alpha=1, beta=1, out=buf9)
del primals_11
buf10 = empty_strided_cuda((4, 4, 4, 16), (256, 64, 16, 1), torch.
float32)
triton_poi_fused_gelu_5[grid(1024)](buf9, buf10, 1024, XBLOCK=256,
num_warps=4, num_stages=1)
buf11 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf10, (64, 16), (16, 1), 0),
reinterpret_tensor(primals_12, (16, 4), (1, 16), 0), out=buf11)
buf12 = reinterpret_tensor(buf11, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf11
triton_poi_fused_add_6[grid(256)](buf12, primals_3, buf5,
primals_13, 256, XBLOCK=256, num_warps=4, num_stages=1)
del primals_13
return buf12, primals_3, primals_5, primals_8, reinterpret_tensor(buf2,
(64, 4), (4, 1), 0), buf3, reinterpret_tensor(buf4, (64, 16), (16,
1), 0), buf5, reinterpret_tensor(buf8, (64, 4), (4, 1), 0
), buf9, reinterpret_tensor(buf10, (64, 16), (16, 1), 0
), primals_12, primals_10, primals_6, primals_4
def drop_path(x, drop_prob: 'float'=0.0, training: 'bool'=False):
"""Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
This is the same as the DropConnect impl I created for EfficientNet, etc networks, however,
the original name is misleading as 'Drop Connect' is a different form of dropout in a separate paper...
See discussion: https://github.com/tensorflow/tpu/issues/494#issuecomment-532968956 ... I've opted for
changing the layer and argument names to 'drop path' rather than mix DropConnect as a layer name and use
'survival rate' as the argument.
"""
if drop_prob == 0.0 or not training:
return x
keep_prob = 1 - drop_prob
shape = (x.shape[0],) + (1,) * (x.ndim - 1)
random_tensor = keep_prob + torch.rand(shape, dtype=x.dtype, device=x.
device)
random_tensor.floor_()
output = x.div(keep_prob) * random_tensor
return output
class DropPath(nn.Module):
"""Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
"""
def __init__(self, drop_prob=None):
super(DropPath, self).__init__()
self.drop_prob = drop_prob
def forward(self, x):
return drop_path(x, self.drop_prob, self.training)
class VanillaMlp(nn.Module):
""" MLP as used in Vision Transformer, MLP-Mixer and related networks
"""
def __init__(self, in_features, hidden_features=None, out_features=None,
act_layer=nn.GELU, drop=0.0):
super().__init__()
out_features = out_features or in_features
hidden_features = hidden_features or in_features
self.fc1 = nn.Linear(in_features, hidden_features)
self.act = act_layer()
self.fc2 = nn.Linear(hidden_features, out_features)
self.drop = nn.Dropout(drop)
def forward(self, x):
x = self.fc1(x)
x = self.act(x)
x = self.drop(x)
x = self.fc2(x)
x = self.drop(x)
return x
class MixerBlockNew(nn.Module):
def __init__(self, num_patch, dim, token_mlp_ratio, channel_mlp_ratio,
drop=0.0, drop_path=0.0, norm_layer=nn.LayerNorm, act_layer=nn.GELU):
super().__init__()
self.norm1 = norm_layer(dim)
self.norm2 = norm_layer(dim)
token_mlp_dim = round(dim * token_mlp_ratio)
channel_mlp_dim = round(dim * channel_mlp_ratio)
self.drop_path = DropPath(drop_path
) if drop_path > 0.0 else nn.Identity()
self.token_mix = VanillaMlp(num_patch, token_mlp_dim, num_patch,
act_layer, drop)
self.channel_mix = VanillaMlp(dim, channel_mlp_dim, dim, act_layer,
drop)
def forward(self, input_0):
primals_1 = self.norm1.weight
primals_2 = self.norm1.bias
primals_7 = self.norm2.weight
primals_8 = self.norm2.bias
primals_4 = self.token_mix.fc1.weight
primals_5 = self.token_mix.fc1.bias
primals_6 = self.token_mix.fc2.weight
primals_9 = self.token_mix.fc2.bias
primals_10 = self.channel_mix.fc1.weight
primals_11 = self.channel_mix.fc1.bias
primals_12 = self.channel_mix.fc2.weight
primals_13 = self.channel_mix.fc2.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11, primals_12, primals_13])
return output[0]
|
Sense-GVT/BigPretrain
|
MixerBlock
| false
| 17,929
|
[
"Apache-2.0"
] | 8
|
d8d9b43d94dd1364c18c1e5ba21b85a31cdbba9e
|
https://github.com/Sense-GVT/BigPretrain/tree/d8d9b43d94dd1364c18c1e5ba21b85a31cdbba9e
|
SelfAttention
|
import torch
import torch.nn as nn
class SelfAttention(nn.Module):
def __init__(self, embed_dims, heads):
super(SelfAttention, self).__init__()
self.heads = heads
self.embed_dims = embed_dims
self.depth = embed_dims // heads
self.query = nn.Linear(self.depth, self.depth)
self.key = nn.Linear(self.depth, self.depth)
self.value = nn.Linear(self.depth, self.depth)
self.fc_out = nn.Linear(self.depth * self.heads * 2, self.embed_dims)
def forward(self, query, key, value, mask):
batch, q_len, k_len, v_len = query.shape[0], query.shape[1], key.shape[
1], value.shape[1]
query = query.reshape(batch, q_len, self.heads, self.depth)
key = key.reshape(batch, k_len, self.heads, self.depth)
value = value.reshape(batch, v_len, self.heads, self.depth)
query = self.query(query)
key = self.key(key)
value = self.value(value)
energy = torch.einsum('bqhd, bkhd -> bhqk', [query, key])
if mask is not None:
energy.masked_fill(mask == 0, float('-1e20'))
energy = torch.softmax(energy / (self.depth ** 1 / 2), dim=-1)
out = torch.einsum('bhqv, bvhd -> bqhd', [energy, value])
out = out.reshape(batch, q_len, self.heads * self.depth)
query = query.reshape(batch, q_len, self.heads * self.depth)
out = torch.cat([query, out], dim=-1)
out = self.fc_out(out)
return out
def get_inputs():
return [torch.rand([4, 4, 4, 1]), torch.rand([4, 4, 4, 1]), torch.rand(
[4, 4, 4, 1]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'embed_dims': 4, 'heads': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused__softmax_div_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 4
x2 = xindex // 16
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + (x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp5 = tl.load(in_ptr1 + (4 + x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr1 + (8 + x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp13 = tl.load(in_ptr1 + (12 + x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tmp0 * tmp1
tmp3 = 2.0
tmp4 = tmp2 * tmp3
tmp6 = tmp0 * tmp5
tmp7 = tmp6 * tmp3
tmp8 = triton_helpers.maximum(tmp4, tmp7)
tmp10 = tmp0 * tmp9
tmp11 = tmp10 * tmp3
tmp12 = triton_helpers.maximum(tmp8, tmp11)
tmp14 = tmp0 * tmp13
tmp15 = tmp14 * tmp3
tmp16 = triton_helpers.maximum(tmp12, tmp15)
tmp17 = tmp4 - tmp16
tmp18 = tl_math.exp(tmp17)
tmp19 = tmp7 - tmp16
tmp20 = tl_math.exp(tmp19)
tmp21 = tmp18 + tmp20
tmp22 = tmp11 - tmp16
tmp23 = tl_math.exp(tmp22)
tmp24 = tmp21 + tmp23
tmp25 = tmp15 - tmp16
tmp26 = tl_math.exp(tmp25)
tmp27 = tmp24 + tmp26
tl.store(out_ptr0 + x3, tmp16, xmask)
tl.store(out_ptr1 + x3, tmp27, xmask)
@triton.jit
def triton_poi_fused__softmax_div_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x4 = xindex // 4
x0 = xindex % 4
x1 = xindex // 4 % 4
x3 = xindex // 64
x2 = xindex // 16 % 4
tmp0 = tl.load(in_ptr0 + x4, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + (x1 + 4 * x0 + 16 * x3), xmask,
eviction_policy='evict_last')
tmp5 = tl.load(in_ptr2 + x4, xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr3 + x4, xmask, eviction_policy='evict_last')
tmp2 = tmp0 * tmp1
tmp3 = 2.0
tmp4 = tmp2 * tmp3
tmp6 = tmp4 - tmp5
tmp7 = tl_math.exp(tmp6)
tmp9 = tmp7 / tmp8
tl.store(out_ptr0 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), tmp9, xmask)
@triton.jit
def triton_poi_fused_clone_2(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 + 0)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK, YBLOCK])
tmp3 = tmp0 + tmp2
tl.store(out_ptr0 + (x2 + 4 * y3), tmp3, xmask & ymask)
@triton.jit
def triton_poi_fused_cat_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 8
x3 = xindex // 8
x1 = xindex // 8 % 4
x2 = xindex // 32
x4 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (4 * x3 + x0), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 8, tl.int64)
tmp9 = tl.load(in_ptr1 + (x1 + 4 * (-4 + x0) + 16 * x2), tmp6 & xmask,
eviction_policy='evict_last', other=0.0)
tmp10 = tl.where(tmp4, tmp5, tmp9)
tl.store(out_ptr0 + x4, tmp10, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11, primals_12
) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 1), (16, 4, 1, 1))
assert_size_stride(primals_2, (4, 4, 4, 1), (16, 4, 1, 1))
assert_size_stride(primals_3, (4, 4, 4, 1), (16, 4, 1, 1))
assert_size_stride(primals_4, (1, 1), (1, 1))
assert_size_stride(primals_5, (1,), (1,))
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, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_11, (4, 8), (8, 1))
assert_size_stride(primals_12, (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_5, reinterpret_tensor(primals_1, (64,
1), (1, 1), 0), primals_4, alpha=1, beta=1, out=buf1)
del primals_4
del primals_5
buf3 = empty_strided_cuda((64, 1), (1, 1), torch.float32)
extern_kernels.addmm(primals_7, reinterpret_tensor(primals_2, (64,
1), (1, 1), 0), primals_6, alpha=1, beta=1, out=buf3)
del primals_6
del primals_7
buf4 = empty_strided_cuda((64, 1), (1, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_3, (64, 1), (1, 1), 0),
primals_8, out=buf4)
del primals_8
buf5 = empty_strided_cuda((4, 4, 4, 1), (16, 1, 4, 64), torch.float32)
buf6 = empty_strided_cuda((4, 4, 4, 1), (16, 1, 4, 64), torch.float32)
get_raw_stream(0)
triton_poi_fused__softmax_div_0[grid(64)](buf1, buf3, buf5, buf6,
64, XBLOCK=64, num_warps=1, num_stages=1)
buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__softmax_div_1[grid(256)](buf1, buf3, buf5, buf6,
buf7, 256, XBLOCK=128, num_warps=4, num_stages=1)
del buf5
buf8 = reinterpret_tensor(buf6, (4, 4, 4, 1, 1), (16, 4, 1, 1, 1), 0)
del buf6
triton_poi_fused_clone_2[grid(16, 4)](buf4, primals_9, buf8, 16, 4,
XBLOCK=4, YBLOCK=8, num_warps=1, num_stages=1)
del primals_9
buf9 = reinterpret_tensor(buf4, (16, 4, 1), (4, 1, 1), 0)
del buf4
extern_kernels.bmm(reinterpret_tensor(buf7, (16, 4, 4), (16, 4, 1),
0), reinterpret_tensor(buf8, (16, 4, 1), (4, 1, 0), 0), out=buf9)
buf10 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
triton_poi_fused_cat_3[grid(128)](buf1, buf9, buf10, 128, XBLOCK=
128, num_warps=4, num_stages=1)
buf11 = reinterpret_tensor(buf9, (16, 4), (4, 1), 0)
del buf9
extern_kernels.addmm(primals_12, reinterpret_tensor(buf10, (16, 8),
(8, 1), 0), reinterpret_tensor(primals_11, (8, 4), (1, 8), 0),
alpha=1, beta=1, out=buf11)
del primals_12
return reinterpret_tensor(buf11, (4, 4, 4), (16, 4, 1), 0
), reinterpret_tensor(primals_1, (64, 1), (1, 1), 0
), buf1, reinterpret_tensor(primals_2, (64, 1), (1, 1), 0
), buf3, reinterpret_tensor(primals_3, (64, 1), (1, 1), 0
), buf7, reinterpret_tensor(buf10, (16, 8), (8, 1), 0
), primals_11, reinterpret_tensor(buf8, (16, 1, 4), (4, 1, 1), 0)
class SelfAttentionNew(nn.Module):
def __init__(self, embed_dims, heads):
super(SelfAttentionNew, self).__init__()
self.heads = heads
self.embed_dims = embed_dims
self.depth = embed_dims // heads
self.query = nn.Linear(self.depth, self.depth)
self.key = nn.Linear(self.depth, self.depth)
self.value = nn.Linear(self.depth, self.depth)
self.fc_out = nn.Linear(self.depth * self.heads * 2, self.embed_dims)
def forward(self, input_0, input_1, input_2, input_3):
primals_4 = self.query.weight
primals_5 = self.query.bias
primals_6 = self.key.weight
primals_7 = self.key.bias
primals_8 = self.value.weight
primals_9 = self.value.bias
primals_11 = self.fc_out.weight
primals_12 = self.fc_out.bias
primals_1 = input_0
primals_2 = input_1
primals_3 = input_2
primals_10 = input_3
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11, primals_12])
return output[0]
|
ShivamRajSharma/Transformer-Text-To-Spech
|
SelfAttention
| false
| 17,930
|
[
"MIT"
] | 10
|
2e1cf84a791497e414fb72ae04d954fce934a32a
|
https://github.com/ShivamRajSharma/Transformer-Text-To-Spech/tree/2e1cf84a791497e414fb72ae04d954fce934a32a
|
ContrastiveLoss
|
import torch
from torchvision.transforms import functional as F
import torch.utils.data
from torch import nn
import torch.nn.functional as F
class ContrastiveLoss(nn.Module):
"""
Contrastive loss
Takes embeddings of two samples and a target label == 1 if samples are from the same class and label == 0 otherwise
output1/output2: embeddings nx2
"""
def __init__(self, margin):
super(ContrastiveLoss, self).__init__()
self.margin = margin
self.eps = 1e-09
def forward(self, output1, output2, target, size_average=True):
target = target
distances = (output2 - output1).pow(2).sum(1)
losses = 0.5 * (target * distances + (1 + -1 * target) * F.relu(
self.margin - (distances + self.eps).sqrt()).pow(2))
return losses.mean() if size_average else losses.sum()
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 [[], {'margin': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
import torch.utils.data
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_pow_sub_sum_0(in_ptr0, in_ptr1, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 16
x1 = xindex // 16
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask)
tmp1 = tl.load(in_ptr1 + (x0 + 64 * x1), xmask)
tmp4 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask)
tmp5 = tl.load(in_ptr1 + (16 + x0 + 64 * x1), xmask)
tmp9 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask)
tmp10 = tl.load(in_ptr1 + (32 + x0 + 64 * x1), xmask)
tmp14 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask)
tmp15 = tl.load(in_ptr1 + (48 + x0 + 64 * x1), xmask)
tmp2 = tmp0 - tmp1
tmp3 = tmp2 * tmp2
tmp6 = tmp4 - tmp5
tmp7 = tmp6 * tmp6
tmp8 = tmp3 + tmp7
tmp11 = tmp9 - tmp10
tmp12 = tmp11 * tmp11
tmp13 = tmp8 + tmp12
tmp16 = tmp14 - tmp15
tmp17 = tmp16 * tmp16
tmp18 = tmp13 + tmp17
tl.store(out_ptr0 + x2, tmp18, xmask)
@triton.jit
def triton_per_fused_add_mean_mul_pow_relu_rsub_sqrt_1(in_out_ptr0, in_ptr0,
in_ptr1, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r2 = rindex
r0 = rindex % 64
tmp0 = tl.load(in_ptr0 + r2, None)
tmp1 = tl.load(in_ptr1 + r0, None, eviction_policy='evict_last')
tmp2 = tmp0 * tmp1
tmp3 = -1.0
tmp4 = tmp0 * tmp3
tmp5 = 1.0
tmp6 = tmp4 + tmp5
tmp7 = 1e-09
tmp8 = tmp1 + tmp7
tmp9 = libdevice.sqrt(tmp8)
tmp10 = 4.0
tmp11 = tmp10 - tmp9
tmp12 = tl.full([1], 0, tl.int32)
tmp13 = triton_helpers.maximum(tmp12, tmp11)
tmp14 = tmp13 * tmp13
tmp15 = tmp6 * tmp14
tmp16 = tmp2 + tmp15
tmp17 = 0.5
tmp18 = tmp16 * tmp17
tmp19 = tl.broadcast_to(tmp18, [RBLOCK])
tmp21 = triton_helpers.promote_to_tensor(tl.sum(tmp19, 0))
tmp22 = 256.0
tmp23 = tmp21 / tmp22
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp23, None)
def call(args):
arg0_1, arg1_1, arg2_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_pow_sub_sum_0[grid(64)](arg1_1, arg2_1, buf0, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del arg1_1
del arg2_1
buf1 = empty_strided_cuda((), (), torch.float32)
buf2 = buf1
del buf1
triton_per_fused_add_mean_mul_pow_relu_rsub_sqrt_1[grid(1)](buf2,
arg0_1, buf0, 1, 256, num_warps=2, num_stages=1)
del arg0_1
del buf0
return buf2,
class ContrastiveLossNew(nn.Module):
"""
Contrastive loss
Takes embeddings of two samples and a target label == 1 if samples are from the same class and label == 0 otherwise
output1/output2: embeddings nx2
"""
def __init__(self, margin):
super(ContrastiveLossNew, self).__init__()
self.margin = margin
self.eps = 1e-09
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]
|
Sigma10010/nuclei_cells_det
|
ContrastiveLoss
| false
| 17,931
|
[
"MIT"
] | 4
|
c074175fec8938472bb4cddabd83d1d0ea78f230
|
https://github.com/Sigma10010/nuclei_cells_det/tree/c074175fec8938472bb4cddabd83d1d0ea78f230
|
AttentionLayer
|
import math
import torch
from torch import nn
from torch.nn import functional as F
import torch.nn.init
def Linear(in_features, out_features, dropout=0.0):
m = nn.Linear(in_features, out_features)
m.weight.data.normal_(mean=0, std=math.sqrt((1 - dropout) / in_features))
m.bias.data.zero_()
return nn.utils.weight_norm(m)
class AttentionLayer(nn.Module):
def __init__(self, conv_channels, embed_dim):
super(AttentionLayer, self).__init__()
self.in_projection = Linear(conv_channels, embed_dim)
self.out_projection = Linear(embed_dim, conv_channels)
self.bmm = torch.bmm
def forward(self, x, wordemb, imgsfeats):
residual = x
x = (self.in_projection(x) + wordemb) * math.sqrt(0.5)
b, c, n = imgsfeats.size()
y = imgsfeats.view(b, c, n)
x = self.bmm(x, y)
sz = x.size()
x = F.softmax(x.view(sz[0] * sz[1], sz[2]))
x = x.view(sz)
attn_scores = x
y = y.permute(0, 2, 1)
x = self.bmm(x, y)
s = y.size(1)
x = x * (s * math.sqrt(1.0 / s))
x = (self.out_projection(x) + residual) * math.sqrt(0.5)
return x, attn_scores
def get_inputs():
return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4]), torch.rand([4, 4, 4])
]
def get_init_inputs():
return [[], {'conv_channels': 4, 'embed_dim': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
import math
from torch import nn
import torch.nn.init
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused__weight_norm_interface_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')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
tmp1 = tmp0 * tmp0
tmp3 = tmp2 * tmp2
tmp4 = tmp1 + tmp3
tmp6 = tmp5 * tmp5
tmp7 = tmp4 + tmp6
tmp9 = tmp8 * tmp8
tmp10 = tmp7 + tmp9
tmp11 = libdevice.sqrt(tmp10)
tl.store(out_ptr0 + x0, tmp11, xmask)
@triton.jit
def triton_poi_fused__weight_norm_interface_1(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
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp3 = tmp1 / tmp2
tmp4 = tmp0 * tmp3
tl.store(out_ptr0 + x2, tmp4, xmask)
@triton.jit
def triton_poi_fused_add_mul_2(in_out_ptr0, in_ptr0, in_ptr1, xnumel,
XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x2, xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp5 = 0.7071067811865476
tmp6 = tmp4 * tmp5
tl.store(in_out_ptr0 + x2, tmp6, xmask)
@triton.jit
def triton_poi_fused__softmax_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x2, tmp9, xmask)
@triton.jit
def triton_poi_fused__softmax_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused_mul_5(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 = 2.0
tmp2 = tmp0 * tmp1
tl.store(in_out_ptr0 + x0, tmp2, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (4, 1), (1, 1))
assert_size_stride(primals_3, (4, 4), (4, 1))
assert_size_stride(primals_4, (4,), (1,))
assert_size_stride(primals_5, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_6, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_7, (4, 1), (1, 1))
assert_size_stride(primals_8, (4, 4), (4, 1))
assert_size_stride(primals_9, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__weight_norm_interface_0[grid(4)](primals_3, buf0,
4, XBLOCK=4, num_warps=1, num_stages=1)
buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused__weight_norm_interface_1[grid(16)](primals_3,
primals_2, buf0, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0),
reinterpret_tensor(buf1, (4, 4), (1, 4), 0), out=buf2)
buf3 = reinterpret_tensor(buf2, (4, 4, 4), (16, 4, 1), 0)
del buf2
triton_poi_fused_add_mul_2[grid(64)](buf3, primals_4, primals_5, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del primals_4
del primals_5
buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf3, primals_6, out=buf4)
buf5 = reinterpret_tensor(buf3, (16, 4), (4, 1), 0)
del buf3
triton_poi_fused__softmax_3[grid(64)](buf4, buf5, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf6 = reinterpret_tensor(buf4, (16, 4), (4, 1), 0)
del buf4
triton_poi_fused__softmax_4[grid(64)](buf5, buf6, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf7 = reinterpret_tensor(buf5, (4, 4, 4), (16, 4, 1), 0)
del buf5
extern_kernels.bmm(reinterpret_tensor(buf6, (4, 4, 4), (16, 4, 1),
0), reinterpret_tensor(primals_6, (4, 4, 4), (16, 1, 4), 0),
out=buf7)
buf8 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
triton_poi_fused__weight_norm_interface_0[grid(4)](primals_8, buf8,
4, XBLOCK=4, num_warps=1, num_stages=1)
buf9 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused__weight_norm_interface_1[grid(16)](primals_8,
primals_7, buf8, buf9, 16, XBLOCK=16, num_warps=1, num_stages=1)
buf10 = buf7
del buf7
triton_poi_fused_mul_5[grid(64)](buf10, 64, XBLOCK=64, num_warps=1,
num_stages=1)
buf11 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf10, (16, 4), (4, 1), 0),
reinterpret_tensor(buf9, (4, 4), (1, 4), 0), out=buf11)
buf12 = reinterpret_tensor(buf11, (4, 4, 4), (16, 4, 1), 0)
del buf11
triton_poi_fused_add_mul_2[grid(64)](buf12, primals_9, primals_1,
64, XBLOCK=64, num_warps=1, num_stages=1)
del primals_9
return (buf12, reinterpret_tensor(buf6, (4, 4, 4), (16, 4, 1), 0), buf1,
buf9, primals_2, primals_3, primals_7, primals_8, buf0,
reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), buf6,
reinterpret_tensor(primals_6, (4, 4, 4), (16, 1, 4), 0), buf8,
reinterpret_tensor(buf10, (16, 4), (4, 1), 0), buf9)
def Linear(in_features, out_features, dropout=0.0):
m = nn.Linear(in_features, out_features)
m.weight.data.normal_(mean=0, std=math.sqrt((1 - dropout) / in_features))
m.bias.data.zero_()
return nn.utils.weight_norm(m)
class AttentionLayerNew(nn.Module):
def __init__(self, conv_channels, embed_dim):
super(AttentionLayerNew, self).__init__()
self.in_projection = Linear(conv_channels, embed_dim)
self.out_projection = Linear(embed_dim, conv_channels)
self.bmm = torch.bmm
def forward(self, input_0, input_1, input_2):
primals_4 = self.in_projection.bias
primals_2 = self.in_projection.weight_g
primals_3 = self.in_projection.weight_v
primals_9 = self.out_projection.bias
primals_7 = self.out_projection.weight_g
primals_8 = self.out_projection.weight_v
primals_1 = input_0
primals_5 = input_1
primals_6 = input_2
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9])
return output[0], output[1]
|
Shiyang-Yan/Discrete-continous-PG-for-Retrieval
|
AttentionLayer
| false
| 17,932
|
[
"Apache-2.0"
] | 8
|
39fd7a81f732ae043c2ea20352a0c55b72834639
|
https://github.com/Shiyang-Yan/Discrete-continous-PG-for-Retrieval/tree/39fd7a81f732ae043c2ea20352a0c55b72834639
|
wide_basic
|
import torch
import torch.nn as nn
import torch.utils
import torch.utils.data
def get_norm(n_filters, norm):
if norm is None:
return Identity()
elif norm == 'batch':
return nn.BatchNorm2d(n_filters, momentum=0.9)
elif norm == 'instance':
return nn.InstanceNorm2d(n_filters, affine=True)
elif norm == 'layer':
return nn.GroupNorm(1, n_filters)
elif norm == 'act':
return norms.ActNorm(n_filters, False)
class Identity(nn.Module):
def __init__(self, *args, **kwargs):
super().__init__()
def forward(self, x):
return x
class wide_basic(nn.Module):
def __init__(self, in_planes, planes, dropout_rate, stride=1, norm=None,
leak=0.2):
super(wide_basic, self).__init__()
self.lrelu = nn.LeakyReLU(leak)
self.bn1 = get_norm(in_planes, norm)
self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, padding=1,
bias=True)
self.dropout = Identity() if dropout_rate == 0.0 else nn.Dropout(p=
dropout_rate)
self.bn2 = get_norm(planes, norm)
self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride,
padding=1, bias=True)
self.shortcut = nn.Sequential()
if stride != 1 or in_planes != planes:
self.shortcut = nn.Sequential(nn.Conv2d(in_planes, planes,
kernel_size=1, stride=stride, bias=True))
def forward(self, x):
out = self.dropout(self.conv1(self.lrelu(self.bn1(x))))
out = self.conv2(self.lrelu(self.bn2(out)))
out += self.shortcut(x)
return out
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_planes': 4, 'planes': 4, 'dropout_rate': 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
import torch.nn as nn
import torch.utils
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_leaky_relu_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 0.0
tmp2 = tmp0 > tmp1
tmp3 = 0.2
tmp4 = tmp0 * tmp3
tmp5 = tl.where(tmp2, tmp0, tmp4)
tl.store(out_ptr0 + x0, tmp5, xmask)
@triton.jit
def triton_poi_fused_convolution_leaky_relu_1(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp5 = 0.2
tmp6 = tmp2 * tmp5
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(out_ptr0 + x3, tmp4, xmask)
tl.store(out_ptr1 + x3, tmp7, xmask)
@triton.jit
def triton_poi_fused_add_convolution_2(in_out_ptr0, in_ptr0, in_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x3, xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tl.store(in_out_ptr0 + x3, tmp4, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_leaky_relu_0[grid(256)](primals_1, buf0, 256,
XBLOCK=128, num_warps=4, num_stages=1)
buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1))
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_convolution_leaky_relu_1[grid(256)](buf1,
primals_3, buf2, buf3, 256, XBLOCK=256, num_warps=4, num_stages=1)
del buf1
del primals_3
buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 4, 4, 4), (64, 16, 4, 1))
buf5 = buf4
del buf4
triton_poi_fused_add_convolution_2[grid(256)](buf5, primals_5,
primals_1, 256, XBLOCK=128, num_warps=4, num_stages=1)
del primals_1
del primals_5
return buf5, primals_2, primals_4, buf0, buf2, buf3
def get_norm(n_filters, norm):
if norm is None:
return Identity()
elif norm == 'batch':
return nn.BatchNorm2d(n_filters, momentum=0.9)
elif norm == 'instance':
return nn.InstanceNorm2d(n_filters, affine=True)
elif norm == 'layer':
return nn.GroupNorm(1, n_filters)
elif norm == 'act':
return norms.ActNorm(n_filters, False)
class Identity(nn.Module):
def __init__(self, *args, **kwargs):
super().__init__()
def forward(self, x):
return x
class wide_basicNew(nn.Module):
def __init__(self, in_planes, planes, dropout_rate, stride=1, norm=None,
leak=0.2):
super(wide_basicNew, self).__init__()
self.lrelu = nn.LeakyReLU(leak)
self.bn1 = get_norm(in_planes, norm)
self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, padding=1,
bias=True)
self.dropout = Identity() if dropout_rate == 0.0 else nn.Dropout(p=
dropout_rate)
self.bn2 = get_norm(planes, norm)
self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride,
padding=1, bias=True)
self.shortcut = nn.Sequential()
if stride != 1 or in_planes != planes:
self.shortcut = nn.Sequential(nn.Conv2d(in_planes, planes,
kernel_size=1, stride=stride, bias=True))
def forward(self, input_0):
primals_2 = self.conv1.weight
primals_3 = self.conv1.bias
primals_4 = self.conv2.weight
primals_5 = self.conv2.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
Silent-Zebra/JEM
|
wide_basic
| false
| 17,933
|
[
"Apache-2.0"
] | 6
|
33440aff8429d9a24a8ba858d0209f4b48be8e05
|
https://github.com/Silent-Zebra/JEM/tree/33440aff8429d9a24a8ba858d0209f4b48be8e05
|
CPUReverseForgetMult
|
import torch
class CPUReverseForgetMult(torch.nn.Module):
def __init__(self):
super(CPUReverseForgetMult, self).__init__()
def forward(self, f, x, hidden_init=None):
result = []
forgets = f.split(1, dim=0)[::-1]
inputs = (f * x).split(1, dim=0)[::-1]
prev_h = hidden_init
for i, h in enumerate(inputs):
h = h.squeeze()
if prev_h is not None:
h = h + (1 - forgets[i]) * prev_h
result.append(h)
prev_h = h
result = result[::-1]
return torch.cat(result, dim=0)
def get_inputs():
return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_add_cat_mul_rsub_0(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, out_ptr2, out_ptr3, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 16
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + (64 + x2), xmask)
tmp3 = tl.load(in_ptr0 + (16 + x0), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr1 + (128 + x2), xmask)
tmp8 = tl.load(in_ptr0 + (32 + x0), xmask, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr1 + (192 + x2), xmask)
tmp16 = tl.load(in_ptr1 + x2, xmask)
tmp18 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 * tmp1
tmp4 = 1.0
tmp5 = tmp4 - tmp3
tmp7 = tmp0 * tmp6
tmp9 = tmp4 - tmp8
tmp11 = tmp0 * tmp10
tmp12 = tmp9 * tmp11
tmp13 = tmp7 + tmp12
tmp14 = tmp5 * tmp13
tmp15 = tmp2 + tmp14
tmp17 = tmp0 * tmp16
tmp19 = tmp4 - tmp18
tmp20 = tmp19 * tmp15
tmp21 = tmp17 + tmp20
tl.store(out_ptr0 + x2, tmp15, xmask)
tl.store(out_ptr1 + x2, tmp13, xmask)
tl.store(out_ptr2 + x2, tmp21, xmask)
tl.store(out_ptr3 + x2, tmp11, 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, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf4 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
buf0 = reinterpret_tensor(buf4, (4, 4, 4), (16, 4, 1), 64)
buf2 = reinterpret_tensor(buf4, (4, 4, 4), (16, 4, 1), 128)
buf1 = reinterpret_tensor(buf4, (4, 4, 4), (16, 4, 1), 0)
buf3 = reinterpret_tensor(buf4, (4, 4, 4), (16, 4, 1), 192)
get_raw_stream(0)
triton_poi_fused_add_cat_mul_rsub_0[grid(64)](arg0_1, arg1_1, buf0,
buf2, buf1, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1)
del arg0_1
del arg1_1
return buf4,
class CPUReverseForgetMultNew(torch.nn.Module):
def __init__(self):
super(CPUReverseForgetMultNew, 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]
|
Smerity/pytorch-qrnn
|
CPUReverseForgetMult
| false
| 17,934
|
[
"BSD-3-Clause"
] | 4
|
907c8ea53f689136fcc50996b6474de967745202
|
https://github.com/Smerity/pytorch-qrnn/tree/907c8ea53f689136fcc50996b6474de967745202
|
Project3D
|
import torch
import torch.nn as nn
class Project3D(nn.Module):
"""Layer which projects 3D points into a camera with intrinsics K and at position T
"""
def __init__(self, batch_size, height, width, eps=1e-07):
super(Project3D, self).__init__()
self.batch_size = batch_size
self.height = height
self.width = width
self.eps = eps
def forward(self, points, K, T):
P = torch.matmul(K, T)[:, :3, :]
cam_points = torch.matmul(P, points)
pix_coords = cam_points[:, :2, :] / (cam_points[:, 2, :].unsqueeze(
1) + self.eps)
pix_coords = pix_coords.view(self.batch_size, 2, self.height, self.
width)
pix_coords = pix_coords.permute(0, 2, 3, 1)
pix_coords[..., 0] /= self.width - 1
pix_coords[..., 1] /= self.height - 1
pix_coords = (pix_coords - 0.5) * 2
return pix_coords
def get_inputs():
return [torch.rand([4, 3, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand(
[4, 4, 4, 4])]
def get_init_inputs():
return [[], {'batch_size': 4, 'height': 4, 'width': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
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 = 192
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 48
x1 = xindex // 48
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask)
tl.store(out_ptr0 + x2, tmp0, xmask)
@triton.jit
def triton_poi_fused_mul_sub_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16 % 2
x0 = xindex % 16
x2 = xindex // 32
x3 = xindex % 32
x4 = xindex
tmp7 = tl.load(in_ptr0 + (x0 + 48 * x2), xmask, eviction_policy=
'evict_last')
tmp8 = tl.load(in_ptr0 + (32 + x0 + 48 * x2), xmask, eviction_policy=
'evict_last')
tmp15 = tl.load(in_ptr0 + (16 + x0 + 48 * x2), xmask, eviction_policy=
'evict_last')
tmp22 = tl.load(in_ptr0 + (x3 + 48 * x2), xmask)
tmp0 = x1
tmp1 = tl.full([1], 1, tl.int32)
tmp2 = tmp0 == tmp1
tmp3 = tmp1 == tmp1
tmp4 = tl.full([1], 0, tl.int32)
tmp5 = tmp1 == tmp4
tmp6 = tmp4 == tmp4
tmp9 = 1e-07
tmp10 = tmp8 + tmp9
tmp11 = tmp7 / tmp10
tmp12 = 0.3333333333333333
tmp13 = tmp11 * tmp12
tmp14 = tl.where(tmp6, tmp13, tmp11)
tmp16 = tmp15 / tmp10
tmp17 = tl.where(tmp5, tmp13, tmp16)
tmp18 = tl.where(tmp5, tmp14, tmp17)
tmp19 = tmp18 * tmp12
tmp20 = tl.where(tmp3, tmp19, tmp18)
tmp21 = tmp0 == tmp4
tmp23 = tmp22 / tmp10
tmp24 = tl.where(tmp21, tmp13, tmp23)
tmp25 = tl.where(tmp21, tmp14, tmp24)
tmp26 = tl.where(tmp2, tmp19, tmp25)
tmp27 = tl.where(tmp2, tmp20, tmp26)
tmp28 = 0.5
tmp29 = tmp27 - tmp28
tmp30 = 2.0
tmp31 = tmp29 * tmp30
tl.store(out_ptr0 + x4, tmp31, 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, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg2_1, (4, 3, 4, 4), (48, 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(arg1_1, (16, 4, 4), (16, 4, 1
), 0), reinterpret_tensor(arg0_1, (16, 4, 4), (16, 4, 1), 0),
out=buf0)
del arg0_1
del arg1_1
buf1 = empty_strided_cuda((4, 3, 4, 4), (48, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(192)](buf0, buf1, 192, XBLOCK=128,
num_warps=4, num_stages=1)
del buf0
buf2 = empty_strided_cuda((12, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf1, (12, 4, 4), (16, 4, 1),
0), reinterpret_tensor(arg2_1, (12, 4, 4), (16, 4, 1), 0), out=buf2
)
del arg2_1
del buf1
buf3 = empty_strided_cuda((4, 4, 4, 2), (32, 4, 1, 16), torch.float32)
triton_poi_fused_mul_sub_1[grid(128)](buf2, buf3, 128, XBLOCK=128,
num_warps=4, num_stages=1)
del buf2
return buf3,
class Project3DNew(nn.Module):
"""Layer which projects 3D points into a camera with intrinsics K and at position T
"""
def __init__(self, batch_size, height, width, eps=1e-07):
super(Project3DNew, self).__init__()
self.batch_size = batch_size
self.height = height
self.width = width
self.eps = eps
def forward(self, input_0, input_1, input_2):
arg2_1 = input_0
arg0_1 = input_1
arg1_1 = input_2
output = call([arg0_1, arg1_1, arg2_1])
return output[0]
|
Sid1057/sid1057.github.io
|
Project3D
| false
| 17,935
|
[
"MIT"
] | 4
|
623d1731e308b42b6f86304dcfd671a061b414bf
|
https://github.com/Sid1057/sid1057.github.io/tree/623d1731e308b42b6f86304dcfd671a061b414bf
|
ConvBlock
|
import torch
import torch.nn as nn
class Conv3x3(nn.Module):
"""Layer to pad and convolve input
"""
def __init__(self, in_channels, out_channels, use_refl=True):
super(Conv3x3, self).__init__()
if use_refl:
self.pad = nn.ReflectionPad2d(1)
else:
self.pad = nn.ZeroPad2d(1)
self.conv = nn.Conv2d(int(in_channels), int(out_channels), 3)
def forward(self, x):
out = self.pad(x)
out = self.conv(out)
return out
class ConvBlock(nn.Module):
"""Layer to perform a convolution followed by ELU
"""
def __init__(self, in_channels, out_channels):
super(ConvBlock, self).__init__()
self.conv = Conv3x3(in_channels, out_channels)
self.nonlin = nn.ELU(inplace=True)
def forward(self, x):
out = self.conv(x)
out = self.nonlin(out)
return out
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'out_channels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.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_poi_fused_reflection_pad2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 576
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 6
x1 = xindex // 6 % 6
x2 = xindex // 36
x3 = xindex
tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2),
xmask, eviction_policy='evict_last')
tl.store(out_ptr0 + x3, tmp0, xmask)
@triton.jit
def triton_poi_fused_convolution_elu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp5 = 1.0
tmp6 = tmp2 * tmp5
tmp7 = libdevice.expm1(tmp6)
tmp8 = tmp7 * tmp5
tmp9 = tl.where(tmp4, tmp6, tmp8)
tl.store(in_out_ptr0 + x3, 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, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_3, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_reflection_pad2d_0[grid(576)](primals_1, buf0, 576,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_1
buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1))
buf2 = buf1
del buf1
triton_poi_fused_convolution_elu_1[grid(256)](buf2, primals_3, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_3
return buf2, primals_2, buf0, buf2
class Conv3x3(nn.Module):
"""Layer to pad and convolve input
"""
def __init__(self, in_channels, out_channels, use_refl=True):
super(Conv3x3, self).__init__()
if use_refl:
self.pad = nn.ReflectionPad2d(1)
else:
self.pad = nn.ZeroPad2d(1)
self.conv = nn.Conv2d(int(in_channels), int(out_channels), 3)
def forward(self, x):
out = self.pad(x)
out = self.conv(out)
return out
class ConvBlockNew(nn.Module):
"""Layer to perform a convolution followed by ELU
"""
def __init__(self, in_channels, out_channels):
super(ConvBlockNew, self).__init__()
self.conv = Conv3x3(in_channels, out_channels)
self.nonlin = nn.ELU(inplace=True)
def forward(self, input_0):
primals_2 = self.conv.conv.weight
primals_3 = self.conv.conv.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
Sid1057/sid1057.github.io
|
ConvBlock
| false
| 17,936
|
[
"MIT"
] | 4
|
623d1731e308b42b6f86304dcfd671a061b414bf
|
https://github.com/Sid1057/sid1057.github.io/tree/623d1731e308b42b6f86304dcfd671a061b414bf
|
VirtualBatchNorm1d
|
from torch.nn import Module
import torch
import torch.utils
import torch.utils.data
from torch.nn.parameter import Parameter
from torch.nn.modules import Module
class VirtualBatchNorm1d(Module):
"""
Module for Virtual Batch Normalization.
Implementation borrowed and modified from Rafael_Valle's code + help of SimonW from this discussion thread:
https://discuss.pytorch.org/t/parameter-grad-of-conv-weight-is-none-after-virtual-batch-normalization/9036
"""
def __init__(self, num_features: 'int', eps: 'float'=1e-05):
super().__init__()
self.num_features = num_features
self.eps = eps
self.ref_mean = self.register_parameter('ref_mean', None)
self.ref_mean_sq = self.register_parameter('ref_mean_sq', None)
gamma = torch.normal(mean=torch.ones(1, num_features, 1), std=0.02)
self.gamma = Parameter(gamma.float())
self.beta = Parameter(torch.FloatTensor(1, num_features, 1).fill_(0))
def get_stats(self, x):
"""
Calculates mean and mean square for given batch x.
Args:
x: tensor containing batch of activations
Returns:
mean: mean tensor over features
mean_sq: squared mean tensor over features
"""
mean = x.mean(2, keepdim=True).mean(0, keepdim=True)
mean_sq = (x ** 2).mean(2, keepdim=True).mean(0, keepdim=True)
return mean, mean_sq
def forward(self, x, ref_mean: 'None', ref_mean_sq: 'None'):
"""
Forward pass of virtual batch normalization.
Virtual batch normalization require two forward passes
for reference batch and train batch, respectively.
The input parameter is_reference should indicate whether it is a forward pass
for reference batch or not.
Args:
x: input tensor
is_reference(bool): True if forwarding for reference batch
Result:
x: normalized batch tensor
"""
mean, mean_sq = self.get_stats(x)
if ref_mean is None or ref_mean_sq is None:
mean = mean.clone().detach()
mean_sq = mean_sq.clone().detach()
out = self._normalize(x, mean, mean_sq)
else:
batch_size = x.size(0)
new_coeff = 1.0 / (batch_size + 1.0)
old_coeff = 1.0 - new_coeff
mean = new_coeff * mean + old_coeff * ref_mean
mean_sq = new_coeff * mean_sq + old_coeff * ref_mean_sq
out = self._normalize(x, mean, mean_sq)
return out, mean, mean_sq
def _normalize(self, x, mean, mean_sq):
"""
Normalize tensor x given the statistics.
Args:
x: input tensor
mean: mean over features. it has size [1:num_features:]
mean_sq: squared means over features.
Result:
x: normalized batch tensor
"""
assert mean_sq is not None
assert mean is not None
assert len(x.size()) == 3
if mean.size(1) != self.num_features:
raise Exception(
'Mean size not equal to number of featuers : given {}, expected {}'
.format(mean.size(1), self.num_features))
if mean_sq.size(1) != self.num_features:
raise Exception(
'Squared mean tensor size not equal to number of features : given {}, expected {}'
.format(mean_sq.size(1), self.num_features))
std = torch.sqrt(self.eps + mean_sq - mean ** 2)
x = x - mean
x = x / std
x = x * self.gamma
x = x + self.beta
return x
def __repr__(self):
return '{name}(num_features={num_features}, eps={eps}'.format(name=
self.__class__.__name__, **self.__dict__)
def get_inputs():
return [torch.rand([4, 4, 4]), torch.rand([4, 4]), torch.rand([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
from torch.nn import Module
import torch.utils
import torch.utils.data
from torch.nn.parameter import Parameter
from torch.nn.modules import Module
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_pow_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK:
tl.constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr0 + (16 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp10 = tl.load(in_ptr0 + (17 + 4 * x0), xmask, eviction_policy=
'evict_last')
tmp12 = tl.load(in_ptr0 + (18 + 4 * x0), xmask, eviction_policy=
'evict_last')
tmp14 = tl.load(in_ptr0 + (19 + 4 * x0), xmask, eviction_policy=
'evict_last')
tmp18 = tl.load(in_ptr0 + (32 + 4 * x0), xmask, eviction_policy=
'evict_last')
tmp19 = tl.load(in_ptr0 + (33 + 4 * x0), xmask, eviction_policy=
'evict_last')
tmp21 = tl.load(in_ptr0 + (34 + 4 * x0), xmask, eviction_policy=
'evict_last')
tmp23 = tl.load(in_ptr0 + (35 + 4 * x0), xmask, eviction_policy=
'evict_last')
tmp27 = tl.load(in_ptr0 + (48 + 4 * x0), xmask, eviction_policy=
'evict_last')
tmp28 = tl.load(in_ptr0 + (49 + 4 * x0), xmask, eviction_policy=
'evict_last')
tmp30 = tl.load(in_ptr0 + (50 + 4 * x0), xmask, eviction_policy=
'evict_last')
tmp32 = tl.load(in_ptr0 + (51 + 4 * x0), xmask, eviction_policy=
'evict_last')
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp7 = 4.0
tmp8 = tmp6 / tmp7
tmp11 = tmp9 + tmp10
tmp13 = tmp11 + tmp12
tmp15 = tmp13 + tmp14
tmp16 = tmp15 / tmp7
tmp17 = tmp8 + tmp16
tmp20 = tmp18 + tmp19
tmp22 = tmp20 + tmp21
tmp24 = tmp22 + tmp23
tmp25 = tmp24 / tmp7
tmp26 = tmp17 + tmp25
tmp29 = tmp27 + tmp28
tmp31 = tmp29 + tmp30
tmp33 = tmp31 + tmp32
tmp34 = tmp33 / tmp7
tmp35 = tmp26 + tmp34
tmp36 = tmp35 / tmp7
tmp37 = tmp0 * tmp0
tmp38 = tmp1 * tmp1
tmp39 = tmp37 + tmp38
tmp40 = tmp3 * tmp3
tmp41 = tmp39 + tmp40
tmp42 = tmp5 * tmp5
tmp43 = tmp41 + tmp42
tmp44 = tmp43 / tmp7
tmp45 = tmp9 * tmp9
tmp46 = tmp10 * tmp10
tmp47 = tmp45 + tmp46
tmp48 = tmp12 * tmp12
tmp49 = tmp47 + tmp48
tmp50 = tmp14 * tmp14
tmp51 = tmp49 + tmp50
tmp52 = tmp51 / tmp7
tmp53 = tmp44 + tmp52
tmp54 = tmp18 * tmp18
tmp55 = tmp19 * tmp19
tmp56 = tmp54 + tmp55
tmp57 = tmp21 * tmp21
tmp58 = tmp56 + tmp57
tmp59 = tmp23 * tmp23
tmp60 = tmp58 + tmp59
tmp61 = tmp60 / tmp7
tmp62 = tmp53 + tmp61
tmp63 = tmp27 * tmp27
tmp64 = tmp28 * tmp28
tmp65 = tmp63 + tmp64
tmp66 = tmp30 * tmp30
tmp67 = tmp65 + tmp66
tmp68 = tmp32 * tmp32
tmp69 = tmp67 + tmp68
tmp70 = tmp69 / tmp7
tmp71 = tmp62 + tmp70
tmp72 = tmp71 / tmp7
tl.store(out_ptr0 + x0, tmp36, xmask)
tl.store(out_ptr1 + x0, tmp72, xmask)
@triton.jit
def triton_poi_fused_add_mul_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 4
x2 = xindex
tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x2, xmask)
tmp1 = 0.2
tmp2 = tmp0 * tmp1
tmp4 = 0.8
tmp5 = tmp3 * tmp4
tmp6 = tmp2 + tmp5
tl.store(out_ptr0 + x2, tmp6, xmask)
@triton.jit
def triton_poi_fused_add_div_mul_pow_sqrt_sub_2(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x4 = xindex % 16
x1 = xindex // 4 % 4
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + x4, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + x4, xmask, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 1e-05
tmp5 = tmp3 + tmp4
tmp6 = tmp1 * tmp1
tmp7 = tmp5 - tmp6
tmp8 = libdevice.sqrt(tmp7)
tmp9 = tmp2 / tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tl.store(out_ptr0 + x3, tmp13, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4, 4), (4, 1))
assert_size_stride(primals_4, (1, 4, 1), (4, 1, 1))
assert_size_stride(primals_5, (1, 4, 1), (4, 1, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((1, 4, 1), (4, 1, 4), torch.float32)
buf1 = empty_strided_cuda((1, 4, 1), (4, 1, 4), torch.float32)
get_raw_stream(0)
triton_poi_fused_mean_pow_0[grid(4)](primals_1, buf0, buf1, 4,
XBLOCK=4, num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((1, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_mul_1[grid(16)](buf0, primals_2, buf2, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del buf0
del primals_2
buf3 = empty_strided_cuda((1, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_mul_1[grid(16)](buf1, primals_3, buf3, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del buf1
del primals_3
buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_div_mul_pow_sqrt_sub_2[grid(64)](primals_1,
buf2, buf3, primals_4, primals_5, buf4, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del primals_4
del primals_5
return buf4, buf2, buf3, primals_1, buf2, buf3
class VirtualBatchNorm1dNew(Module):
"""
Module for Virtual Batch Normalization.
Implementation borrowed and modified from Rafael_Valle's code + help of SimonW from this discussion thread:
https://discuss.pytorch.org/t/parameter-grad-of-conv-weight-is-none-after-virtual-batch-normalization/9036
"""
def __init__(self, num_features: 'int', eps: 'float'=1e-05):
super().__init__()
self.num_features = num_features
self.eps = eps
self.ref_mean = self.register_parameter('ref_mean', None)
self.ref_mean_sq = self.register_parameter('ref_mean_sq', None)
gamma = torch.normal(mean=torch.ones(1, num_features, 1), std=0.02)
self.gamma = Parameter(gamma.float())
self.beta = Parameter(torch.FloatTensor(1, num_features, 1).fill_(0))
def get_stats(self, x):
"""
Calculates mean and mean square for given batch x.
Args:
x: tensor containing batch of activations
Returns:
mean: mean tensor over features
mean_sq: squared mean tensor over features
"""
mean = x.mean(2, keepdim=True).mean(0, keepdim=True)
mean_sq = (x ** 2).mean(2, keepdim=True).mean(0, keepdim=True)
return mean, mean_sq
def _normalize(self, x, mean, mean_sq):
"""
Normalize tensor x given the statistics.
Args:
x: input tensor
mean: mean over features. it has size [1:num_features:]
mean_sq: squared means over features.
Result:
x: normalized batch tensor
"""
assert mean_sq is not None
assert mean is not None
assert len(x.size()) == 3
if mean.size(1) != self.num_features:
raise Exception(
'Mean size not equal to number of featuers : given {}, expected {}'
.format(mean.size(1), self.num_features))
if mean_sq.size(1) != self.num_features:
raise Exception(
'Squared mean tensor size not equal to number of features : given {}, expected {}'
.format(mean_sq.size(1), self.num_features))
std = torch.sqrt(self.eps + mean_sq - mean ** 2)
x = x - mean
x = x / std
x = x * self.gamma
x = x + self.beta
return x
def __repr__(self):
return '{name}(num_features={num_features}, eps={eps}'.format(name=
self.__class__.__name__, **self.__dict__)
def forward(self, input_0, input_1, input_2):
primals_4 = self.gamma
primals_5 = self.beta
primals_1 = input_0
primals_2 = input_1
primals_3 = input_2
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0], output[1], output[2]
|
Silent-Zebra/JEM
|
VirtualBatchNorm1d
| false
| 17,937
|
[
"Apache-2.0"
] | 6
|
33440aff8429d9a24a8ba858d0209f4b48be8e05
|
https://github.com/Silent-Zebra/JEM/tree/33440aff8429d9a24a8ba858d0209f4b48be8e05
|
WeightNet_DW
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class WeightNet_DW(nn.Module):
""" Here we show a grouping manner when we apply
WeightNet to a depthwise convolution. The grouped
fc layer directly generates the convolutional kernel,
has fewer parameters while achieving comparable results.
This layer has M/G*inp inputs, inp groups and inp*ksize*ksize outputs.
Args:
inp (int): Number of input channels
oup (int): Number of output channels
ksize (int): Size of the convolving kernel
stride (int): Stride of the convolution
"""
def __init__(self, inp, ksize, stride):
super().__init__()
self.M = 2
self.G = 2
self.pad = ksize // 2
inp_gap = max(16, inp // 16)
self.inp = inp
self.ksize = ksize
self.stride = stride
self.wn_fc1 = nn.Conv2d(inp_gap, self.M // self.G * inp, 1, 1, 0,
groups=1, bias=True)
self.sigmoid = nn.Sigmoid()
self.wn_fc2 = nn.Conv2d(self.M // self.G * inp, inp * ksize * ksize,
1, 1, 0, groups=inp, bias=False)
def forward(self, x, x_gap):
""" Input:
x (bs*c*h*w): the output feature from previous convolution layer
x_gap (bs*inp_gap*1*1): the output feature from reduction layer
"""
x_w = self.wn_fc1(x_gap)
x_w = self.sigmoid(x_w)
x_w = self.wn_fc2(x_w)
batch_size = x.shape[0]
x = x.reshape(1, -1, x.shape[2], x.shape[3])
x_w = x_w.reshape(-1, 1, self.ksize, self.ksize)
x = F.conv2d(x, weight=x_w, stride=self.stride, padding=self.pad,
groups=batch_size * self.inp)
x = x.reshape(-1, self.inp, x.shape[2], x.shape[3])
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 16, 64, 64])]
def get_init_inputs():
return [[], {'inp': 4, 'ksize': 4, 'stride': 1}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 64
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
x2 = xindex
y3 = yindex
y0 = yindex % 16
y1 = yindex // 16
tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (y0 + 16 * x2 + 65536 * y1), tmp0, ymask)
@triton.jit
def triton_poi_fused_convolution_sigmoid_1(in_out_ptr0, in_ptr0, xnumel,
XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, None)
tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.sigmoid(tmp2)
tl.store(in_out_ptr0 + x2, tmp3, None)
@triton.jit
def triton_poi_fused_view_2(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
x1 = xindex
y0 = yindex
tmp0 = tl.load(in_ptr0 + (x1 + 16 * y0), xmask & ymask)
tl.store(out_ptr0 + (y0 + 16 * x1), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_view_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex
tmp0 = tl.load(in_ptr0 + (64 * (x0 % 4096) + 262144 * (x0 // 262144) +
x0 // 4096 % 64), None, eviction_policy='evict_last')
tl.store(out_ptr0 + x0, tmp0, None)
@triton.jit
def triton_poi_fused_view_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
xnumel = 25
yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1)
) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x1 = xindex
y0 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 65536 * x1), xmask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (x1 + 25 * y0), tmp0, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 16, 1, 1), (16, 1, 1, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 16, 64, 64), (65536, 4096, 64, 1))
assert_size_stride(primals_4, (64, 1, 1, 1), (1, 1, 1, 1))
assert_size_stride(primals_5, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 16, 64, 64), (65536, 1, 1024, 16),
torch.float32)
get_raw_stream(0)
triton_poi_fused_0[grid(64, 4096)](primals_3, buf0, 64, 4096,
XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
del primals_3
buf1 = extern_kernels.convolution(buf0, primals_1, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf1, (4, 4, 64, 64), (16384, 1, 256, 4))
buf2 = buf1
del buf1
triton_poi_fused_convolution_sigmoid_1[grid(65536)](buf2, primals_2,
65536, XBLOCK=256, num_warps=4, num_stages=1)
del primals_2
buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=4, bias=None)
assert_size_stride(buf3, (4, 64, 64, 64), (262144, 1, 4096, 64))
buf4 = empty_strided_cuda((1, 16, 4, 4), (256, 1, 64, 16), torch.
float32)
triton_poi_fused_view_2[grid(16, 16)](primals_5, buf4, 16, 16,
XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1)
del primals_5
buf5 = empty_strided_cuda((65536, 1, 4, 4), (16, 4, 4, 1), torch.
float32)
triton_poi_fused_view_3[grid(1048576)](buf3, buf5, 1048576, XBLOCK=
1024, num_warps=4, num_stages=1)
del buf3
buf6 = extern_kernels.convolution(buf4, buf5, stride=(1, 1),
padding=(2, 2), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=16, bias=None)
assert_size_stride(buf6, (1, 65536, 5, 5), (1638400, 1, 327680, 65536))
buf7 = empty_strided_cuda((16384, 4, 5, 5), (100, 25, 5, 1), torch.
float32)
triton_poi_fused_view_4[grid(65536, 25)](buf6, buf7, 65536, 25,
XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
del buf6
return buf7, primals_1, buf0, primals_4, buf2, buf4, buf5
class WeightNet_DWNew(nn.Module):
""" Here we show a grouping manner when we apply
WeightNet to a depthwise convolution. The grouped
fc layer directly generates the convolutional kernel,
has fewer parameters while achieving comparable results.
This layer has M/G*inp inputs, inp groups and inp*ksize*ksize outputs.
Args:
inp (int): Number of input channels
oup (int): Number of output channels
ksize (int): Size of the convolving kernel
stride (int): Stride of the convolution
"""
def __init__(self, inp, ksize, stride):
super().__init__()
self.M = 2
self.G = 2
self.pad = ksize // 2
inp_gap = max(16, inp // 16)
self.inp = inp
self.ksize = ksize
self.stride = stride
self.wn_fc1 = nn.Conv2d(inp_gap, self.M // self.G * inp, 1, 1, 0,
groups=1, bias=True)
self.sigmoid = nn.Sigmoid()
self.wn_fc2 = nn.Conv2d(self.M // self.G * inp, inp * ksize * ksize,
1, 1, 0, groups=inp, bias=False)
def forward(self, input_0, input_1):
primals_1 = self.wn_fc1.weight
primals_2 = self.wn_fc1.bias
primals_4 = self.wn_fc2.weight
primals_5 = input_0
primals_3 = input_1
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
Sense-GVT/BigPretrain
|
WeightNet_DW
| false
| 17,938
|
[
"Apache-2.0"
] | 8
|
d8d9b43d94dd1364c18c1e5ba21b85a31cdbba9e
|
https://github.com/Sense-GVT/BigPretrain/tree/d8d9b43d94dd1364c18c1e5ba21b85a31cdbba9e
|
SSIM
|
import torch
import torch.nn as nn
class SSIM(nn.Module):
"""Layer to compute the SSIM loss between a pair of images
"""
def __init__(self):
super(SSIM, self).__init__()
self.mu_x_pool = nn.AvgPool2d(3, 1)
self.mu_y_pool = nn.AvgPool2d(3, 1)
self.sig_x_pool = nn.AvgPool2d(3, 1)
self.sig_y_pool = nn.AvgPool2d(3, 1)
self.sig_xy_pool = nn.AvgPool2d(3, 1)
self.refl = nn.ReflectionPad2d(1)
self.C1 = 0.01 ** 2
self.C2 = 0.03 ** 2
def forward(self, x, y):
x = self.refl(x)
y = self.refl(y)
mu_x = self.mu_x_pool(x)
mu_y = self.mu_y_pool(y)
sigma_x = self.sig_x_pool(x ** 2) - mu_x ** 2
sigma_y = self.sig_y_pool(y ** 2) - mu_y ** 2
sigma_xy = self.sig_xy_pool(x * y) - mu_x * mu_y
SSIM_n = (2 * mu_x * mu_y + self.C1) * (2 * sigma_xy + self.C2)
SSIM_d = (mu_x ** 2 + mu_y ** 2 + self.C1) * (sigma_x + sigma_y +
self.C2)
return torch.clamp((1 - SSIM_n / SSIM_d) / 2, 0, 1)
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_mul_reflection_pad2d_0(in_ptr0, in_ptr1, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 576
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 6
x1 = xindex // 6 % 6
x2 = xindex // 36
x3 = xindex
tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2),
xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2),
xmask, eviction_policy='evict_last')
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x3, tmp2, xmask)
@triton.jit
def triton_poi_fused_add_avg_pool2d_clamp_div_mul_pow_reflection_pad2d_rsub_sub_1(
in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4 % 4
x2 = xindex // 16
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 6 * x1 + 36 * x2), xmask)
tmp1 = tl.load(in_ptr0 + (1 + x0 + 6 * x1 + 36 * x2), xmask)
tmp3 = tl.load(in_ptr0 + (2 + x0 + 6 * x1 + 36 * x2), xmask)
tmp5 = tl.load(in_ptr0 + (6 + x0 + 6 * x1 + 36 * x2), xmask)
tmp7 = tl.load(in_ptr0 + (7 + x0 + 6 * x1 + 36 * x2), xmask)
tmp9 = tl.load(in_ptr0 + (8 + x0 + 6 * x1 + 36 * x2), xmask)
tmp11 = tl.load(in_ptr0 + (12 + x0 + 6 * x1 + 36 * x2), xmask)
tmp13 = tl.load(in_ptr0 + (13 + x0 + 6 * x1 + 36 * x2), xmask)
tmp15 = tl.load(in_ptr0 + (14 + x0 + 6 * x1 + 36 * x2), xmask)
tmp19 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2),
xmask, eviction_policy='evict_last')
tmp20 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-3 + x0) + -4 *
tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2), xmask)
tmp22 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-2 + x0) + -4 *
tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2), xmask)
tmp24 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
x0)) + -4 * tl_math.abs(-3 + x1) + 16 * x2), xmask, eviction_policy
='evict_last')
tmp26 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-3 + x0) + -4 *
tl_math.abs(-3 + x1) + 16 * x2), xmask)
tmp28 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-2 + x0) + -4 *
tl_math.abs(-3 + x1) + 16 * x2), xmask)
tmp30 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
x0)) + -4 * tl_math.abs(-2 + x1) + 16 * x2), xmask, eviction_policy
='evict_last')
tmp32 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-3 + x0) + -4 *
tl_math.abs(-2 + x1) + 16 * x2), xmask)
tmp34 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-2 + x0) + -4 *
tl_math.abs(-2 + x1) + 16 * x2), xmask)
tmp55 = tl.load(in_ptr2 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2),
xmask, eviction_policy='evict_last')
tmp56 = tl.load(in_ptr2 + (15 + -1 * tl_math.abs(-3 + x0) + -4 *
tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2), xmask)
tmp58 = tl.load(in_ptr2 + (15 + -1 * tl_math.abs(-2 + x0) + -4 *
tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2), xmask)
tmp60 = tl.load(in_ptr2 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
x0)) + -4 * tl_math.abs(-3 + x1) + 16 * x2), xmask, eviction_policy
='evict_last')
tmp62 = tl.load(in_ptr2 + (15 + -1 * tl_math.abs(-3 + x0) + -4 *
tl_math.abs(-3 + x1) + 16 * x2), xmask)
tmp64 = tl.load(in_ptr2 + (15 + -1 * tl_math.abs(-2 + x0) + -4 *
tl_math.abs(-3 + x1) + 16 * x2), xmask)
tmp66 = tl.load(in_ptr2 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
x0)) + -4 * tl_math.abs(-2 + x1) + 16 * x2), xmask, eviction_policy
='evict_last')
tmp68 = tl.load(in_ptr2 + (15 + -1 * tl_math.abs(-3 + x0) + -4 *
tl_math.abs(-2 + x1) + 16 * x2), xmask)
tmp70 = tl.load(in_ptr2 + (15 + -1 * tl_math.abs(-2 + x0) + -4 *
tl_math.abs(-2 + x1) + 16 * x2), xmask)
tmp2 = tmp1 + tmp0
tmp4 = tmp3 + tmp2
tmp6 = tmp5 + tmp4
tmp8 = tmp7 + tmp6
tmp10 = tmp9 + tmp8
tmp12 = tmp11 + tmp10
tmp14 = tmp13 + tmp12
tmp16 = tmp15 + tmp14
tmp17 = 0.1111111111111111
tmp18 = tmp16 * tmp17
tmp21 = tmp20 + tmp19
tmp23 = tmp22 + tmp21
tmp25 = tmp24 + tmp23
tmp27 = tmp26 + tmp25
tmp29 = tmp28 + tmp27
tmp31 = tmp30 + tmp29
tmp33 = tmp32 + tmp31
tmp35 = tmp34 + tmp33
tmp36 = tmp35 * tmp17
tmp37 = tmp19 * tmp19
tmp38 = tmp20 * tmp20
tmp39 = tmp38 + tmp37
tmp40 = tmp22 * tmp22
tmp41 = tmp40 + tmp39
tmp42 = tmp24 * tmp24
tmp43 = tmp42 + tmp41
tmp44 = tmp26 * tmp26
tmp45 = tmp44 + tmp43
tmp46 = tmp28 * tmp28
tmp47 = tmp46 + tmp45
tmp48 = tmp30 * tmp30
tmp49 = tmp48 + tmp47
tmp50 = tmp32 * tmp32
tmp51 = tmp50 + tmp49
tmp52 = tmp34 * tmp34
tmp53 = tmp52 + tmp51
tmp54 = tmp53 * tmp17
tmp57 = tmp56 + tmp55
tmp59 = tmp58 + tmp57
tmp61 = tmp60 + tmp59
tmp63 = tmp62 + tmp61
tmp65 = tmp64 + tmp63
tmp67 = tmp66 + tmp65
tmp69 = tmp68 + tmp67
tmp71 = tmp70 + tmp69
tmp72 = tmp71 * tmp17
tmp73 = tmp55 * tmp55
tmp74 = tmp56 * tmp56
tmp75 = tmp74 + tmp73
tmp76 = tmp58 * tmp58
tmp77 = tmp76 + tmp75
tmp78 = tmp60 * tmp60
tmp79 = tmp78 + tmp77
tmp80 = tmp62 * tmp62
tmp81 = tmp80 + tmp79
tmp82 = tmp64 * tmp64
tmp83 = tmp82 + tmp81
tmp84 = tmp66 * tmp66
tmp85 = tmp84 + tmp83
tmp86 = tmp68 * tmp68
tmp87 = tmp86 + tmp85
tmp88 = tmp70 * tmp70
tmp89 = tmp88 + tmp87
tmp90 = tmp89 * tmp17
tmp91 = 2.0
tmp92 = tmp36 * tmp91
tmp93 = tmp92 * tmp72
tmp94 = 0.0001
tmp95 = tmp93 + tmp94
tmp96 = tmp36 * tmp72
tmp97 = tmp18 - tmp96
tmp98 = tmp97 * tmp91
tmp99 = 0.0009
tmp100 = tmp98 + tmp99
tmp101 = tmp95 * tmp100
tmp102 = tmp36 * tmp36
tmp103 = tmp72 * tmp72
tmp104 = tmp102 + tmp103
tmp105 = tmp104 + tmp94
tmp106 = tmp54 - tmp102
tmp107 = tmp90 - tmp103
tmp108 = tmp106 + tmp107
tmp109 = tmp108 + tmp99
tmp110 = tmp105 * tmp109
tmp111 = tmp101 / tmp110
tmp112 = 1.0
tmp113 = tmp112 - tmp111
tmp114 = 0.5
tmp115 = tmp113 * tmp114
tmp116 = 0.0
tmp117 = triton_helpers.maximum(tmp115, tmp116)
tmp118 = triton_helpers.minimum(tmp117, tmp112)
tl.store(in_out_ptr0 + x3, tmp118, 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)
buf2 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_mul_reflection_pad2d_0[grid(576)](arg0_1, arg1_1,
buf2, 576, XBLOCK=128, num_warps=4, num_stages=1)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf6 = buf0
del buf0
buf7 = buf6
del buf6
triton_poi_fused_add_avg_pool2d_clamp_div_mul_pow_reflection_pad2d_rsub_sub_1[
grid(256)](buf7, buf2, arg0_1, arg1_1, 256, XBLOCK=128,
num_warps=4, num_stages=1)
del arg0_1
del arg1_1
del buf2
return buf7,
class SSIMNew(nn.Module):
"""Layer to compute the SSIM loss between a pair of images
"""
def __init__(self):
super(SSIMNew, self).__init__()
self.mu_x_pool = nn.AvgPool2d(3, 1)
self.mu_y_pool = nn.AvgPool2d(3, 1)
self.sig_x_pool = nn.AvgPool2d(3, 1)
self.sig_y_pool = nn.AvgPool2d(3, 1)
self.sig_xy_pool = nn.AvgPool2d(3, 1)
self.refl = nn.ReflectionPad2d(1)
self.C1 = 0.01 ** 2
self.C2 = 0.03 ** 2
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
Sid1057/sid1057.github.io
|
SSIM
| false
| 17,939
|
[
"MIT"
] | 4
|
623d1731e308b42b6f86304dcfd671a061b414bf
|
https://github.com/Sid1057/sid1057.github.io/tree/623d1731e308b42b6f86304dcfd671a061b414bf
|
GraphConvolution
|
from torch.nn import Module
import torch
import torch.autograd
import torch.nn as nn
from torch.nn.modules.module import Module
class GraphConvolution(Module):
"""
Simple GCN layer, similar to https://arxiv.org/abs/1609.02907.
"""
def __init__(self, state_dim, name='', out_state_dim=None):
super(GraphConvolution, self).__init__()
self.state_dim = state_dim
if out_state_dim is None:
self.out_state_dim = state_dim
else:
self.out_state_dim = out_state_dim
self.fc1 = nn.Linear(in_features=self.state_dim, out_features=self.
out_state_dim)
self.fc2 = nn.Linear(in_features=self.state_dim, out_features=self.
out_state_dim)
self.name = name
def forward(self, input, adj):
state_in = self.fc1(input)
forward_input = self.fc2(torch.bmm(adj, input))
return state_in + forward_input
def get_inputs():
return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'state_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.nn import Module
import torch.autograd
import torch.nn as nn
from torch.nn.modules.module import Module
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_add_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel,
XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x2, xmask)
tmp4 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp5 = tmp3 + tmp4
tmp6 = tmp2 + tmp5
tl.store(in_out_ptr0 + x2, tmp6, xmask)
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), (16, 4, 1))
assert_size_stride(primals_4, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_5, (4, 4), (4, 1))
assert_size_stride(primals_6, (4,), (1,))
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((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(primals_4, primals_3, out=buf1)
del primals_4
buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf1, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), out=buf2)
del primals_5
buf3 = reinterpret_tensor(buf0, (4, 4, 4), (16, 4, 1), 0)
del buf0
get_raw_stream(0)
triton_poi_fused_add_0[grid(64)](buf3, primals_2, buf2, primals_6,
64, XBLOCK=64, num_warps=1, num_stages=1)
del buf2
del primals_2
del primals_6
return buf3, reinterpret_tensor(primals_3, (16, 4), (4, 1), 0
), reinterpret_tensor(buf1, (16, 4), (4, 1), 0)
class GraphConvolutionNew(Module):
"""
Simple GCN layer, similar to https://arxiv.org/abs/1609.02907.
"""
def __init__(self, state_dim, name='', out_state_dim=None):
super(GraphConvolutionNew, self).__init__()
self.state_dim = state_dim
if out_state_dim is None:
self.out_state_dim = state_dim
else:
self.out_state_dim = out_state_dim
self.fc1 = nn.Linear(in_features=self.state_dim, out_features=self.
out_state_dim)
self.fc2 = nn.Linear(in_features=self.state_dim, out_features=self.
out_state_dim)
self.name = name
def forward(self, input_0, input_1):
primals_1 = self.fc1.weight
primals_2 = self.fc1.bias
primals_5 = self.fc2.weight
primals_6 = self.fc2.bias
primals_3 = input_0
primals_4 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6])
return output[0]
|
SowmyaAitha/Palmira
|
GraphConvolution
| false
| 17,940
|
[
"MIT"
] | 6
|
c3ae884e35b8b3703a5e4ba52d7b0bdae6da1bad
|
https://github.com/SowmyaAitha/Palmira/tree/c3ae884e35b8b3703a5e4ba52d7b0bdae6da1bad
|
Decoder
|
import torch
import torch.nn as nn
class Decoder(nn.Module):
def __init__(self):
super(Decoder, self).__init__()
self.pre11 = nn.ReflectionPad2d((1, 1, 1, 1))
self.conv11 = nn.Conv2d(in_channels=512, out_channels=256,
kernel_size=3, stride=1)
self.relu11 = nn.ReLU(inplace=True)
self.up1 = nn.Upsample(scale_factor=2, mode='nearest')
self.pre21 = nn.ReflectionPad2d((1, 1, 1, 1))
self.conv21 = nn.Conv2d(in_channels=256, out_channels=256,
kernel_size=3, stride=1)
self.relu21 = nn.ReLU(inplace=True)
self.pre22 = nn.ReflectionPad2d((1, 1, 1, 1))
self.conv22 = nn.Conv2d(in_channels=256, out_channels=256,
kernel_size=3, stride=1)
self.relu22 = nn.ReLU(inplace=True)
self.pre23 = nn.ReflectionPad2d((1, 1, 1, 1))
self.conv23 = nn.Conv2d(in_channels=256, out_channels=256,
kernel_size=3, stride=1)
self.relu23 = nn.ReLU(inplace=True)
self.pre24 = nn.ReflectionPad2d((1, 1, 1, 1))
self.conv24 = nn.Conv2d(in_channels=256, out_channels=128,
kernel_size=3, stride=1)
self.relu24 = nn.ReLU(inplace=True)
self.up2 = nn.Upsample(scale_factor=2, mode='nearest')
self.pre31 = nn.ReflectionPad2d((1, 1, 1, 1))
self.conv31 = nn.Conv2d(in_channels=128, out_channels=128,
kernel_size=3, stride=1)
self.relu31 = nn.ReLU(inplace=True)
self.pre32 = nn.ReflectionPad2d((1, 1, 1, 1))
self.conv32 = nn.Conv2d(in_channels=128, out_channels=64,
kernel_size=3, stride=1)
self.relu32 = nn.ReLU(inplace=True)
self.up3 = nn.Upsample(scale_factor=2, mode='nearest')
self.pre41 = nn.ReflectionPad2d((1, 1, 1, 1))
self.conv41 = nn.Conv2d(in_channels=64, out_channels=64,
kernel_size=3, stride=1)
self.relu41 = nn.ReLU(inplace=True)
self.pre42 = nn.ReflectionPad2d((1, 1, 1, 1))
self.conv42 = nn.Conv2d(in_channels=64, out_channels=3, kernel_size
=3, stride=1)
self.relu42 = nn.ReLU(inplace=True)
def forward(self, x):
x = self.pre11(x)
x = self.relu11(self.conv11(x))
x = self.up1(x)
x = self.pre21(x)
x = self.relu21(self.conv21(x))
x = self.pre22(x)
x = self.relu22(self.conv22(x))
x = self.pre23(x)
x = self.relu23(self.conv23(x))
x = self.pre24(x)
x = self.relu24(self.conv24(x))
x = self.up2(x)
x = self.pre31(x)
x = self.relu31(self.conv31(x))
x = self.pre32(x)
x = self.relu32(self.conv32(x))
x = self.up3(x)
x = self.pre41(x)
x = self.relu41(self.conv41(x))
x = self.pre42(x)
x = self.conv42(x)
return x
def get_inputs():
return [torch.rand([4, 512, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_reflection_pad2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex % 6
x1 = xindex // 6 % 6
x2 = xindex // 36
x3 = xindex
tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2), None,
eviction_policy='evict_last')
tl.store(out_ptr0 + x3, tmp0, None)
@triton.jit
def triton_poi_fused__to_copy_add_arange_mul_1(out_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 8
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = x0
tmp1 = tmp0.to(tl.float32)
tmp2 = 0.5
tmp3 = tmp1 * tmp2
tmp4 = tmp3.to(tl.int32)
tl.store(out_ptr0 + x0, tmp4, xmask)
@triton.jit
def triton_poi_fused__unsafe_index_convolution_reflection_pad2d_relu_2(in_ptr0,
in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x1 = xindex // 10 % 10
x0 = xindex % 10
x4 = xindex // 100
x2 = xindex // 100 % 256
x7 = xindex
tmp0 = tl.load(in_ptr0 + (7 + -1 * tl_math.abs(-7 + tl_math.abs(-1 + x1
))), None, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (7 + -1 * tl_math.abs(-7 + tl_math.abs(-1 + x0
))), None, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr2 + x2, None, eviction_policy='evict_last')
tmp1 = tl.full([XBLOCK], 4, tl.int32)
tmp2 = tmp0 + tmp1
tmp3 = tmp0 < 0
tmp4 = tl.where(tmp3, tmp2, tmp0)
tmp6 = tmp5 + tmp1
tmp7 = tmp5 < 0
tmp8 = tl.where(tmp7, tmp6, tmp5)
tmp9 = tl.load(in_ptr1 + (tmp8 + 4 * tmp4 + 16 * x4), None,
eviction_policy='evict_last')
tmp11 = tmp9 + tmp10
tmp12 = tl.full([1], 0, tl.int32)
tmp13 = triton_helpers.maximum(tmp12, tmp11)
tl.store(out_ptr0 + x7, tmp13, None)
@triton.jit
def triton_poi_fused_convolution_reflection_pad2d_relu_3(in_ptr0, in_ptr1,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex % 10
x1 = xindex // 10 % 10
x4 = xindex // 100
x2 = xindex // 100 % 256
x5 = xindex
tmp0 = tl.load(in_ptr0 + (63 + -1 * tl_math.abs(-7 + tl_math.abs(-1 +
x0)) + -8 * tl_math.abs(-7 + tl_math.abs(-1 + x1)) + 64 * x4), None,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + x2, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(out_ptr0 + x5, tmp4, None)
@triton.jit
def triton_poi_fused__to_copy_add_arange_mul_4(out_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = x0
tmp1 = tmp0.to(tl.float32)
tmp2 = 0.5
tmp3 = tmp1 * tmp2
tmp4 = tmp3.to(tl.int32)
tl.store(out_ptr0 + x0, tmp4, xmask)
@triton.jit
def triton_poi_fused__unsafe_index_convolution_reflection_pad2d_relu_5(in_ptr0,
in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x1 = xindex // 18 % 18
x0 = xindex % 18
x4 = xindex // 324
x2 = xindex // 324 % 128
x7 = xindex
tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-15 + tl_math.abs(-1 +
x1))), None, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-15 + tl_math.abs(-1 +
x0))), None, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr2 + x2, None, eviction_policy='evict_last')
tmp1 = tl.full([XBLOCK], 8, tl.int32)
tmp2 = tmp0 + tmp1
tmp3 = tmp0 < 0
tmp4 = tl.where(tmp3, tmp2, tmp0)
tmp6 = tmp5 + tmp1
tmp7 = tmp5 < 0
tmp8 = tl.where(tmp7, tmp6, tmp5)
tmp9 = tl.load(in_ptr1 + (tmp8 + 8 * tmp4 + 64 * x4), None,
eviction_policy='evict_last')
tmp11 = tmp9 + tmp10
tmp12 = tl.full([1], 0, tl.int32)
tmp13 = triton_helpers.maximum(tmp12, tmp11)
tl.store(out_ptr0 + x7, tmp13, None)
@triton.jit
def triton_poi_fused_convolution_reflection_pad2d_relu_6(in_ptr0, in_ptr1,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex % 18
x1 = xindex // 18 % 18
x4 = xindex // 324
x2 = xindex // 324 % 128
x5 = xindex
tmp0 = tl.load(in_ptr0 + (255 + -1 * tl_math.abs(-15 + tl_math.abs(-1 +
x0)) + -16 * tl_math.abs(-15 + tl_math.abs(-1 + x1)) + 256 * x4),
None, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + x2, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(out_ptr0 + x5, tmp4, None)
@triton.jit
def triton_poi_fused__to_copy_add_arange_mul_7(out_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 32
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = x0
tmp1 = tmp0.to(tl.float32)
tmp2 = 0.5
tmp3 = tmp1 * tmp2
tmp4 = tmp3.to(tl.int32)
tl.store(out_ptr0 + x0, tmp4, xmask)
@triton.jit
def triton_poi_fused__unsafe_index_convolution_reflection_pad2d_relu_8(in_ptr0,
in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 295936
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 34 % 34
x0 = xindex % 34
x4 = xindex // 1156
x2 = xindex // 1156 % 64
x7 = xindex
tmp0 = tl.load(in_ptr0 + (31 + -1 * tl_math.abs(-31 + tl_math.abs(-1 +
x1))), xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (31 + -1 * tl_math.abs(-31 + tl_math.abs(-1 +
x0))), xmask, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last')
tmp1 = tl.full([XBLOCK], 16, tl.int32)
tmp2 = tmp0 + tmp1
tmp3 = tmp0 < 0
tmp4 = tl.where(tmp3, tmp2, tmp0)
tmp6 = tmp5 + tmp1
tmp7 = tmp5 < 0
tmp8 = tl.where(tmp7, tmp6, tmp5)
tmp9 = tl.load(in_ptr1 + (tmp8 + 16 * tmp4 + 256 * x4), xmask,
eviction_policy='evict_last')
tmp11 = tmp9 + tmp10
tmp12 = tl.full([1], 0, tl.int32)
tmp13 = triton_helpers.maximum(tmp12, tmp11)
tl.store(out_ptr0 + x7, tmp13, xmask)
@triton.jit
def triton_poi_fused_convolution_reflection_pad2d_relu_9(in_ptr0, in_ptr1,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 295936
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 34
x1 = xindex // 34 % 34
x4 = xindex // 1156
x2 = xindex // 1156 % 64
x5 = xindex
tmp0 = tl.load(in_ptr0 + (1023 + -1 * tl_math.abs(-31 + tl_math.abs(-1 +
x0)) + -32 * tl_math.abs(-31 + tl_math.abs(-1 + x1)) + 1024 * x4),
xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(out_ptr0 + x5, tmp4, xmask)
@triton.jit
def triton_poi_fused_convolution_10(in_out_ptr0, in_ptr0, xnumel, XBLOCK:
tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 1024 % 3
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, None)
@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_11(in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 1024 % 64
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(out_ptr0 + x3, tmp6, None)
@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_12(in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 256 % 64
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(out_ptr0 + x3, tmp6, None)
@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_13(in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 256 % 128
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(out_ptr0 + x3, tmp6, None)
@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_14(in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 64 % 128
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(out_ptr0 + x3, tmp6, None)
@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_15(in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 64 % 256
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(out_ptr0 + x3, tmp6, None)
@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_16(in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 16 % 256
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(out_ptr0 + x3, tmp6, None)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
primals_13, primals_14, primals_15, primals_16, primals_17,
primals_18, primals_19) = args
args.clear()
assert_size_stride(primals_1, (4, 512, 4, 4), (8192, 16, 4, 1))
assert_size_stride(primals_2, (256, 512, 3, 3), (4608, 9, 3, 1))
assert_size_stride(primals_3, (256,), (1,))
assert_size_stride(primals_4, (256, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_5, (256,), (1,))
assert_size_stride(primals_6, (256, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_7, (256,), (1,))
assert_size_stride(primals_8, (256, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_9, (256,), (1,))
assert_size_stride(primals_10, (128, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_11, (128,), (1,))
assert_size_stride(primals_12, (128, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_13, (128,), (1,))
assert_size_stride(primals_14, (64, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_15, (64,), (1,))
assert_size_stride(primals_16, (64, 64, 3, 3), (576, 9, 3, 1))
assert_size_stride(primals_17, (64,), (1,))
assert_size_stride(primals_18, (3, 64, 3, 3), (576, 9, 3, 1))
assert_size_stride(primals_19, (3,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 512, 6, 6), (18432, 36, 6, 1), torch.
float32)
get_raw_stream(0)
triton_poi_fused_reflection_pad2d_0[grid(73728)](primals_1, buf0,
73728, XBLOCK=512, num_warps=8, 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, 256, 4, 4), (4096, 16, 4, 1))
buf2 = empty_strided_cuda((8,), (1,), torch.int64)
triton_poi_fused__to_copy_add_arange_mul_1[grid(8)](buf2, 8, XBLOCK
=8, num_warps=1, num_stages=1)
buf3 = empty_strided_cuda((4, 256, 10, 10), (25600, 100, 10, 1),
torch.float32)
triton_poi_fused__unsafe_index_convolution_reflection_pad2d_relu_2[grid
(102400)](buf2, buf1, primals_3, buf3, 102400, XBLOCK=512,
num_warps=8, num_stages=1)
buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 256, 8, 8), (16384, 64, 8, 1))
buf5 = empty_strided_cuda((4, 256, 10, 10), (25600, 100, 10, 1),
torch.float32)
triton_poi_fused_convolution_reflection_pad2d_relu_3[grid(102400)](buf4
, primals_5, buf5, 102400, XBLOCK=512, num_warps=8, num_stages=1)
buf6 = extern_kernels.convolution(buf5, primals_6, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf6, (4, 256, 8, 8), (16384, 64, 8, 1))
buf7 = empty_strided_cuda((4, 256, 10, 10), (25600, 100, 10, 1),
torch.float32)
triton_poi_fused_convolution_reflection_pad2d_relu_3[grid(102400)](buf6
, primals_7, buf7, 102400, XBLOCK=512, num_warps=8, num_stages=1)
buf8 = extern_kernels.convolution(buf7, primals_8, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf8, (4, 256, 8, 8), (16384, 64, 8, 1))
buf9 = empty_strided_cuda((4, 256, 10, 10), (25600, 100, 10, 1),
torch.float32)
triton_poi_fused_convolution_reflection_pad2d_relu_3[grid(102400)](buf8
, primals_9, buf9, 102400, XBLOCK=512, num_warps=8, num_stages=1)
buf10 = extern_kernels.convolution(buf9, primals_10, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf10, (4, 128, 8, 8), (8192, 64, 8, 1))
buf11 = empty_strided_cuda((16,), (1,), torch.int64)
triton_poi_fused__to_copy_add_arange_mul_4[grid(16)](buf11, 16,
XBLOCK=16, num_warps=1, num_stages=1)
buf12 = empty_strided_cuda((4, 128, 18, 18), (41472, 324, 18, 1),
torch.float32)
triton_poi_fused__unsafe_index_convolution_reflection_pad2d_relu_5[grid
(165888)](buf11, buf10, primals_11, buf12, 165888, XBLOCK=512,
num_warps=8, num_stages=1)
buf13 = extern_kernels.convolution(buf12, primals_12, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf13, (4, 128, 16, 16), (32768, 256, 16, 1))
buf14 = empty_strided_cuda((4, 128, 18, 18), (41472, 324, 18, 1),
torch.float32)
triton_poi_fused_convolution_reflection_pad2d_relu_6[grid(165888)](
buf13, primals_13, buf14, 165888, XBLOCK=1024, num_warps=4,
num_stages=1)
buf15 = extern_kernels.convolution(buf14, primals_14, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf15, (4, 64, 16, 16), (16384, 256, 16, 1))
buf16 = empty_strided_cuda((32,), (1,), torch.int64)
triton_poi_fused__to_copy_add_arange_mul_7[grid(32)](buf16, 32,
XBLOCK=32, num_warps=1, num_stages=1)
buf17 = empty_strided_cuda((4, 64, 34, 34), (73984, 1156, 34, 1),
torch.float32)
triton_poi_fused__unsafe_index_convolution_reflection_pad2d_relu_8[grid
(295936)](buf16, buf15, primals_15, buf17, 295936, XBLOCK=512,
num_warps=8, num_stages=1)
buf18 = extern_kernels.convolution(buf17, primals_16, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf18, (4, 64, 32, 32), (65536, 1024, 32, 1))
buf19 = empty_strided_cuda((4, 64, 34, 34), (73984, 1156, 34, 1),
torch.float32)
triton_poi_fused_convolution_reflection_pad2d_relu_9[grid(295936)](
buf18, primals_17, buf19, 295936, XBLOCK=1024, num_warps=4,
num_stages=1)
buf20 = extern_kernels.convolution(buf19, primals_18, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf20, (4, 3, 32, 32), (3072, 1024, 32, 1))
buf21 = buf20
del buf20
triton_poi_fused_convolution_10[grid(12288)](buf21, primals_19,
12288, XBLOCK=256, num_warps=4, num_stages=1)
del primals_19
buf22 = empty_strided_cuda((4, 64, 32, 32), (65536, 1024, 32, 1),
torch.bool)
triton_poi_fused_convolution_relu_threshold_backward_11[grid(262144)](
buf18, primals_17, buf22, 262144, XBLOCK=1024, num_warps=4,
num_stages=1)
del buf18
del primals_17
buf23 = empty_strided_cuda((4, 64, 16, 16), (16384, 256, 16, 1),
torch.bool)
triton_poi_fused_convolution_relu_threshold_backward_12[grid(65536)](
buf15, primals_15, buf23, 65536, XBLOCK=512, num_warps=4,
num_stages=1)
del buf15
del primals_15
buf24 = empty_strided_cuda((4, 128, 16, 16), (32768, 256, 16, 1),
torch.bool)
triton_poi_fused_convolution_relu_threshold_backward_13[grid(131072)](
buf13, primals_13, buf24, 131072, XBLOCK=1024, num_warps=4,
num_stages=1)
del buf13
del primals_13
buf25 = empty_strided_cuda((4, 128, 8, 8), (8192, 64, 8, 1), torch.bool
)
triton_poi_fused_convolution_relu_threshold_backward_14[grid(32768)](
buf10, primals_11, buf25, 32768, XBLOCK=128, num_warps=4,
num_stages=1)
del buf10
del primals_11
buf26 = empty_strided_cuda((4, 256, 8, 8), (16384, 64, 8, 1), torch
.bool)
triton_poi_fused_convolution_relu_threshold_backward_15[grid(65536)](
buf8, primals_9, buf26, 65536, XBLOCK=512, num_warps=4,
num_stages=1)
del buf8
del primals_9
buf27 = empty_strided_cuda((4, 256, 8, 8), (16384, 64, 8, 1), torch
.bool)
triton_poi_fused_convolution_relu_threshold_backward_15[grid(65536)](
buf6, primals_7, buf27, 65536, XBLOCK=512, num_warps=4,
num_stages=1)
del buf6
del primals_7
buf28 = empty_strided_cuda((4, 256, 8, 8), (16384, 64, 8, 1), torch
.bool)
triton_poi_fused_convolution_relu_threshold_backward_15[grid(65536)](
buf4, primals_5, buf28, 65536, XBLOCK=512, num_warps=4,
num_stages=1)
del buf4
del primals_5
buf29 = empty_strided_cuda((4, 256, 4, 4), (4096, 16, 4, 1), torch.bool
)
triton_poi_fused_convolution_relu_threshold_backward_16[grid(16384)](
buf1, primals_3, buf29, 16384, XBLOCK=256, num_warps=4,
num_stages=1)
del buf1
del primals_3
return (buf21, primals_2, primals_4, primals_6, primals_8, primals_10,
primals_12, primals_14, primals_16, primals_18, buf0, buf2, buf3,
buf5, buf7, buf9, buf11, buf12, buf14, buf16, buf17, buf19, buf22,
buf23, buf24, buf25, buf26, buf27, buf28, buf29)
class DecoderNew(nn.Module):
def __init__(self):
super(DecoderNew, self).__init__()
self.pre11 = nn.ReflectionPad2d((1, 1, 1, 1))
self.conv11 = nn.Conv2d(in_channels=512, out_channels=256,
kernel_size=3, stride=1)
self.relu11 = nn.ReLU(inplace=True)
self.up1 = nn.Upsample(scale_factor=2, mode='nearest')
self.pre21 = nn.ReflectionPad2d((1, 1, 1, 1))
self.conv21 = nn.Conv2d(in_channels=256, out_channels=256,
kernel_size=3, stride=1)
self.relu21 = nn.ReLU(inplace=True)
self.pre22 = nn.ReflectionPad2d((1, 1, 1, 1))
self.conv22 = nn.Conv2d(in_channels=256, out_channels=256,
kernel_size=3, stride=1)
self.relu22 = nn.ReLU(inplace=True)
self.pre23 = nn.ReflectionPad2d((1, 1, 1, 1))
self.conv23 = nn.Conv2d(in_channels=256, out_channels=256,
kernel_size=3, stride=1)
self.relu23 = nn.ReLU(inplace=True)
self.pre24 = nn.ReflectionPad2d((1, 1, 1, 1))
self.conv24 = nn.Conv2d(in_channels=256, out_channels=128,
kernel_size=3, stride=1)
self.relu24 = nn.ReLU(inplace=True)
self.up2 = nn.Upsample(scale_factor=2, mode='nearest')
self.pre31 = nn.ReflectionPad2d((1, 1, 1, 1))
self.conv31 = nn.Conv2d(in_channels=128, out_channels=128,
kernel_size=3, stride=1)
self.relu31 = nn.ReLU(inplace=True)
self.pre32 = nn.ReflectionPad2d((1, 1, 1, 1))
self.conv32 = nn.Conv2d(in_channels=128, out_channels=64,
kernel_size=3, stride=1)
self.relu32 = nn.ReLU(inplace=True)
self.up3 = nn.Upsample(scale_factor=2, mode='nearest')
self.pre41 = nn.ReflectionPad2d((1, 1, 1, 1))
self.conv41 = nn.Conv2d(in_channels=64, out_channels=64,
kernel_size=3, stride=1)
self.relu41 = nn.ReLU(inplace=True)
self.pre42 = nn.ReflectionPad2d((1, 1, 1, 1))
self.conv42 = nn.Conv2d(in_channels=64, out_channels=3, kernel_size
=3, stride=1)
self.relu42 = nn.ReLU(inplace=True)
def forward(self, input_0):
primals_2 = self.conv11.weight
primals_3 = self.conv11.bias
primals_4 = self.conv21.weight
primals_5 = self.conv21.bias
primals_6 = self.conv22.weight
primals_7 = self.conv22.bias
primals_8 = self.conv23.weight
primals_9 = self.conv23.bias
primals_10 = self.conv24.weight
primals_11 = self.conv24.bias
primals_12 = self.conv31.weight
primals_13 = self.conv31.bias
primals_14 = self.conv32.weight
primals_15 = self.conv32.bias
primals_16 = self.conv41.weight
primals_17 = self.conv41.bias
primals_18 = self.conv42.weight
primals_19 = self.conv42.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11, primals_12, primals_13, primals_14,
primals_15, primals_16, primals_17, primals_18, primals_19])
return output[0]
|
ShiZhuming/StyleTransfer
|
Decoder
| false
| 17,941
|
[
"MIT"
] | 10
|
cba2a3ceb733a2d129d52d4a3cac07c7651bd928
|
https://github.com/ShiZhuming/StyleTransfer/tree/cba2a3ceb733a2d129d52d4a3cac07c7651bd928
|
SH2Signal
|
import torch
import numpy as np
import torch.nn as nn
from scipy import special as sci
def cart2sph(x, y, z):
"""
cart2sph(x, y, z) -> theta, phi, r
Computes the corresponding spherical coordinate of the given input parameters :attr:`x`, :attr:`y` and :attr:`x`.
Args:
x (Number): x position
y (Number): y position
z (Number): z position
Example::
>>> cart2sph(1, 1, 1)
(0.78539816339744828, 0.95531661812450919, 1.7320508075688772)
"""
azimuthal_angle = np.arctan2(y, x)
radial_distance = np.sqrt(x ** 2 + y ** 2 + z ** 2)
polar_angle = np.arccos(z / radial_distance)
return azimuthal_angle, polar_angle, radial_distance
class SH2Signal(nn.Module):
"""
SH2Signal(dwi_sh) -> dwi
Computes the corresponding dwi signal for each gradient
Args:
x_in (5D tensor): input spherical harmonic tensor
x_in.size(): (Batchsize x Number of shells*Number of coefficients x DimX x DimY x DimZ)
y (5D tensor): corresponding dwi tensor
y.size(): (Batchsize x Number of shells * Number of gradients x DimX x DimY x DimZ)
"""
def __init__(self, sh_order, gradients):
super(SH2Signal, self).__init__()
self.sh_order = sh_order
self.num_gradients = gradients.shape[0]
self.num_coefficients = int((self.sh_order + 1) * (self.sh_order /
2 + 1))
SH2SignalMat = np.zeros((self.num_coefficients, self.num_gradients))
for id_gradient in range(self.num_gradients):
id_coefficient = 0
for id_order in range(0, self.sh_order + 1, 2):
for id_degree in range(-id_order, id_order + 1):
gradients_phi, gradients_theta, _gradients_z = cart2sph(
gradients[id_gradient, 0], gradients[id_gradient, 1
], gradients[id_gradient, 2])
y = sci.sph_harm(np.abs(id_degree), id_order,
gradients_phi, gradients_theta)
if id_degree < 0:
SH2SignalMat[id_coefficient, id_gradient] = np.real(y
) * np.sqrt(2)
elif id_degree == 0:
SH2SignalMat[id_coefficient, id_gradient] = np.real(y)
elif id_degree > 0:
SH2SignalMat[id_coefficient, id_gradient] = np.imag(y
) * np.sqrt(2)
id_coefficient += 1
self.SH2SignalMat = torch.nn.Parameter(torch.from_numpy(
SH2SignalMat).float(), requires_grad=False)
def forward(self, x_in):
x_dim = x_in.size()
x = x_in.reshape((x_dim[0], np.ceil(x_in.size(1) / self.
num_coefficients).astype(int), self.num_coefficients, x_dim[-3],
x_dim[-2], x_dim[-1]))
x = x.permute(0, 1, 3, 4, 5, 2)
y = x.matmul(self.SH2SignalMat)
y = y.permute(0, 1, 5, 2, 3, 4).contiguous().reshape((x_dim[0], -1,
x_dim[-3], x_dim[-2], x_dim[-1]))
return y
def get_inputs():
return [torch.rand([4, 1, 15, 4, 4, 4])]
def get_init_inputs():
return [[], {'sh_order': 4, 'gradients': torch.rand([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
import numpy as np
import torch.nn as nn
from scipy import special as sci
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 = 256
xnumel = 15
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 % 64
y1 = yindex // 64
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 64 * x2 + 960 * y1), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 15 * y3), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_clone_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 64
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 + 256 * y1), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 64 * y3), tmp0, xmask & ymask)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 1, 15, 4, 4, 4), (960, 960, 64, 16, 4, 1))
assert_size_stride(arg1_1, (15, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 1, 4, 4, 4, 15), (960, 960, 240, 60,
15, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(256, 15)](arg0_1, buf0, 256, 15,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del arg0_1
buf1 = empty_strided_cuda((64, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf0, (64, 4, 15), (60, 15, 1
), 0), reinterpret_tensor(arg1_1, (64, 15, 4), (0, 4, 1), 0),
out=buf1)
del arg1_1
del buf0
buf2 = empty_strided_cuda((4, 1, 4, 4, 4, 4), (256, 256, 64, 16, 4,
1), torch.float32)
triton_poi_fused_clone_1[grid(16, 64)](buf1, buf2, 16, 64, XBLOCK=
64, YBLOCK=16, num_warps=4, num_stages=1)
del buf1
return reinterpret_tensor(buf2, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1), 0),
def cart2sph(x, y, z):
"""
cart2sph(x, y, z) -> theta, phi, r
Computes the corresponding spherical coordinate of the given input parameters :attr:`x`, :attr:`y` and :attr:`x`.
Args:
x (Number): x position
y (Number): y position
z (Number): z position
Example::
>>> cart2sph(1, 1, 1)
(0.78539816339744828, 0.95531661812450919, 1.7320508075688772)
"""
azimuthal_angle = np.arctan2(y, x)
radial_distance = np.sqrt(x ** 2 + y ** 2 + z ** 2)
polar_angle = np.arccos(z / radial_distance)
return azimuthal_angle, polar_angle, radial_distance
class SH2SignalNew(nn.Module):
"""
SH2Signal(dwi_sh) -> dwi
Computes the corresponding dwi signal for each gradient
Args:
x_in (5D tensor): input spherical harmonic tensor
x_in.size(): (Batchsize x Number of shells*Number of coefficients x DimX x DimY x DimZ)
y (5D tensor): corresponding dwi tensor
y.size(): (Batchsize x Number of shells * Number of gradients x DimX x DimY x DimZ)
"""
def __init__(self, sh_order, gradients):
super(SH2SignalNew, self).__init__()
self.sh_order = sh_order
self.num_gradients = gradients.shape[0]
self.num_coefficients = int((self.sh_order + 1) * (self.sh_order /
2 + 1))
SH2SignalMat = np.zeros((self.num_coefficients, self.num_gradients))
for id_gradient in range(self.num_gradients):
id_coefficient = 0
for id_order in range(0, self.sh_order + 1, 2):
for id_degree in range(-id_order, id_order + 1):
gradients_phi, gradients_theta, _gradients_z = cart2sph(
gradients[id_gradient, 0], gradients[id_gradient, 1
], gradients[id_gradient, 2])
y = sci.sph_harm(np.abs(id_degree), id_order,
gradients_phi, gradients_theta)
if id_degree < 0:
SH2SignalMat[id_coefficient, id_gradient] = np.real(y
) * np.sqrt(2)
elif id_degree == 0:
SH2SignalMat[id_coefficient, id_gradient] = np.real(y)
elif id_degree > 0:
SH2SignalMat[id_coefficient, id_gradient] = np.imag(y
) * np.sqrt(2)
id_coefficient += 1
self.SH2SignalMat = torch.nn.Parameter(torch.from_numpy(
SH2SignalMat).float(), requires_grad=False)
def forward(self, input_0):
arg1_1 = self.SH2SignalMat
arg0_1 = input_0
output = call([arg0_1, arg1_1])
return output[0]
|
SimonKoppers/DELIMIT
|
SH2Signal
| false
| 17,942
|
[
"MIT"
] | 7
|
d778a567bbec1beef2395ead60aa1e30086bb07c
|
https://github.com/SimonKoppers/DELIMIT/tree/d778a567bbec1beef2395ead60aa1e30086bb07c
|
GraphResConvolution
|
from torch.nn import Module
import torch
import torch.autograd
import torch.nn as nn
from torch.nn.modules.module import Module
class GraphConvolution(Module):
"""
Simple GCN layer, similar to https://arxiv.org/abs/1609.02907.
"""
def __init__(self, state_dim, name='', out_state_dim=None):
super(GraphConvolution, self).__init__()
self.state_dim = state_dim
if out_state_dim is None:
self.out_state_dim = state_dim
else:
self.out_state_dim = out_state_dim
self.fc1 = nn.Linear(in_features=self.state_dim, out_features=self.
out_state_dim)
self.fc2 = nn.Linear(in_features=self.state_dim, out_features=self.
out_state_dim)
self.name = name
def forward(self, input, adj):
state_in = self.fc1(input)
forward_input = self.fc2(torch.bmm(adj, input))
return state_in + forward_input
class GraphResConvolution(Module):
"""
Simple GCN layer, similar to https://arxiv.org/abs/1609.02907.
"""
def __init__(self, state_dim, name=''):
super(GraphResConvolution, self).__init__()
self.state_dim = state_dim
self.gcn_1 = GraphConvolution(state_dim, f'{name}_1')
self.gcn_2 = GraphConvolution(state_dim, f'{name}_2')
self.relu1 = nn.ReLU()
self.relu2 = nn.ReLU()
self.name = name
def forward(self, input, adj):
output_1 = self.gcn_1(input, adj)
output_1_relu = self.relu1(output_1)
output_2 = self.gcn_2(output_1_relu, adj)
output_2_res = output_2 + input
output = self.relu2(output_2_res)
return output
def get_inputs():
return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'state_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.nn import Module
import torch.autograd
import torch.nn as nn
from torch.nn.modules.module import Module
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_add_relu_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2,
xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x2, xmask)
tmp4 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp5 = tmp3 + tmp4
tmp6 = tmp2 + tmp5
tmp7 = tl.full([1], 0, tl.int32)
tmp8 = triton_helpers.maximum(tmp7, tmp6)
tl.store(in_out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused_add_relu_threshold_backward_1(in_out_ptr0, in_ptr0,
in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x2, xmask)
tmp4 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr3 + x2, xmask)
tmp2 = tmp0 + tmp1
tmp5 = tmp3 + tmp4
tmp6 = tmp2 + tmp5
tmp8 = tmp6 + 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)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10) = args
args.clear()
assert_size_stride(primals_1, (4, 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), (16, 4, 1))
assert_size_stride(primals_5, (4, 4), (4, 1))
assert_size_stride(primals_6, (4,), (1,))
assert_size_stride(primals_7, (4, 4), (4, 1))
assert_size_stride(primals_8, (4,), (1,))
assert_size_stride(primals_9, (4, 4), (4, 1))
assert_size_stride(primals_10, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((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((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(primals_4, primals_3, out=buf1)
buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf1, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), out=buf2)
del primals_5
buf3 = reinterpret_tensor(buf0, (4, 4, 4), (16, 4, 1), 0)
del buf0
get_raw_stream(0)
triton_poi_fused_add_relu_0[grid(64)](buf3, primals_2, buf2,
primals_6, 64, XBLOCK=64, num_warps=1, num_stages=1)
del primals_2
del primals_6
buf4 = buf2
del buf2
extern_kernels.mm(reinterpret_tensor(buf3, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), out=buf4)
buf5 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(primals_4, buf3, out=buf5)
buf6 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf5, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_9, (4, 4), (1, 4), 0), out=buf6)
buf7 = reinterpret_tensor(buf4, (4, 4, 4), (16, 4, 1), 0)
del buf4
buf8 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
triton_poi_fused_add_relu_threshold_backward_1[grid(64)](buf7,
primals_8, buf6, primals_10, primals_3, buf8, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del buf6
del primals_10
del primals_8
return buf7, reinterpret_tensor(primals_3, (16, 4), (4, 1), 0
), reinterpret_tensor(buf1, (16, 4), (4, 1), 0
), buf3, reinterpret_tensor(buf5, (16, 4), (4, 1), 0
), buf8, primals_9, reinterpret_tensor(primals_4, (4, 4, 4), (16, 1,
4), 0), primals_7
class GraphConvolution(Module):
"""
Simple GCN layer, similar to https://arxiv.org/abs/1609.02907.
"""
def __init__(self, state_dim, name='', out_state_dim=None):
super(GraphConvolution, self).__init__()
self.state_dim = state_dim
if out_state_dim is None:
self.out_state_dim = state_dim
else:
self.out_state_dim = out_state_dim
self.fc1 = nn.Linear(in_features=self.state_dim, out_features=self.
out_state_dim)
self.fc2 = nn.Linear(in_features=self.state_dim, out_features=self.
out_state_dim)
self.name = name
def forward(self, input, adj):
state_in = self.fc1(input)
forward_input = self.fc2(torch.bmm(adj, input))
return state_in + forward_input
class GraphResConvolutionNew(Module):
"""
Simple GCN layer, similar to https://arxiv.org/abs/1609.02907.
"""
def __init__(self, state_dim, name=''):
super(GraphResConvolutionNew, self).__init__()
self.state_dim = state_dim
self.gcn_1 = GraphConvolution(state_dim, f'{name}_1')
self.gcn_2 = GraphConvolution(state_dim, f'{name}_2')
self.relu1 = nn.ReLU()
self.relu2 = nn.ReLU()
self.name = name
def forward(self, input_0, input_1):
primals_1 = self.gcn_1.fc1.weight
primals_2 = self.gcn_1.fc1.bias
primals_5 = self.gcn_1.fc2.weight
primals_6 = self.gcn_1.fc2.bias
primals_7 = self.gcn_2.fc1.weight
primals_8 = self.gcn_2.fc1.bias
primals_9 = self.gcn_2.fc2.weight
primals_10 = self.gcn_2.fc2.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, primals_9, primals_10])
return output[0]
|
SowmyaAitha/Palmira
|
GraphResConvolution
| false
| 17,943
|
[
"MIT"
] | 6
|
c3ae884e35b8b3703a5e4ba52d7b0bdae6da1bad
|
https://github.com/SowmyaAitha/Palmira/tree/c3ae884e35b8b3703a5e4ba52d7b0bdae6da1bad
|
SharedDropoutMLP
|
import torch
import torch.nn as nn
class SharedDropout(nn.Module):
"""
SharedDropout differs from the vanilla dropout strategy in that
the dropout mask is shared across one dimension.
Args:
p (float):
The probability of an element to be zeroed. Default: 0.5.
batch_first (bool):
If ``True``, the input and output tensors are provided as ``[batch_size, seq_len, *]``.
Default: ``True``.
Examples:
>>> x = torch.ones(1, 3, 5)
>>> nn.Dropout()(x)
tensor([[[0., 2., 2., 0., 0.],
[2., 2., 0., 2., 2.],
[2., 2., 2., 2., 0.]]])
>>> SharedDropout()(x)
tensor([[[2., 0., 2., 0., 2.],
[2., 0., 2., 0., 2.],
[2., 0., 2., 0., 2.]]])
Reference:
- https://github.com/yzhangcs/parser/blob/main/supar/modules/dropout.py
"""
def __init__(self, p=0.5, batch_first=True):
super().__init__()
self.p = p
self.batch_first = batch_first
def __repr__(self):
s = f'p={self.p}'
if self.batch_first:
s += f', batch_first={self.batch_first}'
return f'{self.__class__.__name__}({s})'
def forward(self, x):
"""
Args:
x (~torch.Tensor):
A tensor of any shape.
Returns:
The returned tensor is of the same shape as `x`.
"""
if self.training:
if self.batch_first:
mask = self.get_mask(x[:, 0], self.p).unsqueeze(1)
else:
mask = self.get_mask(x[0], self.p)
x = x * mask
return x
@staticmethod
def get_mask(x, p):
return x.new_empty(x.shape).bernoulli_(1 - p) / (1 - p)
class SharedDropoutMLP(nn.Module):
"""
Applies a linear transformation together with a non-linear activation to the incoming tensor:
:math:`y = \\mathrm{Activation}(x A^T + b)`
Args:
n_in (~torch.Tensor):
The size of each input feature.
n_out (~torch.Tensor):
The size of each output feature.
dropout (float):
If non-zero, introduce a :class:`SharedDropout` layer on the output with this dropout ratio. Default: 0.
activation (bool):
Whether to use activations. Default: True.
"""
def __init__(self, n_in, n_out, dropout=0, activation=True):
super().__init__()
self.n_in = n_in
self.n_out = n_out
self.linear = nn.Linear(n_in, n_out)
self.activation = nn.LeakyReLU(negative_slope=0.1
) if activation else nn.Identity()
self.dropout = SharedDropout(p=dropout)
self.reset_parameters()
def __repr__(self):
s = f'n_in={self.n_in}, n_out={self.n_out}'
if self.dropout.p > 0:
s += f', dropout={self.dropout.p}'
return f'{self.__class__.__name__}({s})'
def reset_parameters(self):
nn.init.orthogonal_(self.linear.weight)
nn.init.zeros_(self.linear.bias)
def forward(self, x):
"""
Args:
x (~torch.Tensor):
The size of each input feature is `n_in`.
Returns:
A tensor with the size of each output feature `n_out`.
"""
x = self.linear(x)
x = self.activation(x)
x = self.dropout(x)
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'n_in': 4, 'n_out': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
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.1
tmp6 = tmp2 * tmp5
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(out_ptr0 + x2, tmp4, xmask)
tl.store(out_ptr1 + x2, tmp7, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0)
del primals_1
buf1 = 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 buf0
del primals_2
return buf2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf1
class SharedDropout(nn.Module):
"""
SharedDropout differs from the vanilla dropout strategy in that
the dropout mask is shared across one dimension.
Args:
p (float):
The probability of an element to be zeroed. Default: 0.5.
batch_first (bool):
If ``True``, the input and output tensors are provided as ``[batch_size, seq_len, *]``.
Default: ``True``.
Examples:
>>> x = torch.ones(1, 3, 5)
>>> nn.Dropout()(x)
tensor([[[0., 2., 2., 0., 0.],
[2., 2., 0., 2., 2.],
[2., 2., 2., 2., 0.]]])
>>> SharedDropout()(x)
tensor([[[2., 0., 2., 0., 2.],
[2., 0., 2., 0., 2.],
[2., 0., 2., 0., 2.]]])
Reference:
- https://github.com/yzhangcs/parser/blob/main/supar/modules/dropout.py
"""
def __init__(self, p=0.5, batch_first=True):
super().__init__()
self.p = p
self.batch_first = batch_first
def __repr__(self):
s = f'p={self.p}'
if self.batch_first:
s += f', batch_first={self.batch_first}'
return f'{self.__class__.__name__}({s})'
def forward(self, x):
"""
Args:
x (~torch.Tensor):
A tensor of any shape.
Returns:
The returned tensor is of the same shape as `x`.
"""
if self.training:
if self.batch_first:
mask = self.get_mask(x[:, 0], self.p).unsqueeze(1)
else:
mask = self.get_mask(x[0], self.p)
x = x * mask
return x
@staticmethod
def get_mask(x, p):
return x.new_empty(x.shape).bernoulli_(1 - p) / (1 - p)
class SharedDropoutMLPNew(nn.Module):
"""
Applies a linear transformation together with a non-linear activation to the incoming tensor:
:math:`y = \\mathrm{Activation}(x A^T + b)`
Args:
n_in (~torch.Tensor):
The size of each input feature.
n_out (~torch.Tensor):
The size of each output feature.
dropout (float):
If non-zero, introduce a :class:`SharedDropout` layer on the output with this dropout ratio. Default: 0.
activation (bool):
Whether to use activations. Default: True.
"""
def __init__(self, n_in, n_out, dropout=0, activation=True):
super().__init__()
self.n_in = n_in
self.n_out = n_out
self.linear = nn.Linear(n_in, n_out)
self.activation = nn.LeakyReLU(negative_slope=0.1
) if activation else nn.Identity()
self.dropout = SharedDropout(p=dropout)
self.reset_parameters()
def __repr__(self):
s = f'n_in={self.n_in}, n_out={self.n_out}'
if self.dropout.p > 0:
s += f', dropout={self.dropout.p}'
return f'{self.__class__.__name__}({s})'
def reset_parameters(self):
nn.init.orthogonal_(self.linear.weight)
nn.init.zeros_(self.linear.bias)
def forward(self, input_0):
primals_1 = self.linear.weight
primals_2 = self.linear.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
Spico197/REx
|
SharedDropoutMLP
| false
| 17,944
|
[
"MIT"
] | 4
|
bb3cdb845765a63e9bd18070068af52a1b2db3f3
|
https://github.com/Spico197/REx/tree/bb3cdb845765a63e9bd18070068af52a1b2db3f3
|
SubjObjSpan
|
import torch
import numpy as np
from typing import Iterable
from typing import Optional
import torch.nn as nn
def find_closest_span_pairs(head: 'Iterable', tail: 'Iterable', backtrace:
'Optional[bool]'=True):
"""
Find all span pairs.
Args:
head: list of start position predictions, either 1 or 0
tail: list of end position predictions, either 1 or 0
backtrace: if there are more tail predictions than head predictions,
then backtrace to find a closest head position to get a span pair
Examples:
>>> head = torch.tensor([1, 0, 0, 1, 0, 0, 1], dtype=torch.long)
>>> tail = torch.tensor([0, 1, 0, 1, 0, 1, 1], dtype=torch.long)
>>> find_closest_span_pairs(head, tail, backtrace=False)
[(0, 1), (3, 3), (6, 6)]
>>> find_closest_span_pairs(head, tail, backtrace=True)
[(0, 1), (3, 3), (6, 6), (3, 5)]
"""
if isinstance(head, torch.Tensor):
head = head.detach().cpu()
if isinstance(tail, torch.Tensor):
tail = tail.detach().cpu()
head_valid_poses = np.where(head == 1)[0]
tail_valid_poses = np.where(tail == 1)[0]
tail_used_poses = {pos: (False) for pos in tail_valid_poses.tolist()}
pairs = []
for head_i in head_valid_poses:
tail_js = tail_valid_poses[tail_valid_poses >= head_i]
if len(tail_js) > 0:
tail_j = tail_js[0]
tail_used_poses[tail_j] = True
pairs.append((head_i, tail_j))
if backtrace:
for tail_j in tail_used_poses:
if tail_used_poses[tail_j] is False:
head_is = head_valid_poses[head_valid_poses <= tail_j]
if len(head_is) > 0:
head_i = head_is[-1]
pairs.append((head_i, tail_j))
return pairs
def find_closest_span_pairs_with_index(heads: 'Iterable', tails: 'Iterable',
backtrace: 'Optional[bool]'=True):
"""
Find all possible pairs with indexes,
useful for object discoveries with class idx.
Args:
heads: batch of torch.Tensor
tails: batch of torch.Tensor
backtrace: if there are more tail predictions than head predictions,
then backtrace to find a closest head position to get a span pair
Examples:
>>> heads = torch.tensor([[1, 0, 0, 1, 0, 0, 1], [1, 0, 0, 1, 0, 0, 1]], dtype=torch.long)
>>> tails = torch.tensor([[0, 1, 0, 1, 0, 1, 1], [0, 1, 0, 0, 0, 1, 0]], dtype=torch.long)
>>> find_closest_span_pairs(heads, tails, backtrace=False)
[(0, 0, 1), (0, 3, 3), (0, 6, 6), (1, 0, 1), (1, 3, 5)]
>>> find_closest_span_pairs(heads, tails, backtrace=True)
[(0, 0, 1), (0, 3, 3), (0, 6, 6), (0, 3, 5), (1, 0, 1), (1, 3, 5)]
"""
results = []
for idx, (head, tail) in enumerate(zip(heads, tails)):
pairs = find_closest_span_pairs(head, tail, backtrace=backtrace)
for pair in pairs:
results.append((idx, pair[0], pair[1]))
return results
class SubjObjSpan(nn.Module):
"""
Inputs:
hidden: (batch_size, seq_len, hidden_size)
one_subj_head: object golden head with one subject (batch_size, hidden_size)
one_subj_tail: object golden tail with one subject (batch_size, hidden_size)
"""
def __init__(self, hidden_size, num_classes, threshold:
'Optional[float]'=0.5):
super().__init__()
self.threshold = threshold
self.subj_head_ffnn = nn.Linear(hidden_size, 1)
self.subj_tail_ffnn = nn.Linear(hidden_size, 1)
self.obj_head_ffnn = nn.Linear(hidden_size, num_classes)
self.obj_tail_ffnn = nn.Linear(hidden_size, num_classes)
def get_objs_for_specific_subj(self, subj_head_mapping,
subj_tail_mapping, hidden):
subj_head = torch.matmul(subj_head_mapping, hidden)
subj_tail = torch.matmul(subj_tail_mapping, hidden)
sub = (subj_head + subj_tail) / 2
encoded_text = hidden + sub
pred_obj_heads = self.obj_head_ffnn(encoded_text)
pred_obj_tails = self.obj_tail_ffnn(encoded_text)
return pred_obj_heads, pred_obj_tails
def build_mapping(self, subj_heads, subj_tails):
"""
Build head & tail mapping for predicted subjects,
for each instance in a batch, for a subject in all
the predicted subjects, return a single subject
and its corresponding mappings.
"""
for subj_head, subj_tail in zip(subj_heads, subj_tails):
subjs = find_closest_span_pairs(subj_head, subj_tail)
seq_len = subj_head.shape[0]
for subj in subjs:
subj_head_mapping = torch.zeros(seq_len, device=subj_head.
device)
subj_tail_mapping = torch.zeros(seq_len, device=subj_tail.
device)
subj_head_mapping[subj[0]] = 1.0
subj_tail_mapping[subj[1]] = 1.0
yield subj, subj_head_mapping, subj_tail_mapping
def build_batch_mapping(self, subj_head, subj_tail):
"""
Build head & tail mapping for predicted subjects,
for each instance in a batch, return all the predicted
subjects and mappings.
"""
subjs = find_closest_span_pairs(subj_head, subj_tail)
seq_len = subj_head.shape[0]
if len(subjs) > 0:
subjs_head_mapping = torch.zeros(len(subjs), seq_len, device=
subj_head.device)
subjs_tail_mapping = torch.zeros(len(subjs), seq_len, device=
subj_tail.device)
for subj_idx, subj in enumerate(subjs):
subjs_head_mapping[subj_idx, subj[0]] = 1.0
subjs_tail_mapping[subj_idx, subj[1]] = 1.0
return subjs, subjs_head_mapping, subjs_tail_mapping
else:
return None, None, None
def forward(self, hidden, subj_head, subj_tail):
subj_head_out = self.subj_head_ffnn(hidden)
subj_tail_out = self.subj_tail_ffnn(hidden)
obj_head_out, obj_tail_out = self.get_objs_for_specific_subj(subj_head
.unsqueeze(1), subj_tail.unsqueeze(1), hidden)
return subj_head_out.squeeze(-1), subj_tail_out.squeeze(-1
), obj_head_out, obj_tail_out
def predict(self, hidden):
if hidden.shape[0] != 1:
raise RuntimeError(
f'eval batch size must be 1 x hidden_size, while hidden is {hidden.shape}'
)
subj_head_out = self.subj_head_ffnn(hidden)
subj_tail_out = self.subj_tail_ffnn(hidden)
subj_head_out = torch.sigmoid(subj_head_out)
subj_tail_out = torch.sigmoid(subj_tail_out)
pred_subj_head = subj_head_out.ge(self.threshold).long()
pred_subj_tail = subj_tail_out.ge(self.threshold).long()
triples = []
subjs, subj_head_mappings, subj_tail_mappings = (self.
build_batch_mapping(pred_subj_head.squeeze(0).squeeze(-1),
pred_subj_tail.squeeze(0).squeeze(-1)))
if subjs:
obj_head_out, obj_tail_out = self.get_objs_for_specific_subj(
subj_head_mappings.unsqueeze(1), subj_tail_mappings.
unsqueeze(1), hidden)
obj_head_out = torch.sigmoid(obj_head_out)
obj_tail_out = torch.sigmoid(obj_tail_out)
obj_head_out = obj_head_out.ge(self.threshold).long()
obj_tail_out = obj_tail_out.ge(self.threshold).long()
for subj_idx, subj in enumerate(subjs):
objs = find_closest_span_pairs_with_index(obj_head_out[
subj_idx].permute(1, 0), obj_tail_out[subj_idx].permute
(1, 0))
for relation_idx, obj_pair_start, obj_pair_end in objs:
triples.append(((subj[0], subj[1] + 1), relation_idx, (
obj_pair_start, obj_pair_end + 1)))
return [triples]
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 [[], {'hidden_size': 4, 'num_classes': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import numpy as np
from typing import Iterable
from typing import Optional
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 64
x2 = xindex // 256
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + x3, tmp0, xmask)
@triton.jit
def triton_poi_fused_clone_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 256
x2 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tl.store(out_ptr0 + x2, tmp0, xmask)
@triton.jit
def triton_poi_fused_add_div_2(in_out_ptr0, in_ptr0, in_ptr1, xnumel,
XBLOCK: tl.constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 256
x2 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_out_ptr0 + x2, xmask)
tmp2 = tl.load(in_ptr1 + x2, xmask)
tmp3 = tmp1 + tmp2
tmp4 = 0.5
tmp5 = tmp3 * tmp4
tmp6 = tmp0 + tmp5
tl.store(in_out_ptr0 + x2, tmp6, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11) = args
args.clear()
assert_size_stride(primals_1, (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, 4), (4, 1))
assert_size_stride(primals_5, (1,), (1,))
assert_size_stride(primals_6, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_7, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_8, (4, 4), (4, 1))
assert_size_stride(primals_9, (4,), (1,))
assert_size_stride(primals_10, (4, 4), (4, 1))
assert_size_stride(primals_11, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
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
buf3 = empty_strided_cuda((64, 1), (1, 1), torch.float32)
extern_kernels.addmm(primals_5, reinterpret_tensor(primals_3, (64,
4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 1), (1, 4), 0
), alpha=1, beta=1, out=buf3)
del primals_4
del primals_5
buf4 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1),
torch.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(1024)](primals_6, buf4, 1024, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_6
buf5 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1),
torch.float32)
triton_poi_fused_clone_1[grid(1024)](primals_3, buf5, 1024, XBLOCK=
256, num_warps=4, num_stages=1)
buf6 = empty_strided_cuda((64, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf4, (64, 4, 4), (16, 4, 1),
0), reinterpret_tensor(buf5, (64, 4, 4), (16, 4, 1), 0), out=buf6)
buf7 = buf4
del buf4
triton_poi_fused_clone_0[grid(1024)](primals_7, buf7, 1024, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_7
buf8 = empty_strided_cuda((64, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf7, (64, 4, 4), (16, 4, 1),
0), reinterpret_tensor(buf5, (64, 4, 4), (16, 4, 1), 0), out=buf8)
del buf5
buf9 = reinterpret_tensor(buf6, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1), 0
)
del buf6
triton_poi_fused_add_div_2[grid(1024)](buf9, primals_3, buf8, 1024,
XBLOCK=256, num_warps=4, num_stages=1)
buf10 = reinterpret_tensor(buf8, (256, 4), (4, 1), 0)
del buf8
extern_kernels.addmm(primals_9, reinterpret_tensor(buf9, (256, 4),
(4, 1), 0), reinterpret_tensor(primals_8, (4, 4), (1, 4), 0),
alpha=1, beta=1, out=buf10)
del primals_8
del primals_9
buf11 = reinterpret_tensor(buf7, (256, 4), (4, 1), 0)
del buf7
extern_kernels.addmm(primals_11, reinterpret_tensor(buf9, (256, 4),
(4, 1), 0), reinterpret_tensor(primals_10, (4, 4), (1, 4), 0),
alpha=1, beta=1, out=buf11)
del primals_10
del primals_11
return reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0
), reinterpret_tensor(buf3, (4, 4, 4), (16, 4, 1), 0
), reinterpret_tensor(buf10, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1), 0
), reinterpret_tensor(buf11, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1), 0
), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), reinterpret_tensor(buf9, (256, 4), (4, 1), 0)
def find_closest_span_pairs(head: 'Iterable', tail: 'Iterable', backtrace:
'Optional[bool]'=True):
"""
Find all span pairs.
Args:
head: list of start position predictions, either 1 or 0
tail: list of end position predictions, either 1 or 0
backtrace: if there are more tail predictions than head predictions,
then backtrace to find a closest head position to get a span pair
Examples:
>>> head = torch.tensor([1, 0, 0, 1, 0, 0, 1], dtype=torch.long)
>>> tail = torch.tensor([0, 1, 0, 1, 0, 1, 1], dtype=torch.long)
>>> find_closest_span_pairs(head, tail, backtrace=False)
[(0, 1), (3, 3), (6, 6)]
>>> find_closest_span_pairs(head, tail, backtrace=True)
[(0, 1), (3, 3), (6, 6), (3, 5)]
"""
if isinstance(head, torch.Tensor):
head = head.detach().cpu()
if isinstance(tail, torch.Tensor):
tail = tail.detach().cpu()
head_valid_poses = np.where(head == 1)[0]
tail_valid_poses = np.where(tail == 1)[0]
tail_used_poses = {pos: (False) for pos in tail_valid_poses.tolist()}
pairs = []
for head_i in head_valid_poses:
tail_js = tail_valid_poses[tail_valid_poses >= head_i]
if len(tail_js) > 0:
tail_j = tail_js[0]
tail_used_poses[tail_j] = True
pairs.append((head_i, tail_j))
if backtrace:
for tail_j in tail_used_poses:
if tail_used_poses[tail_j] is False:
head_is = head_valid_poses[head_valid_poses <= tail_j]
if len(head_is) > 0:
head_i = head_is[-1]
pairs.append((head_i, tail_j))
return pairs
def find_closest_span_pairs_with_index(heads: 'Iterable', tails: 'Iterable',
backtrace: 'Optional[bool]'=True):
"""
Find all possible pairs with indexes,
useful for object discoveries with class idx.
Args:
heads: batch of torch.Tensor
tails: batch of torch.Tensor
backtrace: if there are more tail predictions than head predictions,
then backtrace to find a closest head position to get a span pair
Examples:
>>> heads = torch.tensor([[1, 0, 0, 1, 0, 0, 1], [1, 0, 0, 1, 0, 0, 1]], dtype=torch.long)
>>> tails = torch.tensor([[0, 1, 0, 1, 0, 1, 1], [0, 1, 0, 0, 0, 1, 0]], dtype=torch.long)
>>> find_closest_span_pairs(heads, tails, backtrace=False)
[(0, 0, 1), (0, 3, 3), (0, 6, 6), (1, 0, 1), (1, 3, 5)]
>>> find_closest_span_pairs(heads, tails, backtrace=True)
[(0, 0, 1), (0, 3, 3), (0, 6, 6), (0, 3, 5), (1, 0, 1), (1, 3, 5)]
"""
results = []
for idx, (head, tail) in enumerate(zip(heads, tails)):
pairs = find_closest_span_pairs(head, tail, backtrace=backtrace)
for pair in pairs:
results.append((idx, pair[0], pair[1]))
return results
class SubjObjSpanNew(nn.Module):
"""
Inputs:
hidden: (batch_size, seq_len, hidden_size)
one_subj_head: object golden head with one subject (batch_size, hidden_size)
one_subj_tail: object golden tail with one subject (batch_size, hidden_size)
"""
def __init__(self, hidden_size, num_classes, threshold:
'Optional[float]'=0.5):
super().__init__()
self.threshold = threshold
self.subj_head_ffnn = nn.Linear(hidden_size, 1)
self.subj_tail_ffnn = nn.Linear(hidden_size, 1)
self.obj_head_ffnn = nn.Linear(hidden_size, num_classes)
self.obj_tail_ffnn = nn.Linear(hidden_size, num_classes)
def get_objs_for_specific_subj(self, subj_head_mapping,
subj_tail_mapping, hidden):
subj_head = torch.matmul(subj_head_mapping, hidden)
subj_tail = torch.matmul(subj_tail_mapping, hidden)
sub = (subj_head + subj_tail) / 2
encoded_text = hidden + sub
pred_obj_heads = self.obj_head_ffnn(encoded_text)
pred_obj_tails = self.obj_tail_ffnn(encoded_text)
return pred_obj_heads, pred_obj_tails
def build_mapping(self, subj_heads, subj_tails):
"""
Build head & tail mapping for predicted subjects,
for each instance in a batch, for a subject in all
the predicted subjects, return a single subject
and its corresponding mappings.
"""
for subj_head, subj_tail in zip(subj_heads, subj_tails):
subjs = find_closest_span_pairs(subj_head, subj_tail)
seq_len = subj_head.shape[0]
for subj in subjs:
subj_head_mapping = torch.zeros(seq_len, device=subj_head.
device)
subj_tail_mapping = torch.zeros(seq_len, device=subj_tail.
device)
subj_head_mapping[subj[0]] = 1.0
subj_tail_mapping[subj[1]] = 1.0
yield subj, subj_head_mapping, subj_tail_mapping
def build_batch_mapping(self, subj_head, subj_tail):
"""
Build head & tail mapping for predicted subjects,
for each instance in a batch, return all the predicted
subjects and mappings.
"""
subjs = find_closest_span_pairs(subj_head, subj_tail)
seq_len = subj_head.shape[0]
if len(subjs) > 0:
subjs_head_mapping = torch.zeros(len(subjs), seq_len, device=
subj_head.device)
subjs_tail_mapping = torch.zeros(len(subjs), seq_len, device=
subj_tail.device)
for subj_idx, subj in enumerate(subjs):
subjs_head_mapping[subj_idx, subj[0]] = 1.0
subjs_tail_mapping[subj_idx, subj[1]] = 1.0
return subjs, subjs_head_mapping, subjs_tail_mapping
else:
return None, None, None
def predict(self, hidden):
if hidden.shape[0] != 1:
raise RuntimeError(
f'eval batch size must be 1 x hidden_size, while hidden is {hidden.shape}'
)
subj_head_out = self.subj_head_ffnn(hidden)
subj_tail_out = self.subj_tail_ffnn(hidden)
subj_head_out = torch.sigmoid(subj_head_out)
subj_tail_out = torch.sigmoid(subj_tail_out)
pred_subj_head = subj_head_out.ge(self.threshold).long()
pred_subj_tail = subj_tail_out.ge(self.threshold).long()
triples = []
subjs, subj_head_mappings, subj_tail_mappings = (self.
build_batch_mapping(pred_subj_head.squeeze(0).squeeze(-1),
pred_subj_tail.squeeze(0).squeeze(-1)))
if subjs:
obj_head_out, obj_tail_out = self.get_objs_for_specific_subj(
subj_head_mappings.unsqueeze(1), subj_tail_mappings.
unsqueeze(1), hidden)
obj_head_out = torch.sigmoid(obj_head_out)
obj_tail_out = torch.sigmoid(obj_tail_out)
obj_head_out = obj_head_out.ge(self.threshold).long()
obj_tail_out = obj_tail_out.ge(self.threshold).long()
for subj_idx, subj in enumerate(subjs):
objs = find_closest_span_pairs_with_index(obj_head_out[
subj_idx].permute(1, 0), obj_tail_out[subj_idx].permute
(1, 0))
for relation_idx, obj_pair_start, obj_pair_end in objs:
triples.append(((subj[0], subj[1] + 1), relation_idx, (
obj_pair_start, obj_pair_end + 1)))
return [triples]
def forward(self, input_0, input_1, input_2):
primals_1 = self.subj_head_ffnn.weight
primals_2 = self.subj_head_ffnn.bias
primals_4 = self.subj_tail_ffnn.weight
primals_5 = self.subj_tail_ffnn.bias
primals_8 = self.obj_head_ffnn.weight
primals_9 = self.obj_head_ffnn.bias
primals_10 = self.obj_tail_ffnn.weight
primals_11 = self.obj_tail_ffnn.bias
primals_3 = input_0
primals_6 = input_1
primals_7 = input_2
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11])
return output[0], output[1], output[2], output[3]
|
Spico197/REx
|
SubjObjSpan
| false
| 17,945
|
[
"MIT"
] | 4
|
bb3cdb845765a63e9bd18070068af52a1b2db3f3
|
https://github.com/Spico197/REx/tree/bb3cdb845765a63e9bd18070068af52a1b2db3f3
|
make_dense
|
import torch
import torch.nn as nn
import torch.utils.model_zoo
class make_dense(nn.Module):
def __init__(self, channels_in, channels_out, kernel_size=3):
super(make_dense, self).__init__()
self.leaky_relu = nn.LeakyReLU(0.1, inplace=True)
self.conv = nn.Conv2d(channels_in, channels_out, kernel_size=
kernel_size, padding=(kernel_size - 1) // 2, bias=False)
def forward(self, x):
out = self.leaky_relu(self.conv(x))
out = torch.cat((x, out), 1)
return out
def get_inputs():
return [torch.rand([4, 4, 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
import torch.nn as nn
import torch.utils.model_zoo
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 512
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16 % 8
x0 = xindex % 16
x2 = xindex // 128
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 64 * x2), tmp4 & xmask, other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 8, tl.int64)
tmp9 = tl.load(in_ptr1 + (x0 + 16 * (-4 + x1) + 64 * x2), tmp6 & xmask,
other=0.0)
tmp10 = 0.0
tmp11 = tmp9 > tmp10
tmp12 = 0.1
tmp13 = tmp9 * tmp12
tmp14 = tl.where(tmp11, tmp9, tmp13)
tmp15 = tl.full(tmp14.shape, 0.0, tmp14.dtype)
tmp16 = tl.where(tmp6, tmp14, tmp15)
tmp17 = tl.where(tmp4, tmp5, tmp16)
tl.store(out_ptr0 + x3, tmp17, xmask)
@triton.jit
def triton_poi_fused_leaky_relu_leaky_relu_backward_1(in_ptr0, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 0.0
tmp2 = tmp0 > tmp1
tmp3 = 0.1
tmp4 = tmp0 * tmp3
tmp5 = tl.where(tmp2, tmp0, tmp4)
tmp6 = tmp5 > tmp1
tl.store(out_ptr0 + x0, tmp6, xmask)
def call(args):
primals_1, primals_2 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_2, primals_1, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1))
buf1 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(512)](primals_2, buf0, buf1, 512,
XBLOCK=128, num_warps=4, num_stages=1)
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
triton_poi_fused_leaky_relu_leaky_relu_backward_1[grid(256)](buf0,
buf2, 256, XBLOCK=128, num_warps=4, num_stages=1)
del buf0
return buf1, primals_1, primals_2, buf2
class make_denseNew(nn.Module):
def __init__(self, channels_in, channels_out, kernel_size=3):
super(make_denseNew, self).__init__()
self.leaky_relu = nn.LeakyReLU(0.1, inplace=True)
self.conv = nn.Conv2d(channels_in, channels_out, kernel_size=
kernel_size, padding=(kernel_size - 1) // 2, bias=False)
def forward(self, input_0):
primals_1 = self.conv.weight
primals_2 = input_0
output = call([primals_1, primals_2])
return output[0]
|
SeleSchaefer/super_resolution
|
make_dense
| false
| 17,946
|
[
"MIT"
] | 5
|
bf28a959fb150ceeadbd9f0bcfc12f3025cf82f4
|
https://github.com/SeleSchaefer/super_resolution/tree/bf28a959fb150ceeadbd9f0bcfc12f3025cf82f4
|
CE_loss
|
import torch
import torch.nn as nn
import torch.utils.model_zoo
class CE_loss(nn.Module):
def __init__(self):
super().__init__()
self.loss = nn.CrossEntropyLoss()
def forward(self, predict, target):
n, _c, h, w = target.data.shape
predict = predict.permute(0, 2, 3, 1).contiguous().view(n * h * w, -1)
target = target.permute(0, 2, 3, 1).contiguous().view(n * h * w, -1)
return self.loss(predict, torch.max(target, 1)[1])
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
import torch.utils.model_zoo
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused__log_softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 64
x1 = xindex // 64
x2 = xindex
tmp0 = tl.load(in_ptr0 + (16 * x1 + 64 * (x0 // 16) + x0 % 16), xmask)
tmp1 = tl.load(in_ptr0 + (64 * (x0 // 16) + x0 % 16), xmask,
eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (16 + 64 * (x0 // 16) + x0 % 16), xmask,
eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (32 + 64 * (x0 // 16) + x0 % 16), xmask,
eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (48 + 64 * (x0 // 16) + x0 % 16), xmask,
eviction_policy='evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_per_fused_max_nll_loss_forward_1(in_out_ptr0, in_ptr0, in_ptr1,
xnumel, rnumel, XBLOCK: tl.constexpr):
RBLOCK: tl.constexpr = 64
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + (64 * (r0 // 16) + r0 % 16), None)
tmp1 = tl.load(in_ptr0 + (16 + 64 * (r0 // 16) + r0 % 16), None)
tmp17 = tl.load(in_ptr0 + (32 + 64 * (r0 // 16) + r0 % 16), None)
tmp32 = tl.load(in_ptr0 + (48 + 64 * (r0 // 16) + r0 % 16), None)
tmp56 = tl.load(in_ptr1 + r0, None)
tmp58 = tl.load(in_ptr1 + (64 + r0), None)
tmp61 = tl.load(in_ptr1 + (128 + r0), None)
tmp64 = tl.load(in_ptr1 + (192 + r0), None)
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, 1], 0, tl.int64)
tmp11 = tl.full([1, 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, 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, 1], 3, tl.int64)
tmp42 = tmp31 < tmp41
tmp43 = tmp40 & tmp42
tmp44 = tmp38 | tmp43
tl.where(tmp44, tmp30, tmp32)
tmp46 = tl.where(tmp44, tmp31, tmp41)
tmp47 = tl.full([1, 1], -100, tl.int64)
tmp48 = tmp46 != tmp47
tmp49 = tl.where(tmp48, tmp46, tmp10)
tmp50 = tl.full([XBLOCK, RBLOCK], 4, tl.int32)
tmp51 = tmp49 + tmp50
tmp52 = tmp49 < 0
tmp53 = tl.where(tmp52, tmp51, tmp49)
tl.device_assert((0 <= tmp53) & (tmp53 < 4),
'index out of bounds: 0 <= tmp53 < 4')
tmp55 = tl.load(in_ptr1 + (r0 + 64 * tmp53), None)
tmp57 = tl_math.exp(tmp56)
tmp59 = tl_math.exp(tmp58)
tmp60 = tmp57 + tmp59
tmp62 = tl_math.exp(tmp61)
tmp63 = tmp60 + tmp62
tmp65 = tl_math.exp(tmp64)
tmp66 = tmp63 + tmp65
tmp67 = tl_math.log(tmp66)
tmp68 = tmp55 - tmp67
tmp69 = -tmp68
tmp70 = 0.0
tmp71 = tl.where(tmp48, tmp69, tmp70)
tmp72 = tl.broadcast_to(tmp71, [XBLOCK, RBLOCK])
tmp74 = tl.sum(tmp72, 1)[:, None]
tmp75 = tmp48.to(tl.int64)
tmp76 = tl.broadcast_to(tmp75, [XBLOCK, RBLOCK])
tmp78 = tl.sum(tmp76, 1)[:, None]
tmp79 = tmp78.to(tl.float32)
tmp80 = tmp74 / tmp79
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp80, 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)
buf1 = empty_strided_cuda((64, 4), (1, 64), torch.float32)
get_raw_stream(0)
triton_poi_fused__log_softmax_0[grid(256)](arg1_1, buf1, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del arg1_1
buf2 = empty_strided_cuda((), (), torch.float32)
buf4 = buf2
del buf2
triton_per_fused_max_nll_loss_forward_1[grid(1)](buf4, arg0_1, buf1,
1, 64, XBLOCK=1, num_warps=2, num_stages=1)
del arg0_1
del buf1
return buf4,
class CE_lossNew(nn.Module):
def __init__(self):
super().__init__()
self.loss = nn.CrossEntropyLoss()
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
SeleSchaefer/super_resolution
|
CE_loss
| false
| 17,947
|
[
"MIT"
] | 5
|
bf28a959fb150ceeadbd9f0bcfc12f3025cf82f4
|
https://github.com/SeleSchaefer/super_resolution/tree/bf28a959fb150ceeadbd9f0bcfc12f3025cf82f4
|
LogSTFTMagnitude
|
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.data
class LogSTFTMagnitude(nn.Module):
def __init__(self):
super().__init__()
def forward(self, predicts_mag, targets_mag):
log_predicts_mag = torch.log(predicts_mag)
log_targets_mag = torch.log(targets_mag)
outputs = F.l1_loss(log_predicts_mag, log_targets_mag)
return outputs
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
import torch.utils.data
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_abs_log_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)
tmp2 = tl.load(in_ptr1 + r0, None)
tmp1 = tl_math.log(tmp0)
tmp3 = tl_math.log(tmp2)
tmp4 = tmp1 - tmp3
tmp5 = tl_math.abs(tmp4)
tmp6 = tl.broadcast_to(tmp5, [RBLOCK])
tmp8 = triton_helpers.promote_to_tensor(tl.sum(tmp6, 0))
tmp9 = 256.0
tmp10 = tmp8 / tmp9
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp10, 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_log_mean_sub_0[grid(1)](buf1, arg0_1, arg1_1,
1, 256, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
return buf1,
class LogSTFTMagnitudeNew(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]
|
SolomidHero/speech-regeneration-enhancer
|
LogSTFTMagnitude
| false
| 17,948
|
[
"MIT"
] | 8
|
eb43907ff085d68a707ff7bc3af14e93ff66fd65
|
https://github.com/SolomidHero/speech-regeneration-enhancer/tree/eb43907ff085d68a707ff7bc3af14e93ff66fd65
|
Smoother
|
from torch.nn import Module
import torch
from torch import Tensor
from typing import Optional
import torch.nn.functional as F
from torch.nn import Dropout
from torch.nn import LayerNorm
from torch.nn import Conv1d
from torch.nn import MultiheadAttention
class Smoother(Module):
"""Convolutional Transformer Encoder Layer"""
def __init__(self, d_model: 'int', nhead: 'int', d_hid: 'int', dropout=0.1
):
super(Smoother, self).__init__()
self.self_attn = MultiheadAttention(d_model, nhead, dropout=dropout)
self.conv1 = Conv1d(d_model, d_hid, 9, padding=4)
self.conv2 = Conv1d(d_hid, d_model, 1, padding=0)
self.norm1 = LayerNorm(d_model)
self.norm2 = LayerNorm(d_model)
self.dropout1 = Dropout(dropout)
self.dropout2 = Dropout(dropout)
def forward(self, src: 'Tensor', src_mask: 'Optional[Tensor]'=None,
src_key_padding_mask: 'Optional[Tensor]'=None) ->Tensor:
src2 = self.self_attn(src, src, src, attn_mask=src_mask,
key_padding_mask=src_key_padding_mask)[0]
src = src + self.dropout1(src2)
src = self.norm1(src)
src2 = src.transpose(0, 1).transpose(1, 2)
src2 = self.conv2(F.relu(self.conv1(src2)))
src2 = src2.transpose(1, 2).transpose(0, 1)
src = src + self.dropout2(src2)
src = self.norm2(src)
return src
def get_inputs():
return [torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'d_model': 4, 'nhead': 4, 'd_hid': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch.nn import Module
from torch.nn import Dropout
from torch.nn import LayerNorm
from torch.nn import Conv1d
from torch.nn import MultiheadAttention
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_clone_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 192
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4 % 16
x2 = xindex // 64
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 12 * x1), xmask)
tmp1 = tl.load(in_ptr1 + (x0 + 4 * x2), xmask, eviction_policy='evict_last'
)
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + x3, tmp2, xmask)
@triton.jit
def triton_poi_fused_mul_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 1.0
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = 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_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused_clone_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 4
xnumel = 16
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x1 = xindex
y0 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x1), xmask & ymask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (x1 + 16 * y0), 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-05
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp4 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tl.store(out_ptr0 + x2, tmp13, xmask)
@triton.jit
def triton_poi_fused_convolution_7(in_ptr0, out_ptr0, ynumel, xnumel,
YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x1 = xindex
y0 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 16 * x1), xmask & ymask, eviction_policy
='evict_last')
tl.store(out_ptr0 + (x1 + 4 * y0), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_convolution_relu_8(in_out_ptr0, in_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 4 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
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_9(in_ptr0, in_ptr1, in_ptr2, 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
x3 = xindex
y0 = yindex
x1 = xindex % 4
tmp0 = tl.load(in_ptr0 + (x3 + 16 * y0), xmask & ymask, eviction_policy
='evict_last')
tmp1 = tl.load(in_ptr1 + (y0 + 4 * x3), xmask & ymask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp4 = tmp0 + tmp3
tl.store(out_ptr0 + (x3 + 16 * y0), tmp4, xmask & ymask)
@triton.jit
def triton_poi_fused_native_layer_norm_10(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp7 = 4.0
tmp8 = tmp6 / tmp7
tmp9 = tmp0 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tmp1 - tmp8
tmp12 = tmp11 * tmp11
tmp13 = tmp10 + tmp12
tmp14 = tmp3 - tmp8
tmp15 = tmp14 * tmp14
tmp16 = tmp13 + tmp15
tmp17 = tmp5 - tmp8
tmp18 = tmp17 * tmp17
tmp19 = tmp16 + tmp18
tmp20 = tmp19 / tmp7
tmp21 = 1e-05
tmp22 = tmp20 + tmp21
tmp23 = libdevice.rsqrt(tmp22)
tl.store(out_ptr0 + x0, tmp8, xmask)
tl.store(out_ptr1 + x0, tmp23, xmask)
@triton.jit
def triton_poi_fused_native_layer_norm_11(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = tmp2 * tmp3
tmp6 = tmp4 * tmp5
tmp8 = tmp6 + tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
primals_13) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (12,), (1,))
assert_size_stride(primals_3, (12, 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,), (1,))
assert_size_stride(primals_7, (4,), (1,))
assert_size_stride(primals_8, (4, 4, 9), (36, 9, 1))
assert_size_stride(primals_9, (4,), (1,))
assert_size_stride(primals_10, (4, 4, 1), (4, 1, 1))
assert_size_stride(primals_11, (4,), (1,))
assert_size_stride(primals_12, (4,), (1,))
assert_size_stride(primals_13, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((16, 12), (12, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_3, (4, 12), (1, 4), 0), out=buf0)
del primals_3
buf1 = empty_strided_cuda((3, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(192)](buf0, primals_2, buf1, 192,
XBLOCK=128, num_warps=4, num_stages=1)
del buf0
del primals_2
buf2 = empty_strided_cuda((16, 4, 1), (1, 16, 64), torch.float32)
triton_poi_fused_mul_1[grid(64)](buf1, buf2, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf3 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf2, reinterpret_tensor(buf1, (16, 1, 4), (1, 0,
16), 64), out=buf3)
buf4 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_2[grid(256)](buf3, buf4, 256, XBLOCK=256,
num_warps=4, num_stages=1)
buf5 = buf3
del buf3
triton_poi_fused__softmax_3[grid(256)](buf4, buf5, 256, XBLOCK=128,
num_warps=4, num_stages=1)
del buf4
buf6 = empty_strided_cuda((16, 4, 1), (4, 1, 1), torch.float32)
extern_kernels.bmm(buf5, reinterpret_tensor(buf1, (16, 4, 1), (1,
16, 0), 128), out=buf6)
buf7 = empty_strided_cuda((4, 16, 1), (16, 1, 1), torch.float32)
triton_poi_fused_clone_4[grid(4, 16)](buf6, buf7, 4, 16, XBLOCK=16,
YBLOCK=4, num_warps=1, num_stages=1)
buf8 = reinterpret_tensor(buf6, (16, 4), (4, 1), 0)
del buf6
extern_kernels.addmm(primals_5, reinterpret_tensor(buf7, (16, 4), (
4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0),
alpha=1, beta=1, out=buf8)
del primals_5
buf9 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
buf10 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
triton_poi_fused_add_native_layer_norm_5[grid(16)](primals_1, buf8,
buf9, buf10, 16, XBLOCK=16, num_warps=1, num_stages=1)
buf11 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_native_layer_norm_6[grid(64)](primals_1, buf8,
buf9, buf10, primals_6, primals_7, buf11, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del primals_7
buf12 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_convolution_7[grid(16, 4)](buf11, buf12, 16, 4,
XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1)
buf13 = extern_kernels.convolution(buf12, primals_8, stride=(1,),
padding=(4,), dilation=(1,), transposed=False, output_padding=(
0,), groups=1, bias=None)
assert_size_stride(buf13, (4, 4, 4), (16, 4, 1))
buf14 = buf13
del buf13
triton_poi_fused_convolution_relu_8[grid(64)](buf14, primals_9, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del primals_9
buf15 = extern_kernels.convolution(buf14, primals_10, stride=(1,),
padding=(0,), dilation=(1,), transposed=False, output_padding=(
0,), groups=1, bias=None)
assert_size_stride(buf15, (4, 4, 4), (16, 4, 1))
buf16 = buf12
del buf12
triton_poi_fused_add_9[grid(4, 16)](buf11, buf15, primals_11, buf16,
4, 16, XBLOCK=16, YBLOCK=2, num_warps=1, num_stages=1)
del primals_11
buf17 = buf9
del buf9
buf18 = buf10
del buf10
triton_poi_fused_native_layer_norm_10[grid(16)](buf16, buf17, buf18,
16, XBLOCK=16, num_warps=1, num_stages=1)
buf19 = buf15
del buf15
triton_poi_fused_native_layer_norm_11[grid(64)](buf16, buf17, buf18,
primals_12, primals_13, buf19, 64, XBLOCK=64, num_warps=1,
num_stages=1)
del buf17
del buf18
del primals_13
return (buf19, primals_1, primals_6, primals_8, primals_10, primals_12,
buf5, reinterpret_tensor(buf7, (16, 4), (4, 1), 0), buf8,
reinterpret_tensor(buf11, (4, 4, 4), (4, 1, 16), 0), buf14, buf16,
primals_4, reinterpret_tensor(buf1, (16, 1, 4), (1, 1, 16), 128),
reinterpret_tensor(buf2, (16, 1, 4), (1, 1, 16), 0),
reinterpret_tensor(buf1, (16, 4, 1), (1, 16, 1), 64))
class SmootherNew(Module):
"""Convolutional Transformer Encoder Layer"""
def __init__(self, d_model: 'int', nhead: 'int', d_hid: 'int', dropout=0.1
):
super(SmootherNew, self).__init__()
self.self_attn = MultiheadAttention(d_model, nhead, dropout=dropout)
self.conv1 = Conv1d(d_model, d_hid, 9, padding=4)
self.conv2 = Conv1d(d_hid, d_model, 1, padding=0)
self.norm1 = LayerNorm(d_model)
self.norm2 = LayerNorm(d_model)
self.dropout1 = Dropout(dropout)
self.dropout2 = Dropout(dropout)
def forward(self, input_0):
primals_3 = self.self_attn.in_proj_weight
primals_2 = self.self_attn.in_proj_bias
primals_4 = self.self_attn.out_proj.weight
primals_5 = self.self_attn.out_proj.bias
primals_8 = self.conv1.weight
primals_6 = self.conv1.bias
primals_10 = self.conv2.weight
primals_7 = self.conv2.bias
primals_9 = self.norm1.weight
primals_11 = self.norm1.bias
primals_12 = self.norm2.weight
primals_13 = self.norm2.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11, primals_12, primals_13])
return output[0]
|
SolomidHero/FragmentVC-with-RAdam
|
Smoother
| false
| 17,949
|
[
"MIT"
] | 6
|
a0ee884155a4e8f47d8950a35258e58987f6289e
|
https://github.com/SolomidHero/FragmentVC-with-RAdam/tree/a0ee884155a4e8f47d8950a35258e58987f6289e
|
Extractor
|
from torch.nn import Module
import torch
from torch import Tensor
from typing import Optional
from typing import Tuple
import torch.nn.functional as F
from torch.nn import Dropout
from torch.nn import LayerNorm
from torch.nn import Conv1d
from torch.nn import MultiheadAttention
class Extractor(Module):
"""Convolutional Transformer Decoder Layer"""
def __init__(self, d_model: 'int', nhead: 'int', d_hid: 'int', dropout=
0.1, no_residual=False):
super(Extractor, self).__init__()
self.self_attn = MultiheadAttention(d_model, nhead, dropout=dropout)
self.cross_attn = MultiheadAttention(d_model, nhead, dropout=dropout)
self.conv1 = Conv1d(d_model, d_hid, 9, padding=4)
self.conv2 = Conv1d(d_hid, d_model, 1, padding=0)
self.norm1 = LayerNorm(d_model)
self.norm2 = LayerNorm(d_model)
self.norm3 = LayerNorm(d_model)
self.dropout1 = Dropout(dropout)
self.dropout2 = Dropout(dropout)
self.dropout3 = Dropout(dropout)
self.no_residual = no_residual
def forward(self, tgt: 'Tensor', memory: 'Tensor', tgt_mask:
'Optional[Tensor]'=None, memory_mask: 'Optional[Tensor]'=None,
tgt_key_padding_mask: 'Optional[Tensor]'=None,
memory_key_padding_mask: 'Optional[Tensor]'=None, memory_features:
'Optional[Tensor]'=None) ->Tuple[Tensor, Optional[Tensor]]:
tgt2 = self.self_attn(tgt, tgt, tgt, attn_mask=tgt_mask,
key_padding_mask=tgt_key_padding_mask)[0]
tgt = tgt + self.dropout1(tgt2)
tgt = self.norm1(tgt)
tgt2, attn = self.cross_attn(tgt, memory if memory_features is None
else memory_features, memory, attn_mask=memory_mask,
key_padding_mask=memory_key_padding_mask)
if self.no_residual:
tgt = self.dropout2(tgt2)
else:
tgt = tgt + self.dropout2(tgt2)
tgt = self.norm2(tgt)
tgt2 = tgt.transpose(0, 1).transpose(1, 2)
tgt2 = self.conv2(F.relu(self.conv1(tgt2)))
tgt2 = tgt2.transpose(1, 2).transpose(0, 1)
tgt = tgt + self.dropout3(tgt2)
tgt = self.norm3(tgt)
return tgt, attn
def get_inputs():
return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'d_model': 4, 'nhead': 4, 'd_hid': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch.nn import Module
from torch.nn import Dropout
from torch.nn import LayerNorm
from torch.nn import Conv1d
from torch.nn import MultiheadAttention
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_clone_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 192
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4 % 16
x2 = xindex // 64
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 12 * x1), xmask)
tmp1 = tl.load(in_ptr1 + (x0 + 4 * x2), xmask, eviction_policy='evict_last'
)
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + x3, tmp2, xmask)
@triton.jit
def triton_poi_fused_mul_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 1.0
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = 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_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused_clone_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 4
xnumel = 16
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x1 = xindex
y0 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x1), xmask & ymask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (x1 + 16 * y0), 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-05
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp4 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tl.store(out_ptr0 + x2, tmp13, xmask)
@triton.jit
def triton_poi_fused_clone_7(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4 % 16
x2 = xindex // 64
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 8 * x1), xmask)
tmp1 = tl.load(in_ptr1 + (4 + x0 + 4 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + x3, tmp2, xmask)
@triton.jit
def triton_poi_fused_mul_8(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
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x2 % 4, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 1.0
tmp4 = tmp2 * tmp3
tl.store(in_out_ptr0 + x2, tmp4, xmask)
@triton.jit
def triton_poi_fused_mean_9(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 16
x1 = xindex // 16
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask)
tmp1 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask)
tmp3 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask)
tmp5 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp7 = 4.0
tmp8 = tmp6 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused_add_10(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK:
tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_out_ptr0 + x2, xmask)
tmp2 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp4 = tmp0 + tmp3
tl.store(in_out_ptr0 + x2, tmp4, xmask)
@triton.jit
def triton_poi_fused_native_layer_norm_11(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp7 = 4.0
tmp8 = tmp6 / tmp7
tmp9 = tmp0 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tmp1 - tmp8
tmp12 = tmp11 * tmp11
tmp13 = tmp10 + tmp12
tmp14 = tmp3 - tmp8
tmp15 = tmp14 * tmp14
tmp16 = tmp13 + tmp15
tmp17 = tmp5 - tmp8
tmp18 = tmp17 * tmp17
tmp19 = tmp16 + tmp18
tmp20 = tmp19 / tmp7
tmp21 = 1e-05
tmp22 = tmp20 + tmp21
tmp23 = libdevice.rsqrt(tmp22)
tl.store(out_ptr0 + x0, tmp8, xmask)
tl.store(out_ptr1 + x0, tmp23, xmask)
@triton.jit
def triton_poi_fused_native_layer_norm_12(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = tmp2 * tmp3
tmp6 = tmp4 * tmp5
tmp8 = tmp6 + tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused_convolution_13(in_ptr0, out_ptr0, ynumel, xnumel,
YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x1 = xindex
y0 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 16 * x1), xmask & ymask, eviction_policy
='evict_last')
tl.store(out_ptr0 + (x1 + 4 * y0), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_convolution_relu_14(in_out_ptr0, in_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 4 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
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_15(in_ptr0, in_ptr1, in_ptr2, 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
x3 = xindex
y0 = yindex
x1 = xindex % 4
tmp0 = tl.load(in_ptr0 + (x3 + 16 * y0), xmask & ymask, eviction_policy
='evict_last')
tmp1 = tl.load(in_ptr1 + (y0 + 4 * x3), xmask & ymask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp4 = tmp0 + tmp3
tl.store(out_ptr0 + (x3 + 16 * y0), tmp4, xmask & ymask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
primals_13, primals_14, primals_15, primals_16, primals_17,
primals_18, primals_19, primals_20) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (12,), (1,))
assert_size_stride(primals_3, (12, 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,), (1,))
assert_size_stride(primals_7, (4,), (1,))
assert_size_stride(primals_8, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_9, (12, 4), (4, 1))
assert_size_stride(primals_10, (12,), (1,))
assert_size_stride(primals_11, (4, 4), (4, 1))
assert_size_stride(primals_12, (4,), (1,))
assert_size_stride(primals_13, (4,), (1,))
assert_size_stride(primals_14, (4,), (1,))
assert_size_stride(primals_15, (4, 4, 9), (36, 9, 1))
assert_size_stride(primals_16, (4,), (1,))
assert_size_stride(primals_17, (4, 4, 1), (4, 1, 1))
assert_size_stride(primals_18, (4,), (1,))
assert_size_stride(primals_19, (4,), (1,))
assert_size_stride(primals_20, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((16, 12), (12, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_3, (4, 12), (1, 4), 0), out=buf0)
del primals_3
buf1 = empty_strided_cuda((3, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(192)](buf0, primals_2, buf1, 192,
XBLOCK=128, num_warps=4, num_stages=1)
del buf0
del primals_2
buf2 = empty_strided_cuda((16, 4, 1), (1, 16, 64), torch.float32)
triton_poi_fused_mul_1[grid(64)](buf1, buf2, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf3 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf2, reinterpret_tensor(buf1, (16, 1, 4), (1, 0,
16), 64), out=buf3)
buf4 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_2[grid(256)](buf3, buf4, 256, XBLOCK=256,
num_warps=4, num_stages=1)
buf5 = buf3
del buf3
triton_poi_fused__softmax_3[grid(256)](buf4, buf5, 256, XBLOCK=128,
num_warps=4, num_stages=1)
buf6 = empty_strided_cuda((16, 4, 1), (4, 1, 1), torch.float32)
extern_kernels.bmm(buf5, reinterpret_tensor(buf1, (16, 4, 1), (1,
16, 0), 128), out=buf6)
buf7 = empty_strided_cuda((4, 16, 1), (16, 1, 1), torch.float32)
triton_poi_fused_clone_4[grid(4, 16)](buf6, buf7, 4, 16, XBLOCK=16,
YBLOCK=4, num_warps=1, num_stages=1)
buf8 = reinterpret_tensor(buf6, (16, 4), (4, 1), 0)
del buf6
extern_kernels.addmm(primals_5, reinterpret_tensor(buf7, (16, 4), (
4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0),
alpha=1, beta=1, out=buf8)
del primals_5
buf9 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
buf10 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
triton_poi_fused_add_native_layer_norm_5[grid(16)](primals_1, buf8,
buf9, buf10, 16, XBLOCK=16, num_warps=1, num_stages=1)
buf11 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_native_layer_norm_6[grid(64)](primals_1, buf8,
buf9, buf10, primals_6, primals_7, buf11, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del primals_7
buf12 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf11, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_9, (4, 4), (1, 4), 0), out=buf12)
buf13 = empty_strided_cuda((16, 8), (8, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_8, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_9, (4, 8), (1, 4), 16), out=buf13)
buf14 = empty_strided_cuda((2, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_clone_7[grid(128)](buf13, primals_10, buf14, 128,
XBLOCK=128, num_warps=4, num_stages=1)
del buf13
buf15 = reinterpret_tensor(buf12, (16, 4, 1), (1, 16, 64), 0)
del buf12
triton_poi_fused_mul_8[grid(64)](buf15, primals_10, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del primals_10
buf16 = buf4
del buf4
extern_kernels.bmm(buf15, reinterpret_tensor(buf14, (16, 1, 4), (1,
0, 16), 0), out=buf16)
buf17 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_2[grid(256)](buf16, buf17, 256, XBLOCK=
256, num_warps=4, num_stages=1)
buf18 = buf16
del buf16
triton_poi_fused__softmax_3[grid(256)](buf17, buf18, 256, XBLOCK=
128, num_warps=4, num_stages=1)
del buf17
buf19 = empty_strided_cuda((16, 4, 1), (4, 1, 1), torch.float32)
extern_kernels.bmm(buf18, reinterpret_tensor(buf14, (16, 4, 1), (1,
16, 0), 64), out=buf19)
buf20 = empty_strided_cuda((4, 16, 1), (16, 1, 1), torch.float32)
triton_poi_fused_clone_4[grid(4, 16)](buf19, buf20, 4, 16, XBLOCK=
16, YBLOCK=4, num_warps=1, num_stages=1)
buf21 = reinterpret_tensor(buf19, (16, 4), (4, 1), 0)
del buf19
extern_kernels.mm(reinterpret_tensor(buf20, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_11, (4, 4), (1, 4), 0), out=buf21)
buf22 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_mean_9[grid(64)](buf18, buf22, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf23 = reinterpret_tensor(buf21, (4, 4, 4), (16, 4, 1), 0)
del buf21
triton_poi_fused_add_10[grid(64)](buf23, buf11, primals_12, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del primals_12
buf24 = buf9
del buf9
buf25 = buf10
del buf10
triton_poi_fused_native_layer_norm_11[grid(16)](buf23, buf24, buf25,
16, XBLOCK=16, num_warps=1, num_stages=1)
buf26 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_native_layer_norm_12[grid(64)](buf23, buf24, buf25,
primals_13, primals_14, buf26, 64, XBLOCK=64, num_warps=1,
num_stages=1)
del primals_14
buf27 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_convolution_13[grid(16, 4)](buf26, buf27, 16, 4,
XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1)
buf28 = extern_kernels.convolution(buf27, primals_15, stride=(1,),
padding=(4,), dilation=(1,), transposed=False, output_padding=(
0,), groups=1, bias=None)
assert_size_stride(buf28, (4, 4, 4), (16, 4, 1))
buf29 = buf28
del buf28
triton_poi_fused_convolution_relu_14[grid(64)](buf29, primals_16,
64, XBLOCK=64, num_warps=1, num_stages=1)
del primals_16
buf30 = extern_kernels.convolution(buf29, primals_17, stride=(1,),
padding=(0,), dilation=(1,), transposed=False, output_padding=(
0,), groups=1, bias=None)
assert_size_stride(buf30, (4, 4, 4), (16, 4, 1))
buf31 = buf27
del buf27
triton_poi_fused_add_15[grid(4, 16)](buf26, buf30, primals_18,
buf31, 4, 16, XBLOCK=16, YBLOCK=2, num_warps=1, num_stages=1)
del primals_18
buf32 = buf25
del buf25
buf33 = buf24
del buf24
triton_poi_fused_native_layer_norm_11[grid(16)](buf31, buf32, buf33,
16, XBLOCK=16, num_warps=1, num_stages=1)
buf34 = buf30
del buf30
triton_poi_fused_native_layer_norm_12[grid(64)](buf31, buf32, buf33,
primals_19, primals_20, buf34, 64, XBLOCK=64, num_warps=1,
num_stages=1)
del buf32
del buf33
del primals_20
return (buf34, buf22, primals_1, primals_6, primals_13, primals_15,
primals_17, primals_19, buf5, reinterpret_tensor(buf7, (16, 4), (4,
1), 0), buf8, reinterpret_tensor(buf11, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_8, (16, 4), (4, 1), 0), buf18,
reinterpret_tensor(buf20, (16, 4), (4, 1), 0), buf23,
reinterpret_tensor(buf26, (4, 4, 4), (4, 1, 16), 0), buf29, buf31,
primals_11, reinterpret_tensor(buf14, (16, 1, 4), (1, 1, 16), 64),
reinterpret_tensor(buf15, (16, 1, 4), (1, 1, 16), 0),
reinterpret_tensor(buf14, (16, 4, 1), (1, 16, 1), 0),
reinterpret_tensor(primals_9, (4, 4), (4, 1), 0), primals_4,
reinterpret_tensor(buf1, (16, 1, 4), (1, 1, 16), 128),
reinterpret_tensor(buf2, (16, 1, 4), (1, 1, 16), 0),
reinterpret_tensor(buf1, (16, 4, 1), (1, 16, 1), 64))
class ExtractorNew(Module):
"""Convolutional Transformer Decoder Layer"""
def __init__(self, d_model: 'int', nhead: 'int', d_hid: 'int', dropout=
0.1, no_residual=False):
super(ExtractorNew, self).__init__()
self.self_attn = MultiheadAttention(d_model, nhead, dropout=dropout)
self.cross_attn = MultiheadAttention(d_model, nhead, dropout=dropout)
self.conv1 = Conv1d(d_model, d_hid, 9, padding=4)
self.conv2 = Conv1d(d_hid, d_model, 1, padding=0)
self.norm1 = LayerNorm(d_model)
self.norm2 = LayerNorm(d_model)
self.norm3 = LayerNorm(d_model)
self.dropout1 = Dropout(dropout)
self.dropout2 = Dropout(dropout)
self.dropout3 = Dropout(dropout)
self.no_residual = no_residual
def forward(self, input_0, input_1):
primals_3 = self.self_attn.in_proj_weight
primals_2 = self.self_attn.in_proj_bias
primals_4 = self.self_attn.out_proj.weight
primals_5 = self.self_attn.out_proj.bias
primals_9 = self.cross_attn.in_proj_weight
primals_10 = self.cross_attn.in_proj_bias
primals_11 = self.cross_attn.out_proj.weight
primals_6 = self.cross_attn.out_proj.bias
primals_15 = self.conv1.weight
primals_7 = self.conv1.bias
primals_17 = self.conv2.weight
primals_12 = self.conv2.bias
primals_13 = self.norm1.weight
primals_14 = self.norm1.bias
primals_16 = self.norm2.weight
primals_18 = self.norm2.bias
primals_19 = self.norm3.weight
primals_20 = self.norm3.bias
primals_1 = input_0
primals_8 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11, primals_12, primals_13, primals_14,
primals_15, primals_16, primals_17, primals_18, primals_19,
primals_20])
return output[0], output[1]
|
SolomidHero/FragmentVC-with-RAdam
|
Extractor
| false
| 17,950
|
[
"MIT"
] | 6
|
a0ee884155a4e8f47d8950a35258e58987f6289e
|
https://github.com/SolomidHero/FragmentVC-with-RAdam/tree/a0ee884155a4e8f47d8950a35258e58987f6289e
|
State_Autoencoder
|
import torch
import torch.nn as nn
from collections import OrderedDict
class State_Autoencoder(nn.Module):
def __init__(self, frame_stacks=1, channels=3):
super(State_Autoencoder, self).__init__()
self.encoder = nn.Sequential(OrderedDict([('encoder_conv1', nn.
Conv2d(channels * frame_stacks, 16, kernel_size=3, stride=2,
padding=1)), ('encoder_relu1', nn.ReLU()), ('encoder_conv2', nn
.Conv2d(16, 32, kernel_size=3, stride=2, padding=1)), (
'encoder_relu2', nn.ReLU()), ('encoder_conv3', nn.Conv2d(32, 64,
kernel_size=7)), ('encoder_relu3', nn.LeakyReLU())]))
self.bottleneck = nn.Sequential(OrderedDict([('bottleneck_conv1',
nn.Conv2d(64, 64, kernel_size=(1, 1))), ('bottleneck_relu1', nn
.ReLU())]))
self.decoder = nn.Sequential(OrderedDict([('decoder_Tconv1', nn.
ConvTranspose2d(64, 32, kernel_size=7)), ('decoder_relu1', nn.
ReLU()), ('decoder_Tconv2', nn.ConvTranspose2d(32, 16,
kernel_size=3, stride=2, padding=1, output_padding=1)), (
'decoder_relu2', nn.ReLU()), ('decoder_Tconv3', nn.
ConvTranspose2d(16, channels * frame_stacks, kernel_size=3,
stride=2, padding=1, output_padding=1)), ('decoder_relu3', nn.
LeakyReLU())]))
def forward(self, x):
x = self.encoder(x)
x1 = self.bottleneck(x)
x1 = self.decoder(x1)
return x1
def get_inputs():
return [torch.rand([4, 3, 64, 64])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
from collections import OrderedDict
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_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 // 1024 % 16
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x3, tmp4, None)
@triton.jit
def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel,
XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 256 % 32
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x3, tmp4, None)
@triton.jit
def triton_poi_fused_convolution_leaky_relu_2(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 25600
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 100 % 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp5 = 0.01
tmp6 = tmp2 * tmp5
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(out_ptr0 + x3, tmp4, xmask)
tl.store(out_ptr1 + x3, tmp7, xmask)
@triton.jit
def triton_poi_fused_convolution_relu_3(in_out_ptr0, in_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 25600
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 100 % 64
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x3, tmp4, xmask)
@triton.jit
def triton_poi_fused_convolution_leaky_relu_4(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 4096 % 3
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp5 = 0.01
tmp6 = tmp2 * tmp5
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(out_ptr0 + x3, tmp4, None)
tl.store(out_ptr1 + x3, tmp7, None)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
primals_13, primals_14, primals_15) = args
args.clear()
assert_size_stride(primals_1, (16, 3, 3, 3), (27, 9, 3, 1))
assert_size_stride(primals_2, (16,), (1,))
assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 1))
assert_size_stride(primals_4, (32, 16, 3, 3), (144, 9, 3, 1))
assert_size_stride(primals_5, (32,), (1,))
assert_size_stride(primals_6, (64, 32, 7, 7), (1568, 49, 7, 1))
assert_size_stride(primals_7, (64,), (1,))
assert_size_stride(primals_8, (64, 64, 1, 1), (64, 1, 1, 1))
assert_size_stride(primals_9, (64,), (1,))
assert_size_stride(primals_10, (64, 32, 7, 7), (1568, 49, 7, 1))
assert_size_stride(primals_11, (32,), (1,))
assert_size_stride(primals_12, (32, 16, 3, 3), (144, 9, 3, 1))
assert_size_stride(primals_13, (16,), (1,))
assert_size_stride(primals_14, (16, 3, 3, 3), (27, 9, 3, 1))
assert_size_stride(primals_15, (3,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(2,
2), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 16, 32, 32), (16384, 1024, 32, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_relu_0[grid(65536)](buf1, primals_2,
65536, XBLOCK=256, num_warps=4, num_stages=1)
del primals_2
buf2 = extern_kernels.convolution(buf1, primals_4, stride=(2, 2),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 32, 16, 16), (8192, 256, 16, 1))
buf3 = buf2
del buf2
triton_poi_fused_convolution_relu_1[grid(32768)](buf3, primals_5,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_5
buf4 = extern_kernels.convolution(buf3, primals_6, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 64, 10, 10), (6400, 100, 10, 1))
buf5 = empty_strided_cuda((4, 64, 10, 10), (6400, 100, 10, 1),
torch.bool)
buf6 = empty_strided_cuda((4, 64, 10, 10), (6400, 100, 10, 1),
torch.float32)
triton_poi_fused_convolution_leaky_relu_2[grid(25600)](buf4,
primals_7, buf5, buf6, 25600, XBLOCK=128, num_warps=4, num_stages=1
)
del buf4
del primals_7
buf7 = extern_kernels.convolution(buf6, primals_8, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf7, (4, 64, 10, 10), (6400, 100, 10, 1))
buf8 = buf7
del buf7
triton_poi_fused_convolution_relu_3[grid(25600)](buf8, primals_9,
25600, XBLOCK=128, num_warps=4, num_stages=1)
del primals_9
buf9 = extern_kernels.convolution(buf8, primals_10, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=True,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf9, (4, 32, 16, 16), (8192, 256, 16, 1))
buf10 = buf9
del buf9
triton_poi_fused_convolution_relu_1[grid(32768)](buf10, primals_11,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_11
buf11 = extern_kernels.convolution(buf10, primals_12, stride=(2, 2),
padding=(1, 1), dilation=(1, 1), transposed=True,
output_padding=(1, 1), groups=1, bias=None)
assert_size_stride(buf11, (4, 16, 32, 32), (16384, 1024, 32, 1))
buf12 = buf11
del buf11
triton_poi_fused_convolution_relu_0[grid(65536)](buf12, primals_13,
65536, XBLOCK=256, num_warps=4, num_stages=1)
del primals_13
buf13 = extern_kernels.convolution(buf12, primals_14, stride=(2, 2),
padding=(1, 1), dilation=(1, 1), transposed=True,
output_padding=(1, 1), groups=1, bias=None)
assert_size_stride(buf13, (4, 3, 64, 64), (12288, 4096, 64, 1))
buf14 = empty_strided_cuda((4, 3, 64, 64), (12288, 4096, 64, 1),
torch.bool)
buf15 = empty_strided_cuda((4, 3, 64, 64), (12288, 4096, 64, 1),
torch.float32)
triton_poi_fused_convolution_leaky_relu_4[grid(49152)](buf13,
primals_15, buf14, buf15, 49152, XBLOCK=512, num_warps=4,
num_stages=1)
del buf13
del primals_15
return (buf15, primals_1, primals_3, primals_4, primals_6, primals_8,
primals_10, primals_12, primals_14, buf1, buf3, buf5, buf6, buf8,
buf10, buf12, buf14)
class State_AutoencoderNew(nn.Module):
def __init__(self, frame_stacks=1, channels=3):
super(State_AutoencoderNew, self).__init__()
self.encoder = nn.Sequential(OrderedDict([('encoder_conv1', nn.
Conv2d(channels * frame_stacks, 16, kernel_size=3, stride=2,
padding=1)), ('encoder_relu1', nn.ReLU()), ('encoder_conv2', nn
.Conv2d(16, 32, kernel_size=3, stride=2, padding=1)), (
'encoder_relu2', nn.ReLU()), ('encoder_conv3', nn.Conv2d(32, 64,
kernel_size=7)), ('encoder_relu3', nn.LeakyReLU())]))
self.bottleneck = nn.Sequential(OrderedDict([('bottleneck_conv1',
nn.Conv2d(64, 64, kernel_size=(1, 1))), ('bottleneck_relu1', nn
.ReLU())]))
self.decoder = nn.Sequential(OrderedDict([('decoder_Tconv1', nn.
ConvTranspose2d(64, 32, kernel_size=7)), ('decoder_relu1', nn.
ReLU()), ('decoder_Tconv2', nn.ConvTranspose2d(32, 16,
kernel_size=3, stride=2, padding=1, output_padding=1)), (
'decoder_relu2', nn.ReLU()), ('decoder_Tconv3', nn.
ConvTranspose2d(16, channels * frame_stacks, kernel_size=3,
stride=2, padding=1, output_padding=1)), ('decoder_relu3', nn.
LeakyReLU())]))
def forward(self, input_0):
primals_1 = self.encoder.encoder_conv1.weight
primals_2 = self.encoder.encoder_conv1.bias
primals_4 = self.encoder.encoder_conv2.weight
primals_5 = self.encoder.encoder_conv2.bias
primals_6 = self.encoder.encoder_conv3.weight
primals_7 = self.encoder.encoder_conv3.bias
primals_8 = self.bottleneck.bottleneck_conv1.weight
primals_9 = self.bottleneck.bottleneck_conv1.bias
primals_10 = self.decoder.decoder_Tconv1.weight
primals_11 = self.decoder.decoder_Tconv1.bias
primals_12 = self.decoder.decoder_Tconv2.weight
primals_13 = self.decoder.decoder_Tconv2.bias
primals_14 = self.decoder.decoder_Tconv3.weight
primals_15 = self.decoder.decoder_Tconv3.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11, primals_12, primals_13, primals_14,
primals_15])
return output[0]
|
Squishy123/GDE_net
|
State_Autoencoder
| false
| 17,951
|
[
"Apache-2.0"
] | 4
|
9094cbf58edbf0d62a2b2cd66743322597f66269
|
https://github.com/Squishy123/GDE_net/tree/9094cbf58edbf0d62a2b2cd66743322597f66269
|
SmallMnistNoDropout
|
import torch
import torch.nn as nn
import torch.nn
import torch.utils.data
import torch.utils.tensorboard._pytorch_graph
import torch.onnx.symbolic_caffe2
class SmallMnistNoDropout(nn.Module):
def __init__(self):
super(SmallMnistNoDropout, self).__init__()
self.conv1 = nn.Conv2d(1, 10, kernel_size=5)
self.relu1 = nn.ReLU()
self.conv2 = nn.Conv2d(10, 20, kernel_size=5)
self.relu2 = nn.ReLU()
self.fc1 = nn.Linear(320, 50)
self.relu3 = nn.ReLU()
self.fc2 = nn.Linear(50, 10)
self.log_softmax = nn.LogSoftmax(dim=1)
def forward(self, x):
x = self.relu1(self.conv1(x))
x = self.relu2(self.conv2(x))
x = x.view(-1, 320)
x = self.relu3(self.fc1(x))
x = self.fc2(x)
return self.log_softmax(x)
def get_inputs():
return [torch.rand([4, 1, 64, 64])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
import torch.nn
import torch.utils.data
import torch.utils.tensorboard._pytorch_graph
import torch.onnx.symbolic_caffe2
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 = 144000
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 3600 % 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_relu_threshold_backward_1(in_out_ptr0,
in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 250880
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x4 = xindex
x1 = xindex // 3136 % 20
x0 = xindex % 3136
x3 = xindex // 3136
tmp0 = tl.load(in_out_ptr0 + x4, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x4, tmp4, xmask)
tl.store(out_ptr0 + (x0 + 3200 * x3), tmp6, xmask)
@triton.jit
def triton_poi_fused_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 39200
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 50
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x2, tmp4, xmask)
@triton.jit
def triton_per_fused__log_softmax_3(in_ptr0, out_ptr2, xnumel, rnumel,
XBLOCK: tl.constexpr):
xnumel = 784
rnumel = 10
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
rmask = rindex < rnumel
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 10 * x0), rmask & xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(rmask & xmask, tmp1, float('-inf'))
tmp4 = triton_helpers.max2(tmp3, 1)[:, None]
tmp5 = tmp0 - tmp4
tmp6 = tl_math.exp(tmp5)
tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
tmp9 = tl.where(rmask & xmask, tmp7, 0)
tmp10 = tl.sum(tmp9, 1)[:, None]
tmp11 = tl_math.log(tmp10)
tmp12 = tmp5 - tmp11
tl.store(out_ptr2 + (r1 + 10 * x0), tmp12, rmask & xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9) = args
args.clear()
assert_size_stride(primals_1, (10, 1, 5, 5), (25, 25, 5, 1))
assert_size_stride(primals_2, (10,), (1,))
assert_size_stride(primals_3, (4, 1, 64, 64), (4096, 4096, 64, 1))
assert_size_stride(primals_4, (20, 10, 5, 5), (250, 25, 5, 1))
assert_size_stride(primals_5, (20,), (1,))
assert_size_stride(primals_6, (50, 320), (320, 1))
assert_size_stride(primals_7, (50,), (1,))
assert_size_stride(primals_8, (10, 50), (50, 1))
assert_size_stride(primals_9, (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, 10, 60, 60), (36000, 3600, 60, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_relu_0[grid(144000)](buf1, primals_2,
144000, 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, 20, 56, 56), (62720, 3136, 56, 1))
buf3 = buf2
del buf2
buf10 = empty_strided_cuda((4, 20, 56, 56), (64000, 3200, 56, 1),
torch.bool)
triton_poi_fused_convolution_relu_threshold_backward_1[grid(250880)](
buf3, primals_5, buf10, 250880, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_5
buf4 = empty_strided_cuda((784, 50), (50, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf3, (784, 320), (320, 1), 0),
reinterpret_tensor(primals_6, (320, 50), (1, 320), 0), out=buf4)
buf5 = buf4
del buf4
triton_poi_fused_relu_2[grid(39200)](buf5, primals_7, 39200, XBLOCK
=512, num_warps=4, num_stages=1)
del primals_7
buf6 = empty_strided_cuda((784, 10), (10, 1), torch.float32)
extern_kernels.addmm(primals_9, buf5, reinterpret_tensor(primals_8,
(50, 10), (1, 50), 0), alpha=1, beta=1, out=buf6)
del primals_9
buf9 = empty_strided_cuda((784, 10), (10, 1), torch.float32)
triton_per_fused__log_softmax_3[grid(784)](buf6, buf9, 784, 10,
XBLOCK=32, num_warps=4, num_stages=1)
del buf6
return buf9, primals_1, primals_3, primals_4, buf1, reinterpret_tensor(buf3
, (784, 320), (320, 1), 0), buf5, buf9, primals_8, primals_6, buf10
class SmallMnistNoDropoutNew(nn.Module):
def __init__(self):
super(SmallMnistNoDropoutNew, self).__init__()
self.conv1 = nn.Conv2d(1, 10, kernel_size=5)
self.relu1 = nn.ReLU()
self.conv2 = nn.Conv2d(10, 20, kernel_size=5)
self.relu2 = nn.ReLU()
self.fc1 = nn.Linear(320, 50)
self.relu3 = nn.ReLU()
self.fc2 = nn.Linear(50, 10)
self.log_softmax = nn.LogSoftmax(dim=1)
def forward(self, input_0):
primals_1 = self.conv1.weight
primals_2 = self.conv1.bias
primals_4 = self.conv2.weight
primals_5 = self.conv2.bias
primals_6 = self.fc1.weight
primals_7 = self.fc1.bias
primals_8 = self.fc2.weight
primals_9 = self.fc2.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9])
return output[0]
|
Rohan-Chaudhury/aimet
|
SmallMnistNoDropout
| false
| 17,952
|
[
"BSD-3-Clause"
] | 3
|
1c38cac8cc0fd32dca40ce5e39940805d29f7a4a
|
https://github.com/Rohan-Chaudhury/aimet/tree/1c38cac8cc0fd32dca40ce5e39940805d29f7a4a
|
SmallMnist
|
import torch
import torch.nn as nn
import torch.nn
import torch.utils.data
import torch.utils.tensorboard._pytorch_graph
import torch.onnx.symbolic_caffe2
class SmallMnist(nn.Module):
def __init__(self):
super(SmallMnist, self).__init__()
self.conv1 = nn.Conv2d(1, 10, kernel_size=5)
self.relu1 = nn.ReLU()
self.conv2 = nn.Conv2d(10, 20, kernel_size=5)
self.conv2_drop = nn.Dropout2d()
self.relu2 = nn.ReLU()
self.fc1 = nn.Linear(320, 50)
self.relu3 = nn.ReLU()
self.dropout = nn.Dropout()
self.fc2 = nn.Linear(50, 10)
self.log_softmax = nn.LogSoftmax(dim=1)
def forward(self, x):
x = self.relu1(self.conv1(x))
x = self.conv2(x)
x = self.relu2(self.conv2_drop(x))
x = x.view(-1, 320)
x = self.relu3(self.fc1(x))
x = self.dropout(x)
x = self.fc2(x)
return self.log_softmax(x)
def get_inputs():
return [torch.rand([4, 1, 64, 64])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
import torch.nn
import torch.utils.data
import torch.utils.tensorboard._pytorch_graph
import torch.onnx.symbolic_caffe2
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 = 144000
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 3600 % 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_relu_threshold_backward_1(in_out_ptr0,
in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 250880
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x4 = xindex
x1 = xindex // 3136 % 20
x0 = xindex % 3136
x3 = xindex // 3136
tmp0 = tl.load(in_out_ptr0 + x4, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x4, tmp4, xmask)
tl.store(out_ptr0 + (x0 + 3200 * x3), tmp6, xmask)
@triton.jit
def triton_poi_fused_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 39200
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 50
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x2, tmp4, xmask)
@triton.jit
def triton_per_fused__log_softmax_3(in_ptr0, out_ptr2, xnumel, rnumel,
XBLOCK: tl.constexpr):
xnumel = 784
rnumel = 10
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
rmask = rindex < rnumel
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 10 * x0), rmask & xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(rmask & xmask, tmp1, float('-inf'))
tmp4 = triton_helpers.max2(tmp3, 1)[:, None]
tmp5 = tmp0 - tmp4
tmp6 = tl_math.exp(tmp5)
tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
tmp9 = tl.where(rmask & xmask, tmp7, 0)
tmp10 = tl.sum(tmp9, 1)[:, None]
tmp11 = tl_math.log(tmp10)
tmp12 = tmp5 - tmp11
tl.store(out_ptr2 + (r1 + 10 * x0), tmp12, rmask & xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9) = args
args.clear()
assert_size_stride(primals_1, (10, 1, 5, 5), (25, 25, 5, 1))
assert_size_stride(primals_2, (10,), (1,))
assert_size_stride(primals_3, (4, 1, 64, 64), (4096, 4096, 64, 1))
assert_size_stride(primals_4, (20, 10, 5, 5), (250, 25, 5, 1))
assert_size_stride(primals_5, (20,), (1,))
assert_size_stride(primals_6, (50, 320), (320, 1))
assert_size_stride(primals_7, (50,), (1,))
assert_size_stride(primals_8, (10, 50), (50, 1))
assert_size_stride(primals_9, (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, 10, 60, 60), (36000, 3600, 60, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_relu_0[grid(144000)](buf1, primals_2,
144000, 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, 20, 56, 56), (62720, 3136, 56, 1))
buf3 = buf2
del buf2
buf10 = empty_strided_cuda((4, 20, 56, 56), (64000, 3200, 56, 1),
torch.bool)
triton_poi_fused_convolution_relu_threshold_backward_1[grid(250880)](
buf3, primals_5, buf10, 250880, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_5
buf4 = empty_strided_cuda((784, 50), (50, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf3, (784, 320), (320, 1), 0),
reinterpret_tensor(primals_6, (320, 50), (1, 320), 0), out=buf4)
buf5 = buf4
del buf4
triton_poi_fused_relu_2[grid(39200)](buf5, primals_7, 39200, XBLOCK
=512, num_warps=4, num_stages=1)
del primals_7
buf6 = empty_strided_cuda((784, 10), (10, 1), torch.float32)
extern_kernels.addmm(primals_9, buf5, reinterpret_tensor(primals_8,
(50, 10), (1, 50), 0), alpha=1, beta=1, out=buf6)
del primals_9
buf9 = empty_strided_cuda((784, 10), (10, 1), torch.float32)
triton_per_fused__log_softmax_3[grid(784)](buf6, buf9, 784, 10,
XBLOCK=32, num_warps=4, num_stages=1)
del buf6
return buf9, primals_1, primals_3, primals_4, buf1, reinterpret_tensor(buf3
, (784, 320), (320, 1), 0), buf5, buf9, primals_8, primals_6, buf10
class SmallMnistNew(nn.Module):
def __init__(self):
super(SmallMnistNew, self).__init__()
self.conv1 = nn.Conv2d(1, 10, kernel_size=5)
self.relu1 = nn.ReLU()
self.conv2 = nn.Conv2d(10, 20, kernel_size=5)
self.conv2_drop = nn.Dropout2d()
self.relu2 = nn.ReLU()
self.fc1 = nn.Linear(320, 50)
self.relu3 = nn.ReLU()
self.dropout = nn.Dropout()
self.fc2 = nn.Linear(50, 10)
self.log_softmax = nn.LogSoftmax(dim=1)
def forward(self, input_0):
primals_1 = self.conv1.weight
primals_2 = self.conv1.bias
primals_4 = self.conv2.weight
primals_5 = self.conv2.bias
primals_6 = self.fc1.weight
primals_7 = self.fc1.bias
primals_8 = self.fc2.weight
primals_9 = self.fc2.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9])
return output[0]
|
Rohan-Chaudhury/aimet
|
SmallMnist
| false
| 17,953
|
[
"BSD-3-Clause"
] | 3
|
1c38cac8cc0fd32dca40ce5e39940805d29f7a4a
|
https://github.com/Rohan-Chaudhury/aimet/tree/1c38cac8cc0fd32dca40ce5e39940805d29f7a4a
|
SingleBlock
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class FCNet(nn.Module):
def __init__(self, in_size, out_size, activate=None, drop=0.0):
super(FCNet, self).__init__()
self.lin = nn.Linear(in_size, out_size)
self.drop_value = drop
self.drop = nn.Dropout(drop)
self.activate = activate.lower() if activate is not None else None
if activate == 'relu':
self.ac_fn = nn.ReLU()
elif activate == 'sigmoid':
self.ac_fn = nn.Sigmoid()
elif activate == 'tanh':
self.ac_fn = nn.Tanh()
def forward(self, x):
if self.drop_value > 0:
x = self.drop(x)
x = self.lin(x)
if self.activate is not None:
x = self.ac_fn(x)
return x
class OneSideInterModalityUpdate(nn.Module):
"""
one-side Inter-Modality Attention Flow
according to the paper, instead of parallel V->Q & Q->V, we first to V->Q and then Q->V
"""
def __init__(self, src_size, tgt_size, output_size, num_head, drop=0.0):
super(OneSideInterModalityUpdate, self).__init__()
self.src_size = src_size
self.tgt_size = tgt_size
self.output_size = output_size
self.num_head = num_head
self.src_lin = FCNet(src_size, output_size * 2, drop=drop, activate
='relu')
self.tgt_lin = FCNet(tgt_size, output_size, drop=drop, activate='relu')
self.tgt_output = FCNet(output_size + tgt_size, output_size, drop=
drop, activate='relu')
def forward(self, src, tgt):
"""
:param src: eeg feature [batch, regions, feature_size]
:param tgt: eye feature [batch, regions, feature_size]
:return:
"""
_batch_size, _num_src = src.shape[0], src.shape[1]
tgt.shape[1]
src_tran = self.src_lin(src)
tgt_tran = self.tgt_lin(tgt)
src_key, src_val = torch.split(src_tran, src_tran.size(2) // 2, dim=2)
tgt_query = tgt_tran
src_key_set = torch.split(src_key, src_key.size(2) // self.num_head,
dim=2)
src_val_set = torch.split(src_val, src_val.size(2) // self.num_head,
dim=2)
tgt_query_set = torch.split(tgt_query, tgt_query.size(2) // self.
num_head, dim=2)
for i in range(self.num_head):
src_key_slice, tgt_query_slice, src_val_slice = src_key_set[i
], tgt_query_set[i], src_val_set[i]
src2tgt = tgt_query_slice @ src_key_slice.transpose(1, 2) / (self
.output_size // self.num_head) ** 0.5
interMAF_src2tgt = F.softmax(src2tgt, dim=2).unsqueeze(3)
tgt_update = (interMAF_src2tgt * src_val_slice.unsqueeze(1)).sum(2
) if i == 0 else torch.cat((tgt_update, (interMAF_src2tgt *
src_val_slice.unsqueeze(1)).sum(2)), dim=2)
cat_tgt = torch.cat((tgt, tgt_update), dim=2)
tgt_updated = self.tgt_output(cat_tgt)
return tgt_updated
class DyIntraModalityUpdate(nn.Module):
"""
Dynamic Intra-Modality Attention Flow
"""
def __init__(self, v_size, q_size, output_size, num_head, drop=0.0):
super(DyIntraModalityUpdate, self).__init__()
self.v_size = v_size
self.q_size = q_size
self.output_size = output_size
self.num_head = num_head
self.v4q_gate_lin = FCNet(v_size, output_size, drop=drop)
self.q4v_gate_lin = FCNet(q_size, output_size, drop=drop)
self.v_lin = FCNet(v_size, output_size * 3, drop=drop, activate='relu')
self.q_lin = FCNet(q_size, output_size * 3, drop=drop, activate='relu')
self.v_output = FCNet(output_size, output_size, drop=drop, activate
='relu')
self.q_output = FCNet(output_size, output_size, drop=drop, activate
='relu')
self.relu = nn.ReLU()
self.tanh = nn.Tanh()
self.sigmoid = nn.Sigmoid()
def forward(self, v, q):
"""
:param v: [batch_size, num_obj, feature_size]
:param q: [batch_size, max_len, feature_size]
:return:
"""
_batch_size, num_obj = v.shape[0], v.shape[1]
max_len = q.shape[1]
v_mean = v.sum(1) / num_obj
q_mean = q.sum(1) / max_len
v4q_gate = self.sigmoid(self.v4q_gate_lin(v_mean)).unsqueeze(1)
q4v_gate = self.sigmoid(self.q4v_gate_lin(q_mean)).unsqueeze(1)
v_tran = self.v_lin(v)
q_tran = self.q_lin(q)
v_key, v_query, v_val = torch.split(v_tran, v_tran.size(2) // 3, dim=2)
q_key, q_query, q_val = torch.split(q_tran, q_tran.size(2) // 3, dim=2)
gated_v_query = (1 + q4v_gate) * v_query
gated_v_key = (1 + q4v_gate) * v_key
gated_v_val = (1 + q4v_gate) * v_val
gated_q_query = (1 + v4q_gate) * q_query
gated_q_key = (1 + v4q_gate) * q_key
gated_q_val = (1 + v4q_gate) * q_val
v_key_set = torch.split(gated_v_key, gated_v_key.size(2) // self.
num_head, dim=2)
v_query_set = torch.split(gated_v_query, gated_v_query.size(2) //
self.num_head, dim=2)
v_val_set = torch.split(gated_v_val, gated_v_val.size(2) // self.
num_head, dim=2)
q_key_set = torch.split(gated_q_key, gated_q_key.size(2) // self.
num_head, dim=2)
q_query_set = torch.split(gated_q_query, gated_q_query.size(2) //
self.num_head, dim=2)
q_val_set = torch.split(gated_q_val, gated_q_val.size(2) // self.
num_head, dim=2)
for i in range(self.num_head):
v_key_slice, v_query_slice, v_val_slice = v_key_set[i
], v_query_set[i], v_val_set[i]
q_key_slice, q_query_slice, q_val_slice = q_key_set[i
], q_query_set[i], q_val_set[i]
v2v = v_query_slice @ v_key_slice.transpose(1, 2) / (self.
output_size // self.num_head) ** 0.5
q2q = q_query_slice @ q_key_slice.transpose(1, 2) / (self.
output_size // self.num_head) ** 0.5
dyIntranMAF_v2v = F.softmax(v2v, dim=2).unsqueeze(3)
dyIntranMAF_q2q = F.softmax(q2q, dim=2).unsqueeze(3)
v_update = (dyIntranMAF_v2v * v_val_slice.unsqueeze(1)).sum(2
) if i == 0 else torch.cat((v_update, (dyIntranMAF_v2v *
v_val_slice.unsqueeze(1)).sum(2)), dim=2)
q_update = (dyIntranMAF_q2q * q_val_slice.unsqueeze(1)).sum(2
) if i == 0 else torch.cat((q_update, (dyIntranMAF_q2q *
q_val_slice.unsqueeze(1)).sum(2)), dim=2)
updated_v = self.v_output(v + v_update)
updated_q = self.q_output(q + q_update)
return updated_v, updated_q
class SingleBlock(nn.Module):
"""
Single Block Inter- and Intra modality stack multiple times, in such circumstance, all the
basic blocks share the same parameters in the model
"""
def __init__(self, num_blocks, v_size, q_size, output_size,
num_inter_head, num_intra_head, drop=0.0):
super(SingleBlock, self).__init__()
self.v_size = v_size
self.q_size = q_size
self.output_size = output_size
self.num_inter_head = num_inter_head
self.num_intra_head = num_intra_head
self.num_block = num_blocks
self.v_lin = FCNet(v_size, output_size, drop=drop, activate='relu')
self.q_lin = FCNet(q_size, output_size, drop=drop, activate='relu')
self.v2q_interBlock = OneSideInterModalityUpdate(output_size,
output_size, output_size, num_inter_head, drop)
self.q2v_interBlock = OneSideInterModalityUpdate(output_size,
output_size, output_size, num_inter_head, drop)
self.intraBlock = DyIntraModalityUpdate(output_size, output_size,
output_size, num_intra_head, drop)
def forward(self, v, q):
"""
:param v: eeg feature [batch_size, regions, feature_size]
:param q: eye feature [batch_size, regions, feature_size]
:return:
"""
v = self.v_lin(v)
q = self.q_lin(q)
v_container = [v]
q_container = [q]
result_v = [v]
result_q = [q]
for i in range(self.num_block):
q1 = self.v2q_interBlock(v_container[-1], q_container[-1])
q_container.append(q1)
v1 = self.q2v_interBlock(q_container[-1], v_container[-1])
v_container.append(v1)
v2, q2 = self.intraBlock(v_container[-1] + v_container[-2],
q_container[-1] + q_container[-2])
v_container.append(v2)
q_container.append(q2)
result_v.append(v1)
result_v.append(v2)
result_q.append(q1)
result_q.append(q2)
v_container.append(v_container[-1] + v_container[-2] +
v_container[-3])
q_container.append(q_container[-1] + q_container[-2] +
q_container[-3])
return sum(result_v), sum(result_q)
def get_inputs():
return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'num_blocks': 4, 'v_size': 4, 'q_size': 4, 'output_size':
4, 'num_inter_head': 4, 'num_intra_head': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
import torch.nn.functional as F
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_relu_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
x1 = xindex // 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x2, tmp4, xmask)
tl.store(out_ptr0 + (x0 + 8 * x1), tmp4, xmask)
@triton.jit
def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x2, tmp4, xmask)
tl.store(out_ptr0 + x2, tmp6, xmask)
@triton.jit
def triton_poi_fused_relu_threshold_backward_2(in_out_ptr0, in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 8
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x2, tmp4, xmask)
tl.store(out_ptr0 + x2, tmp6, xmask)
@triton.jit
def triton_poi_fused_bmm_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
tl.store(out_ptr0 + x0, tmp0, xmask)
@triton.jit
def triton_poi_fused_bmm_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 8 * x0, xmask, eviction_policy='evict_last')
tl.store(out_ptr0 + x0, tmp0, xmask)
@triton.jit
def triton_poi_fused__softmax_5(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp3 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last'
)
tmp1 = 1.0
tmp2 = tmp0 * tmp1
tmp4 = tmp3 * tmp1
tmp6 = tmp5 * tmp1
tmp7 = triton_helpers.maximum(tmp4, tmp6)
tmp9 = tmp8 * tmp1
tmp10 = triton_helpers.maximum(tmp7, tmp9)
tmp12 = tmp11 * tmp1
tmp13 = triton_helpers.maximum(tmp10, tmp12)
tmp14 = tmp2 - tmp13
tmp15 = tmp14 * tmp1
tmp16 = tl_math.exp(tmp15)
tl.store(out_ptr0 + x2, tmp16, xmask)
@triton.jit
def triton_poi_fused_bmm_6(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tl.store(out_ptr0 + x0, tmp0, xmask)
@triton.jit
def triton_poi_fused_bmm_7(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + (1 + 8 * x0), xmask, eviction_policy='evict_last')
tl.store(out_ptr0 + x0, tmp0, xmask)
@triton.jit
def triton_poi_fused_cat_8(in_ptr0, in_ptr1, in_ptr2, 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 % 2
x3 = xindex // 2
x2 = xindex // 8
x5 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 1, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + 4 * x3, tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tl.load(in_ptr0 + (1 + 4 * x3), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp7 = tmp5 + tmp6
tmp8 = tl.load(in_ptr0 + (2 + 4 * x3), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp9 = tmp7 + tmp8
tmp10 = tl.load(in_ptr0 + (3 + 4 * x3), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp11 = tmp9 + tmp10
tmp12 = tmp5 / tmp11
tmp13 = tl.load(in_ptr1 + (4 + 32 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp14 = tmp12 * tmp13
tmp15 = tmp6 / tmp11
tmp16 = tl.load(in_ptr1 + (12 + 32 * x2), tmp4 & xmask, eviction_policy
='evict_last', other=0.0)
tmp17 = tmp15 * tmp16
tmp18 = tmp14 + tmp17
tmp19 = tmp8 / tmp11
tmp20 = tl.load(in_ptr1 + (20 + 32 * x2), tmp4 & xmask, eviction_policy
='evict_last', other=0.0)
tmp21 = tmp19 * tmp20
tmp22 = tmp18 + tmp21
tmp23 = tmp10 / tmp11
tmp24 = tl.load(in_ptr1 + (28 + 32 * x2), tmp4 & xmask, eviction_policy
='evict_last', other=0.0)
tmp25 = tmp23 * tmp24
tmp26 = tmp22 + tmp25
tmp27 = tl.full(tmp26.shape, 0.0, tmp26.dtype)
tmp28 = tl.where(tmp4, tmp26, tmp27)
tmp29 = tmp0 >= tmp3
tl.full([1], 2, tl.int64)
tmp32 = tl.load(in_ptr2 + 4 * x3, tmp29 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp33 = tl.load(in_ptr2 + (1 + 4 * x3), tmp29 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp34 = tmp32 + tmp33
tmp35 = tl.load(in_ptr2 + (2 + 4 * x3), tmp29 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp36 = tmp34 + tmp35
tmp37 = tl.load(in_ptr2 + (3 + 4 * x3), tmp29 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp38 = tmp36 + tmp37
tmp39 = tmp32 / tmp38
tmp40 = tl.load(in_ptr1 + (5 + 32 * x2), tmp29 & xmask, eviction_policy
='evict_last', other=0.0)
tmp41 = tmp39 * tmp40
tmp42 = tmp33 / tmp38
tmp43 = tl.load(in_ptr1 + (13 + 32 * x2), tmp29 & xmask,
eviction_policy='evict_last', other=0.0)
tmp44 = tmp42 * tmp43
tmp45 = tmp41 + tmp44
tmp46 = tmp35 / tmp38
tmp47 = tl.load(in_ptr1 + (21 + 32 * x2), tmp29 & xmask,
eviction_policy='evict_last', other=0.0)
tmp48 = tmp46 * tmp47
tmp49 = tmp45 + tmp48
tmp50 = tmp37 / tmp38
tmp51 = tl.load(in_ptr1 + (29 + 32 * x2), tmp29 & xmask,
eviction_policy='evict_last', other=0.0)
tmp52 = tmp50 * tmp51
tmp53 = tmp49 + tmp52
tmp54 = tl.full(tmp53.shape, 0.0, tmp53.dtype)
tmp55 = tl.where(tmp29, tmp53, tmp54)
tmp56 = tl.where(tmp4, tmp28, tmp55)
tl.store(out_ptr0 + x5, tmp56, xmask)
@triton.jit
def triton_poi_fused_bmm_9(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
tl.store(out_ptr0 + x0, tmp0, xmask)
@triton.jit
def triton_poi_fused_bmm_10(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + (2 + 8 * x0), xmask, eviction_policy='evict_last')
tl.store(out_ptr0 + x0, tmp0, xmask)
@triton.jit
def triton_poi_fused_cat_11(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 48
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 3
x3 = xindex // 3
x2 = xindex // 12
x5 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 2, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (2 * x3 + x0), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 3, tl.int64)
tmp9 = tl.load(in_ptr1 + 4 * x3, tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp10 = tl.load(in_ptr1 + (1 + 4 * x3), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp11 = tmp9 + tmp10
tmp12 = tl.load(in_ptr1 + (2 + 4 * x3), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp13 = tmp11 + tmp12
tmp14 = tl.load(in_ptr1 + (3 + 4 * x3), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp15 = tmp13 + tmp14
tmp16 = tmp9 / tmp15
tmp17 = tl.load(in_ptr2 + (6 + 32 * x2), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp18 = tmp16 * tmp17
tmp19 = tmp10 / tmp15
tmp20 = tl.load(in_ptr2 + (14 + 32 * x2), tmp6 & xmask, eviction_policy
='evict_last', other=0.0)
tmp21 = tmp19 * tmp20
tmp22 = tmp18 + tmp21
tmp23 = tmp12 / tmp15
tmp24 = tl.load(in_ptr2 + (22 + 32 * x2), tmp6 & xmask, eviction_policy
='evict_last', other=0.0)
tmp25 = tmp23 * tmp24
tmp26 = tmp22 + tmp25
tmp27 = tmp14 / tmp15
tmp28 = tl.load(in_ptr2 + (30 + 32 * x2), tmp6 & xmask, eviction_policy
='evict_last', other=0.0)
tmp29 = tmp27 * tmp28
tmp30 = tmp26 + tmp29
tmp31 = tl.full(tmp30.shape, 0.0, tmp30.dtype)
tmp32 = tl.where(tmp6, tmp30, tmp31)
tmp33 = tl.where(tmp4, tmp5, tmp32)
tl.store(out_ptr0 + x5, tmp33, xmask)
@triton.jit
def triton_poi_fused_bmm_12(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
tl.store(out_ptr0 + x0, tmp0, xmask)
@triton.jit
def triton_poi_fused_bmm_13(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + (3 + 8 * x0), xmask, eviction_policy='evict_last')
tl.store(out_ptr0 + x0, tmp0, xmask)
@triton.jit
def triton_poi_fused_cat_14(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x3 = xindex // 4
x2 = xindex // 16
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 3, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (3 * x3 + x0), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 4, tl.int64)
tmp9 = tl.load(in_ptr1 + 4 * x3, tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp10 = tl.load(in_ptr1 + (1 + 4 * x3), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp11 = tmp9 + tmp10
tmp12 = tl.load(in_ptr1 + (2 + 4 * x3), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp13 = tmp11 + tmp12
tmp14 = tl.load(in_ptr1 + (3 + 4 * x3), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp15 = tmp13 + tmp14
tmp16 = tmp9 / tmp15
tmp17 = tl.load(in_ptr2 + (7 + 32 * x2), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp18 = tmp16 * tmp17
tmp19 = tmp10 / tmp15
tmp20 = tl.load(in_ptr2 + (15 + 32 * x2), tmp6 & xmask, eviction_policy
='evict_last', other=0.0)
tmp21 = tmp19 * tmp20
tmp22 = tmp18 + tmp21
tmp23 = tmp12 / tmp15
tmp24 = tl.load(in_ptr2 + (23 + 32 * x2), tmp6 & xmask, eviction_policy
='evict_last', other=0.0)
tmp25 = tmp23 * tmp24
tmp26 = tmp22 + tmp25
tmp27 = tmp14 / tmp15
tmp28 = tl.load(in_ptr2 + (31 + 32 * x2), tmp6 & xmask, eviction_policy
='evict_last', other=0.0)
tmp29 = tmp27 * tmp28
tmp30 = tmp26 + tmp29
tmp31 = tl.full(tmp30.shape, 0.0, tmp30.dtype)
tmp32 = tl.where(tmp6, tmp30, tmp31)
tmp33 = tl.where(tmp4, tmp5, tmp32)
tl.store(out_ptr0 + (x0 + 8 * x3), tmp33, xmask)
@triton.jit
def triton_poi_fused_add_relu_15(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + x2, xmask)
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = tmp4 + tmp5
tl.store(in_out_ptr0 + x2, tmp4, xmask)
tl.store(out_ptr0 + x2, tmp6, xmask)
@triton.jit
def triton_poi_fused_add_div_relu_sum_16(in_out_ptr0, in_ptr0, in_ptr1,
in_ptr2, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 16 * x1), xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr2 + (x0 + 16 * x1), xmask)
tmp7 = tl.load(in_ptr0 + (4 + x0 + 16 * x1), xmask)
tmp10 = tl.load(in_ptr2 + (4 + x0 + 16 * x1), xmask)
tmp13 = tl.load(in_ptr0 + (8 + x0 + 16 * x1), xmask)
tmp16 = tl.load(in_ptr2 + (8 + x0 + 16 * x1), xmask)
tmp19 = tl.load(in_ptr0 + (12 + x0 + 16 * x1), xmask)
tmp22 = tl.load(in_ptr2 + (12 + x0 + 16 * x1), xmask)
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = tmp4 + tmp5
tmp8 = tmp7 + tmp1
tmp9 = triton_helpers.maximum(tmp3, tmp8)
tmp11 = tmp9 + tmp10
tmp12 = tmp6 + tmp11
tmp14 = tmp13 + tmp1
tmp15 = triton_helpers.maximum(tmp3, tmp14)
tmp17 = tmp15 + tmp16
tmp18 = tmp12 + tmp17
tmp20 = tmp19 + tmp1
tmp21 = triton_helpers.maximum(tmp3, tmp20)
tmp23 = tmp21 + tmp22
tmp24 = tmp18 + tmp23
tmp25 = 0.25
tmp26 = tmp24 * tmp25
tl.store(in_out_ptr0 + x2, tmp26, xmask)
@triton.jit
def triton_poi_fused_add_div_sum_17(in_ptr0, in_ptr1, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 16 * x1), xmask)
tmp1 = tl.load(in_ptr1 + (x0 + 16 * x1), xmask)
tmp3 = tl.load(in_ptr0 + (4 + x0 + 16 * x1), xmask)
tmp4 = tl.load(in_ptr1 + (4 + x0 + 16 * x1), xmask)
tmp7 = tl.load(in_ptr0 + (8 + x0 + 16 * x1), xmask)
tmp8 = tl.load(in_ptr1 + (8 + x0 + 16 * x1), xmask)
tmp11 = tl.load(in_ptr0 + (12 + x0 + 16 * x1), xmask)
tmp12 = tl.load(in_ptr1 + (12 + x0 + 16 * x1), xmask)
tmp2 = tmp0 + tmp1
tmp5 = tmp3 + tmp4
tmp6 = tmp2 + tmp5
tmp9 = tmp7 + tmp8
tmp10 = tmp6 + tmp9
tmp13 = tmp11 + tmp12
tmp14 = tmp10 + tmp13
tmp15 = 0.25
tmp16 = tmp14 * tmp15
tl.store(out_ptr0 + x2, tmp16, xmask)
@triton.jit
def triton_poi_fused_add_relu_18(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr2 + x2, xmask)
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = tmp4 + tmp5
tl.store(out_ptr0 + x2, tmp6, xmask)
@triton.jit
def triton_poi_fused_relu_threshold_backward_19(in_out_ptr0, in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 192
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 12
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x2, tmp4, xmask)
tl.store(out_ptr0 + x2, tmp6, xmask)
@triton.jit
def triton_poi_fused_add_mul_20(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
out_ptr2, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x2 = xindex // 16
x3 = xindex // 4
x4 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2), xmask, eviction_policy='evict_last'
)
tmp4 = tl.load(in_ptr1 + (4 + x0 + 12 * x3), xmask)
tmp6 = tl.load(in_ptr1 + (x0 + 12 * x3), xmask)
tmp8 = tl.load(in_ptr1 + (8 + x0 + 12 * x3), xmask)
tmp1 = tl.sigmoid(tmp0)
tmp2 = 1.0
tmp3 = tmp1 + tmp2
tmp5 = tmp3 * tmp4
tmp7 = tmp3 * tmp6
tmp9 = tmp3 * tmp8
tl.store(out_ptr0 + x4, tmp5, xmask)
tl.store(out_ptr1 + x4, tmp7, xmask)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_cat_21(in_ptr0, in_ptr1, in_ptr2, 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 % 2
x3 = xindex // 2
x2 = xindex // 8
x5 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 1, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + 4 * x3, tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tl.load(in_ptr0 + (1 + 4 * x3), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp7 = tmp5 + tmp6
tmp8 = tl.load(in_ptr0 + (2 + 4 * x3), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp9 = tmp7 + tmp8
tmp10 = tl.load(in_ptr0 + (3 + 4 * x3), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp11 = tmp9 + tmp10
tmp12 = tmp5 / tmp11
tmp13 = tl.load(in_ptr1 + 16 * x2, tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp14 = tmp12 * tmp13
tmp15 = tmp6 / tmp11
tmp16 = tl.load(in_ptr1 + (4 + 16 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp17 = tmp15 * tmp16
tmp18 = tmp14 + tmp17
tmp19 = tmp8 / tmp11
tmp20 = tl.load(in_ptr1 + (8 + 16 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp21 = tmp19 * tmp20
tmp22 = tmp18 + tmp21
tmp23 = tmp10 / tmp11
tmp24 = tl.load(in_ptr1 + (12 + 16 * x2), tmp4 & xmask, eviction_policy
='evict_last', other=0.0)
tmp25 = tmp23 * tmp24
tmp26 = tmp22 + tmp25
tmp27 = tl.full(tmp26.shape, 0.0, tmp26.dtype)
tmp28 = tl.where(tmp4, tmp26, tmp27)
tmp29 = tmp0 >= tmp3
tl.full([1], 2, tl.int64)
tmp32 = tl.load(in_ptr2 + 4 * x3, tmp29 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp33 = tl.load(in_ptr2 + (1 + 4 * x3), tmp29 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp34 = tmp32 + tmp33
tmp35 = tl.load(in_ptr2 + (2 + 4 * x3), tmp29 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp36 = tmp34 + tmp35
tmp37 = tl.load(in_ptr2 + (3 + 4 * x3), tmp29 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp38 = tmp36 + tmp37
tmp39 = tmp32 / tmp38
tmp40 = tl.load(in_ptr1 + (1 + 16 * x2), tmp29 & xmask, eviction_policy
='evict_last', other=0.0)
tmp41 = tmp39 * tmp40
tmp42 = tmp33 / tmp38
tmp43 = tl.load(in_ptr1 + (5 + 16 * x2), tmp29 & xmask, eviction_policy
='evict_last', other=0.0)
tmp44 = tmp42 * tmp43
tmp45 = tmp41 + tmp44
tmp46 = tmp35 / tmp38
tmp47 = tl.load(in_ptr1 + (9 + 16 * x2), tmp29 & xmask, eviction_policy
='evict_last', other=0.0)
tmp48 = tmp46 * tmp47
tmp49 = tmp45 + tmp48
tmp50 = tmp37 / tmp38
tmp51 = tl.load(in_ptr1 + (13 + 16 * x2), tmp29 & xmask,
eviction_policy='evict_last', other=0.0)
tmp52 = tmp50 * tmp51
tmp53 = tmp49 + tmp52
tmp54 = tl.full(tmp53.shape, 0.0, tmp53.dtype)
tmp55 = tl.where(tmp29, tmp53, tmp54)
tmp56 = tl.where(tmp4, tmp28, tmp55)
tl.store(out_ptr0 + x5, tmp56, xmask)
@triton.jit
def triton_poi_fused_cat_22(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 48
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 3
x3 = xindex // 3
x2 = xindex // 12
x5 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 2, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (2 * x3 + x0), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 3, tl.int64)
tmp9 = tl.load(in_ptr1 + 4 * x3, tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp10 = tl.load(in_ptr1 + (1 + 4 * x3), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp11 = tmp9 + tmp10
tmp12 = tl.load(in_ptr1 + (2 + 4 * x3), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp13 = tmp11 + tmp12
tmp14 = tl.load(in_ptr1 + (3 + 4 * x3), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp15 = tmp13 + tmp14
tmp16 = tmp9 / tmp15
tmp17 = tl.load(in_ptr2 + (2 + 16 * x2), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp18 = tmp16 * tmp17
tmp19 = tmp10 / tmp15
tmp20 = tl.load(in_ptr2 + (6 + 16 * x2), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp21 = tmp19 * tmp20
tmp22 = tmp18 + tmp21
tmp23 = tmp12 / tmp15
tmp24 = tl.load(in_ptr2 + (10 + 16 * x2), tmp6 & xmask, eviction_policy
='evict_last', other=0.0)
tmp25 = tmp23 * tmp24
tmp26 = tmp22 + tmp25
tmp27 = tmp14 / tmp15
tmp28 = tl.load(in_ptr2 + (14 + 16 * x2), tmp6 & xmask, eviction_policy
='evict_last', other=0.0)
tmp29 = tmp27 * tmp28
tmp30 = tmp26 + tmp29
tmp31 = tl.full(tmp30.shape, 0.0, tmp30.dtype)
tmp32 = tl.where(tmp6, tmp30, tmp31)
tmp33 = tl.where(tmp4, tmp5, tmp32)
tl.store(out_ptr0 + x5, tmp33, xmask)
@triton.jit
def triton_poi_fused_add_cat_23(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2,
in_ptr3, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x4 = xindex // 4
x2 = xindex // 16
x3 = xindex
tmp34 = tl.load(in_ptr3 + x3, xmask)
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 3, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (3 * x4 + x0), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 4, tl.int64)
tmp9 = tl.load(in_ptr1 + 4 * x4, tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp10 = tl.load(in_ptr1 + (1 + 4 * x4), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp11 = tmp9 + tmp10
tmp12 = tl.load(in_ptr1 + (2 + 4 * x4), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp13 = tmp11 + tmp12
tmp14 = tl.load(in_ptr1 + (3 + 4 * x4), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp15 = tmp13 + tmp14
tmp16 = tmp9 / tmp15
tmp17 = tl.load(in_ptr2 + (3 + 16 * x2), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp18 = tmp16 * tmp17
tmp19 = tmp10 / tmp15
tmp20 = tl.load(in_ptr2 + (7 + 16 * x2), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp21 = tmp19 * tmp20
tmp22 = tmp18 + tmp21
tmp23 = tmp12 / tmp15
tmp24 = tl.load(in_ptr2 + (11 + 16 * x2), tmp6 & xmask, eviction_policy
='evict_last', other=0.0)
tmp25 = tmp23 * tmp24
tmp26 = tmp22 + tmp25
tmp27 = tmp14 / tmp15
tmp28 = tl.load(in_ptr2 + (15 + 16 * x2), tmp6 & xmask, eviction_policy
='evict_last', other=0.0)
tmp29 = tmp27 * tmp28
tmp30 = tmp26 + tmp29
tmp31 = tl.full(tmp30.shape, 0.0, tmp30.dtype)
tmp32 = tl.where(tmp6, tmp30, tmp31)
tmp33 = tl.where(tmp4, tmp5, tmp32)
tmp35 = tmp34 + tmp33
tl.store(in_out_ptr0 + x3, tmp35, xmask)
@triton.jit
def triton_poi_fused_add_cat_relu_24(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
in_ptr4, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr2 + x2, xmask)
tmp6 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr4 + x2, xmask)
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp7 = tmp5 + tmp6
tmp8 = triton_helpers.maximum(tmp3, tmp7)
tmp9 = tmp4 + tmp8
tmp11 = tmp9 + tmp10
tl.store(out_ptr0 + x2, tmp11, xmask)
tl.store(out_ptr1 + (x0 + 8 * x1), tmp11, xmask)
@triton.jit
def triton_poi_fused_add_cat_relu_25(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr2 + x2, xmask)
tmp7 = tl.load(in_ptr3 + x2, xmask)
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = tmp4 + tmp5
tmp8 = tmp6 + tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
tl.store(out_ptr1 + (x0 + 8 * x1), tmp8, xmask)
@triton.jit
def triton_poi_fused_add_relu_threshold_backward_26(in_out_ptr0, in_ptr0,
in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8,
in_ptr9, in_ptr10, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4,
out_ptr5, out_ptr6, out_ptr7, out_ptr8, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp3 = tl.load(in_ptr1 + x2, xmask)
tmp4 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr3 + x2, xmask)
tmp10 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
tmp14 = tl.load(in_ptr5 + x2, xmask)
tmp18 = tl.load(in_ptr6 + x2, xmask)
tmp22 = tl.load(in_ptr7 + x2, xmask)
tmp26 = tl.load(in_ptr8 + x2, xmask)
tmp30 = tl.load(in_ptr9 + x2, xmask)
tmp34 = tl.load(in_ptr10 + x2, xmask)
tmp1 = 0.0
tmp2 = tmp0 + tmp1
tmp5 = tmp3 + tmp4
tmp6 = tl.full([1], 0, tl.int32)
tmp7 = triton_helpers.maximum(tmp6, tmp5)
tmp8 = tmp2 + tmp7
tmp11 = tmp9 + tmp10
tmp12 = triton_helpers.maximum(tmp6, tmp11)
tmp13 = tmp8 + tmp12
tmp15 = tmp14 + tmp4
tmp16 = triton_helpers.maximum(tmp6, tmp15)
tmp17 = tmp13 + tmp16
tmp19 = tmp18 + tmp10
tmp20 = triton_helpers.maximum(tmp6, tmp19)
tmp21 = tmp17 + tmp20
tmp23 = tmp22 + tmp4
tmp24 = triton_helpers.maximum(tmp6, tmp23)
tmp25 = tmp21 + tmp24
tmp27 = tmp26 + tmp10
tmp28 = triton_helpers.maximum(tmp6, tmp27)
tmp29 = tmp25 + tmp28
tmp31 = tmp30 + tmp4
tmp32 = triton_helpers.maximum(tmp6, tmp31)
tmp33 = tmp29 + tmp32
tmp35 = tmp34 + tmp10
tmp36 = triton_helpers.maximum(tmp6, tmp35)
tmp37 = tmp33 + tmp36
tmp38 = tmp36 <= tmp1
tmp39 = tmp32 <= tmp1
tmp40 = tmp28 <= tmp1
tmp41 = tmp24 <= tmp1
tmp42 = tmp20 <= tmp1
tmp43 = tmp16 <= tmp1
tmp44 = tmp12 <= tmp1
tmp45 = tmp7 <= tmp1
tmp46 = tmp0 <= tmp1
tl.store(in_out_ptr0 + x2, tmp37, xmask)
tl.store(out_ptr0 + x2, tmp38, xmask)
tl.store(out_ptr1 + x2, tmp39, xmask)
tl.store(out_ptr2 + x2, tmp40, xmask)
tl.store(out_ptr3 + x2, tmp41, xmask)
tl.store(out_ptr4 + x2, tmp42, xmask)
tl.store(out_ptr5 + x2, tmp43, xmask)
tl.store(out_ptr6 + x2, tmp44, xmask)
tl.store(out_ptr7 + x2, tmp45, xmask)
tl.store(out_ptr8 + x2, tmp46, xmask)
@triton.jit
def triton_poi_fused_add_relu_threshold_backward_27(in_out_ptr0, in_ptr0,
in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8,
in_ptr9, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5,
out_ptr6, out_ptr7, out_ptr8, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp3 = tl.load(in_ptr1 + x2, xmask)
tmp5 = tl.load(in_ptr2 + x2, xmask)
tmp6 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr4 + x2, xmask)
tmp13 = tl.load(in_ptr5 + x2, xmask)
tmp17 = tl.load(in_ptr6 + x2, xmask)
tmp19 = tl.load(in_ptr7 + x2, xmask)
tmp23 = tl.load(in_ptr8 + x2, xmask)
tmp25 = tl.load(in_ptr9 + x2, xmask)
tmp1 = 0.0
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp7 = tmp5 + tmp6
tmp8 = tl.full([1], 0, tl.int32)
tmp9 = triton_helpers.maximum(tmp8, tmp7)
tmp10 = tmp4 + tmp9
tmp12 = tmp10 + tmp11
tmp14 = tmp13 + tmp6
tmp15 = triton_helpers.maximum(tmp8, tmp14)
tmp16 = tmp12 + tmp15
tmp18 = tmp16 + tmp17
tmp20 = tmp19 + tmp6
tmp21 = triton_helpers.maximum(tmp8, tmp20)
tmp22 = tmp18 + tmp21
tmp24 = tmp22 + tmp23
tmp26 = tmp25 + tmp6
tmp27 = triton_helpers.maximum(tmp8, tmp26)
tmp28 = tmp24 + tmp27
tmp29 = tmp27 <= tmp1
tmp30 = tmp21 <= tmp1
tmp31 = tmp15 <= tmp1
tmp32 = tmp9 <= tmp1
tmp33 = tmp23 <= tmp1
tmp34 = tmp17 <= tmp1
tmp35 = tmp11 <= tmp1
tmp36 = tmp3 <= tmp1
tmp37 = tmp0 <= tmp1
tl.store(in_out_ptr0 + x2, tmp28, xmask)
tl.store(out_ptr0 + x2, tmp29, xmask)
tl.store(out_ptr1 + x2, tmp30, xmask)
tl.store(out_ptr2 + x2, tmp31, xmask)
tl.store(out_ptr3 + x2, tmp32, xmask)
tl.store(out_ptr4 + x2, tmp33, xmask)
tl.store(out_ptr5 + x2, tmp34, xmask)
tl.store(out_ptr6 + x2, tmp35, xmask)
tl.store(out_ptr7 + x2, tmp36, xmask)
tl.store(out_ptr8 + x2, tmp37, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
primals_13, primals_14, primals_15, primals_16, primals_17,
primals_18, primals_19, primals_20, primals_21, primals_22,
primals_23, primals_24, primals_25, primals_26, primals_27,
primals_28, primals_29, primals_30) = args
args.clear()
assert_size_stride(primals_1, (4, 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, (8, 4), (4, 1))
assert_size_stride(primals_8, (8,), (1,))
assert_size_stride(primals_9, (4, 4), (4, 1))
assert_size_stride(primals_10, (4,), (1,))
assert_size_stride(primals_11, (4, 8), (8, 1))
assert_size_stride(primals_12, (4,), (1,))
assert_size_stride(primals_13, (8, 4), (4, 1))
assert_size_stride(primals_14, (8,), (1,))
assert_size_stride(primals_15, (4, 4), (4, 1))
assert_size_stride(primals_16, (4,), (1,))
assert_size_stride(primals_17, (4, 8), (8, 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, 4), (4, 1))
assert_size_stride(primals_22, (4,), (1,))
assert_size_stride(primals_23, (12, 4), (4, 1))
assert_size_stride(primals_24, (12,), (1,))
assert_size_stride(primals_25, (12, 4), (4, 1))
assert_size_stride(primals_26, (12,), (1,))
assert_size_stride(primals_27, (4, 4), (4, 1))
assert_size_stride(primals_28, (4,), (1,))
assert_size_stride(primals_29, (4, 4), (4, 1))
assert_size_stride(primals_30, (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 = reinterpret_tensor(buf0, (4, 4, 4), (16, 4, 1), 0)
del buf0
buf55 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
buf54 = reinterpret_tensor(buf55, (4, 4, 4), (32, 8, 1), 0)
get_raw_stream(0)
triton_poi_fused_cat_relu_0[grid(64)](buf2, primals_2, buf54, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del primals_2
buf3 = empty_strided_cuda((16, 8), (8, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf2, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_7, (4, 8), (1, 4), 0), out=buf3)
buf4 = reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0)
del buf1
buf28 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
buf27 = reinterpret_tensor(buf28, (4, 4, 4), (32, 8, 1), 0)
triton_poi_fused_cat_relu_0[grid(64)](buf4, primals_5, buf27, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del primals_5
buf5 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf4, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_9, (4, 4), (1, 4), 0), out=buf5)
buf6 = reinterpret_tensor(buf5, (4, 4, 4), (16, 4, 1), 0)
del buf5
buf500 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_1[grid(64)](buf6,
primals_10, buf500, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf7 = reinterpret_tensor(buf3, (4, 4, 8), (32, 8, 1), 0)
del buf3
buf501 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_2[grid(128)](buf7,
primals_8, buf501, 128, XBLOCK=128, num_warps=4, num_stages=1)
buf8 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
triton_poi_fused_bmm_3[grid(16)](buf6, buf8, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf9 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32)
triton_poi_fused_bmm_4[grid(16)](buf7, buf9, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf10 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf8, buf9, out=buf10)
buf11 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf10, buf11, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf12 = reinterpret_tensor(buf9, (4, 4, 1), (4, 1, 16), 0)
del buf9
triton_poi_fused_bmm_6[grid(16)](buf6, buf12, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf13 = reinterpret_tensor(buf8, (4, 1, 4), (4, 16, 1), 0)
del buf8
triton_poi_fused_bmm_7[grid(16)](buf7, buf13, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf14 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf12, buf13, out=buf14)
buf15 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf14, buf15, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf16 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.float32)
triton_poi_fused_cat_8[grid(32)](buf11, buf7, buf15, buf16, 32,
XBLOCK=32, num_warps=1, num_stages=1)
buf17 = reinterpret_tensor(buf13, (4, 4, 1), (4, 1, 16), 0)
del buf13
triton_poi_fused_bmm_9[grid(16)](buf6, buf17, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf18 = reinterpret_tensor(buf12, (4, 1, 4), (4, 16, 1), 0)
del buf12
triton_poi_fused_bmm_10[grid(16)](buf7, buf18, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf19 = buf15
del buf15
extern_kernels.bmm(buf17, buf18, out=buf19)
buf20 = buf11
del buf11
triton_poi_fused__softmax_5[grid(64)](buf19, buf20, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf21 = empty_strided_cuda((4, 4, 3), (12, 3, 1), torch.float32)
triton_poi_fused_cat_11[grid(48)](buf16, buf20, buf7, buf21, 48,
XBLOCK=64, num_warps=1, num_stages=1)
buf22 = reinterpret_tensor(buf18, (4, 4, 1), (4, 1, 16), 0)
del buf18
triton_poi_fused_bmm_12[grid(16)](buf6, buf22, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf23 = reinterpret_tensor(buf17, (4, 1, 4), (4, 16, 1), 0)
del buf17
triton_poi_fused_bmm_13[grid(16)](buf7, buf23, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf24 = buf20
del buf20
extern_kernels.bmm(buf22, buf23, out=buf24)
buf25 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf24, buf25, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf26 = reinterpret_tensor(buf28, (4, 4, 4), (32, 8, 1), 4)
triton_poi_fused_cat_14[grid(64)](buf21, buf25, buf7, buf26, 64,
XBLOCK=64, num_warps=1, num_stages=1)
buf29 = reinterpret_tensor(buf25, (16, 4), (4, 1), 0)
del buf25
extern_kernels.mm(reinterpret_tensor(buf28, (16, 8), (8, 1), 0),
reinterpret_tensor(primals_11, (8, 4), (1, 8), 0), out=buf29)
buf30 = reinterpret_tensor(buf29, (4, 4, 4), (16, 4, 1), 0)
del buf29
buf64 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_relu_15[grid(64)](buf30, primals_12, buf4,
buf64, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf31 = empty_strided_cuda((16, 8), (8, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf30, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_13, (4, 8), (1, 4), 0), out=buf31)
buf32 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf2, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_15, (4, 4), (1, 4), 0), out=buf32)
buf33 = reinterpret_tensor(buf32, (4, 4, 4), (16, 4, 1), 0)
del buf32
buf497 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_1[grid(64)](buf33,
primals_16, buf497, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf34 = reinterpret_tensor(buf31, (4, 4, 8), (32, 8, 1), 0)
del buf31
buf498 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_2[grid(128)](buf34,
primals_14, buf498, 128, XBLOCK=128, num_warps=4, num_stages=1)
buf35 = reinterpret_tensor(buf23, (4, 4, 1), (4, 1, 16), 0)
del buf23
triton_poi_fused_bmm_3[grid(16)](buf33, buf35, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf36 = reinterpret_tensor(buf22, (4, 1, 4), (4, 16, 1), 0)
del buf22
triton_poi_fused_bmm_4[grid(16)](buf34, buf36, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf37 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf35, buf36, out=buf37)
buf38 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf37, buf38, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf39 = reinterpret_tensor(buf36, (4, 4, 1), (4, 1, 16), 0)
del buf36
triton_poi_fused_bmm_6[grid(16)](buf33, buf39, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf40 = reinterpret_tensor(buf35, (4, 1, 4), (4, 16, 1), 0)
del buf35
triton_poi_fused_bmm_7[grid(16)](buf34, buf40, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf41 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf39, buf40, out=buf41)
buf42 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf41, buf42, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf43 = buf16
del buf16
triton_poi_fused_cat_8[grid(32)](buf38, buf34, buf42, buf43, 32,
XBLOCK=32, num_warps=1, num_stages=1)
buf44 = reinterpret_tensor(buf40, (4, 4, 1), (4, 1, 16), 0)
del buf40
triton_poi_fused_bmm_9[grid(16)](buf33, buf44, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf45 = reinterpret_tensor(buf39, (4, 1, 4), (4, 16, 1), 0)
del buf39
triton_poi_fused_bmm_10[grid(16)](buf34, buf45, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf46 = buf42
del buf42
extern_kernels.bmm(buf44, buf45, out=buf46)
buf47 = buf38
del buf38
triton_poi_fused__softmax_5[grid(64)](buf46, buf47, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf48 = buf21
del buf21
triton_poi_fused_cat_11[grid(48)](buf43, buf47, buf34, buf48, 48,
XBLOCK=64, num_warps=1, num_stages=1)
buf49 = reinterpret_tensor(buf45, (4, 4, 1), (4, 1, 16), 0)
del buf45
triton_poi_fused_bmm_12[grid(16)](buf33, buf49, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf50 = reinterpret_tensor(buf44, (4, 1, 4), (4, 16, 1), 0)
del buf44
triton_poi_fused_bmm_13[grid(16)](buf34, buf50, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf51 = buf47
del buf47
extern_kernels.bmm(buf49, buf50, out=buf51)
buf52 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf51, buf52, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf53 = reinterpret_tensor(buf55, (4, 4, 4), (32, 8, 1), 4)
triton_poi_fused_cat_14[grid(64)](buf48, buf52, buf34, buf53, 64,
XBLOCK=64, num_warps=1, num_stages=1)
buf56 = reinterpret_tensor(buf52, (16, 4), (4, 1), 0)
del buf52
extern_kernels.mm(reinterpret_tensor(buf55, (16, 8), (8, 1), 0),
reinterpret_tensor(primals_17, (8, 4), (1, 8), 0), out=buf56)
buf57 = reinterpret_tensor(buf50, (4, 4), (4, 1), 0)
del buf50
buf58 = buf57
del buf57
triton_poi_fused_add_div_relu_sum_16[grid(16)](buf58, buf56,
primals_18, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1)
buf59 = reinterpret_tensor(buf49, (4, 4), (4, 1), 0)
del buf49
triton_poi_fused_add_div_sum_17[grid(16)](buf30, buf4, buf59, 16,
XBLOCK=16, num_warps=1, num_stages=1)
buf60 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_20, buf58, reinterpret_tensor(
primals_19, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf60)
buf61 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_22, buf59, reinterpret_tensor(
primals_21, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf61)
buf62 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_relu_18[grid(64)](buf56, primals_18, buf2,
buf62, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf63 = empty_strided_cuda((16, 12), (12, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf62, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_23, (4, 12), (1, 4), 0), out=buf63)
buf65 = empty_strided_cuda((16, 12), (12, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf64, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_25, (4, 12), (1, 4), 0), out=buf65)
buf66 = reinterpret_tensor(buf63, (4, 4, 12), (48, 12, 1), 0)
del buf63
buf495 = empty_strided_cuda((4, 4, 12), (48, 12, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_19[grid(192)](buf66,
primals_24, buf495, 192, XBLOCK=128, num_warps=4, num_stages=1)
buf67 = reinterpret_tensor(buf65, (4, 4, 12), (48, 12, 1), 0)
del buf65
buf494 = empty_strided_cuda((4, 4, 12), (48, 12, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_19[grid(192)](buf67,
primals_26, buf494, 192, XBLOCK=128, num_warps=4, num_stages=1)
buf68 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf69 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf80 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_mul_20[grid(64)](buf61, buf66, buf68, buf69,
buf80, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf70 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
triton_poi_fused_bmm_3[grid(16)](buf68, buf70, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf71 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32)
triton_poi_fused_bmm_3[grid(16)](buf69, buf71, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf72 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf70, buf71, out=buf72)
buf73 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf74 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf81 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_mul_20[grid(64)](buf60, buf67, buf73, buf74,
buf81, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf75 = reinterpret_tensor(buf71, (4, 4, 1), (4, 1, 16), 0)
del buf71
triton_poi_fused_bmm_3[grid(16)](buf73, buf75, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf76 = reinterpret_tensor(buf70, (4, 1, 4), (4, 16, 1), 0)
del buf70
triton_poi_fused_bmm_3[grid(16)](buf74, buf76, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf77 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf75, buf76, out=buf77)
buf78 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf72, buf78, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf79 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf77, buf79, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf82 = reinterpret_tensor(buf76, (4, 4, 1), (4, 1, 16), 0)
del buf76
triton_poi_fused_bmm_6[grid(16)](buf68, buf82, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf83 = reinterpret_tensor(buf75, (4, 1, 4), (4, 16, 1), 0)
del buf75
triton_poi_fused_bmm_6[grid(16)](buf69, buf83, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf84 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf82, buf83, out=buf84)
buf85 = reinterpret_tensor(buf83, (4, 4, 1), (4, 1, 16), 0)
del buf83
triton_poi_fused_bmm_6[grid(16)](buf73, buf85, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf86 = reinterpret_tensor(buf82, (4, 1, 4), (4, 16, 1), 0)
del buf82
triton_poi_fused_bmm_6[grid(16)](buf74, buf86, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf87 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf85, buf86, out=buf87)
buf88 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf84, buf88, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf89 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf87, buf89, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf90 = buf43
del buf43
triton_poi_fused_cat_21[grid(32)](buf78, buf80, buf88, buf90, 32,
XBLOCK=32, num_warps=1, num_stages=1)
buf91 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.float32)
triton_poi_fused_cat_21[grid(32)](buf79, buf81, buf89, buf91, 32,
XBLOCK=32, num_warps=1, num_stages=1)
buf92 = reinterpret_tensor(buf86, (4, 4, 1), (4, 1, 16), 0)
del buf86
triton_poi_fused_bmm_9[grid(16)](buf68, buf92, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf93 = reinterpret_tensor(buf85, (4, 1, 4), (4, 16, 1), 0)
del buf85
triton_poi_fused_bmm_9[grid(16)](buf69, buf93, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf94 = buf89
del buf89
extern_kernels.bmm(buf92, buf93, out=buf94)
buf95 = reinterpret_tensor(buf93, (4, 4, 1), (4, 1, 16), 0)
del buf93
triton_poi_fused_bmm_9[grid(16)](buf73, buf95, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf96 = reinterpret_tensor(buf92, (4, 1, 4), (4, 16, 1), 0)
del buf92
triton_poi_fused_bmm_9[grid(16)](buf74, buf96, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf97 = buf79
del buf79
extern_kernels.bmm(buf95, buf96, out=buf97)
buf98 = buf88
del buf88
triton_poi_fused__softmax_5[grid(64)](buf94, buf98, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf99 = buf78
del buf78
triton_poi_fused__softmax_5[grid(64)](buf97, buf99, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf100 = buf48
del buf48
triton_poi_fused_cat_22[grid(48)](buf90, buf98, buf80, buf100, 48,
XBLOCK=64, num_warps=1, num_stages=1)
buf101 = empty_strided_cuda((4, 4, 3), (12, 3, 1), torch.float32)
triton_poi_fused_cat_22[grid(48)](buf91, buf99, buf81, buf101, 48,
XBLOCK=64, num_warps=1, num_stages=1)
buf102 = reinterpret_tensor(buf96, (4, 4, 1), (4, 1, 16), 0)
del buf96
triton_poi_fused_bmm_12[grid(16)](buf68, buf102, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf103 = reinterpret_tensor(buf95, (4, 1, 4), (4, 16, 1), 0)
del buf95
triton_poi_fused_bmm_12[grid(16)](buf69, buf103, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf104 = buf99
del buf99
extern_kernels.bmm(buf102, buf103, out=buf104)
buf105 = reinterpret_tensor(buf103, (4, 4, 1), (4, 1, 16), 0)
del buf103
triton_poi_fused_bmm_12[grid(16)](buf73, buf105, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf106 = reinterpret_tensor(buf102, (4, 1, 4), (4, 16, 1), 0)
del buf102
triton_poi_fused_bmm_12[grid(16)](buf74, buf106, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf107 = buf98
del buf98
extern_kernels.bmm(buf105, buf106, out=buf107)
buf108 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf104, buf108, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf109 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf107, buf109, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf110 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf112 = buf110
del buf110
triton_poi_fused_add_cat_23[grid(64)](buf112, buf100, buf108, buf80,
buf62, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf111 = buf108
del buf108
buf114 = buf111
del buf111
triton_poi_fused_add_cat_23[grid(64)](buf114, buf101, buf109, buf81,
buf64, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf113 = reinterpret_tensor(buf109, (16, 4), (4, 1), 0)
del buf109
extern_kernels.mm(reinterpret_tensor(buf112, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_27, (4, 4), (1, 4), 0), out=buf113)
buf115 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf114, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_29, (4, 4), (1, 4), 0), out=buf115)
buf116 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf169 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
buf168 = reinterpret_tensor(buf169, (4, 4, 4), (32, 8, 1), 0)
triton_poi_fused_add_cat_relu_24[grid(64)](buf113, primals_28,
buf56, primals_18, buf2, buf116, buf168, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf117 = empty_strided_cuda((16, 8), (8, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf116, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_7, (4, 8), (1, 4), 0), out=buf117)
buf118 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf142 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
buf141 = reinterpret_tensor(buf142, (4, 4, 4), (32, 8, 1), 0)
triton_poi_fused_add_cat_relu_25[grid(64)](buf115, primals_30,
buf30, buf4, buf118, buf141, 64, XBLOCK=64, num_warps=1,
num_stages=1)
buf119 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf118, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_9, (4, 4), (1, 4), 0), out=buf119)
buf120 = reinterpret_tensor(buf119, (4, 4, 4), (16, 4, 1), 0)
del buf119
buf490 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_1[grid(64)](buf120,
primals_10, buf490, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf121 = reinterpret_tensor(buf117, (4, 4, 8), (32, 8, 1), 0)
del buf117
buf491 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_2[grid(128)](buf121,
primals_8, buf491, 128, XBLOCK=128, num_warps=4, num_stages=1)
buf122 = reinterpret_tensor(buf106, (4, 4, 1), (4, 1, 16), 0)
del buf106
triton_poi_fused_bmm_3[grid(16)](buf120, buf122, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf123 = reinterpret_tensor(buf105, (4, 1, 4), (4, 16, 1), 0)
del buf105
triton_poi_fused_bmm_4[grid(16)](buf121, buf123, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf124 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf122, buf123, out=buf124)
buf125 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf124, buf125, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf126 = reinterpret_tensor(buf123, (4, 4, 1), (4, 1, 16), 0)
del buf123
triton_poi_fused_bmm_6[grid(16)](buf120, buf126, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf127 = reinterpret_tensor(buf122, (4, 1, 4), (4, 16, 1), 0)
del buf122
triton_poi_fused_bmm_7[grid(16)](buf121, buf127, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf128 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf126, buf127, out=buf128)
buf129 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf128, buf129, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf130 = buf91
del buf91
triton_poi_fused_cat_8[grid(32)](buf125, buf121, buf129, buf130, 32,
XBLOCK=32, num_warps=1, num_stages=1)
buf131 = reinterpret_tensor(buf127, (4, 4, 1), (4, 1, 16), 0)
del buf127
triton_poi_fused_bmm_9[grid(16)](buf120, buf131, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf132 = reinterpret_tensor(buf126, (4, 1, 4), (4, 16, 1), 0)
del buf126
triton_poi_fused_bmm_10[grid(16)](buf121, buf132, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf133 = buf129
del buf129
extern_kernels.bmm(buf131, buf132, out=buf133)
buf134 = buf125
del buf125
triton_poi_fused__softmax_5[grid(64)](buf133, buf134, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf135 = buf101
del buf101
triton_poi_fused_cat_11[grid(48)](buf130, buf134, buf121, buf135,
48, XBLOCK=64, num_warps=1, num_stages=1)
buf136 = reinterpret_tensor(buf132, (4, 4, 1), (4, 1, 16), 0)
del buf132
triton_poi_fused_bmm_12[grid(16)](buf120, buf136, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf137 = reinterpret_tensor(buf131, (4, 1, 4), (4, 16, 1), 0)
del buf131
triton_poi_fused_bmm_13[grid(16)](buf121, buf137, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf138 = buf134
del buf134
extern_kernels.bmm(buf136, buf137, out=buf138)
buf139 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf138, buf139, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf140 = reinterpret_tensor(buf142, (4, 4, 4), (32, 8, 1), 4)
triton_poi_fused_cat_14[grid(64)](buf135, buf139, buf121, buf140,
64, XBLOCK=64, num_warps=1, num_stages=1)
buf143 = reinterpret_tensor(buf139, (16, 4), (4, 1), 0)
del buf139
extern_kernels.mm(reinterpret_tensor(buf142, (16, 8), (8, 1), 0),
reinterpret_tensor(primals_11, (8, 4), (1, 8), 0), out=buf143)
buf144 = reinterpret_tensor(buf143, (4, 4, 4), (16, 4, 1), 0)
del buf143
buf178 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_relu_15[grid(64)](buf144, primals_12, buf118,
buf178, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf145 = empty_strided_cuda((16, 8), (8, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf144, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_13, (4, 8), (1, 4), 0), out=buf145)
buf146 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf116, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_15, (4, 4), (1, 4), 0), out=buf146)
buf147 = reinterpret_tensor(buf146, (4, 4, 4), (16, 4, 1), 0)
del buf146
buf487 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_1[grid(64)](buf147,
primals_16, buf487, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf148 = reinterpret_tensor(buf145, (4, 4, 8), (32, 8, 1), 0)
del buf145
buf488 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_2[grid(128)](buf148,
primals_14, buf488, 128, XBLOCK=128, num_warps=4, num_stages=1)
buf149 = reinterpret_tensor(buf137, (4, 4, 1), (4, 1, 16), 0)
del buf137
triton_poi_fused_bmm_3[grid(16)](buf147, buf149, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf150 = reinterpret_tensor(buf136, (4, 1, 4), (4, 16, 1), 0)
del buf136
triton_poi_fused_bmm_4[grid(16)](buf148, buf150, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf151 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf149, buf150, out=buf151)
buf152 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf151, buf152, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf153 = reinterpret_tensor(buf150, (4, 4, 1), (4, 1, 16), 0)
del buf150
triton_poi_fused_bmm_6[grid(16)](buf147, buf153, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf154 = reinterpret_tensor(buf149, (4, 1, 4), (4, 16, 1), 0)
del buf149
triton_poi_fused_bmm_7[grid(16)](buf148, buf154, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf155 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf153, buf154, out=buf155)
buf156 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf155, buf156, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf157 = buf130
del buf130
triton_poi_fused_cat_8[grid(32)](buf152, buf148, buf156, buf157, 32,
XBLOCK=32, num_warps=1, num_stages=1)
buf158 = reinterpret_tensor(buf154, (4, 4, 1), (4, 1, 16), 0)
del buf154
triton_poi_fused_bmm_9[grid(16)](buf147, buf158, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf159 = reinterpret_tensor(buf153, (4, 1, 4), (4, 16, 1), 0)
del buf153
triton_poi_fused_bmm_10[grid(16)](buf148, buf159, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf160 = buf156
del buf156
extern_kernels.bmm(buf158, buf159, out=buf160)
buf161 = buf152
del buf152
triton_poi_fused__softmax_5[grid(64)](buf160, buf161, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf162 = buf135
del buf135
triton_poi_fused_cat_11[grid(48)](buf157, buf161, buf148, buf162,
48, XBLOCK=64, num_warps=1, num_stages=1)
buf163 = reinterpret_tensor(buf159, (4, 4, 1), (4, 1, 16), 0)
del buf159
triton_poi_fused_bmm_12[grid(16)](buf147, buf163, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf164 = reinterpret_tensor(buf158, (4, 1, 4), (4, 16, 1), 0)
del buf158
triton_poi_fused_bmm_13[grid(16)](buf148, buf164, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf165 = buf161
del buf161
extern_kernels.bmm(buf163, buf164, out=buf165)
buf166 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf165, buf166, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf167 = reinterpret_tensor(buf169, (4, 4, 4), (32, 8, 1), 4)
triton_poi_fused_cat_14[grid(64)](buf162, buf166, buf148, buf167,
64, XBLOCK=64, num_warps=1, num_stages=1)
buf170 = reinterpret_tensor(buf166, (16, 4), (4, 1), 0)
del buf166
extern_kernels.mm(reinterpret_tensor(buf169, (16, 8), (8, 1), 0),
reinterpret_tensor(primals_17, (8, 4), (1, 8), 0), out=buf170)
buf171 = reinterpret_tensor(buf164, (4, 4), (4, 1), 0)
del buf164
buf172 = buf171
del buf171
triton_poi_fused_add_div_relu_sum_16[grid(16)](buf172, buf170,
primals_18, buf116, 16, XBLOCK=16, num_warps=1, num_stages=1)
buf173 = reinterpret_tensor(buf163, (4, 4), (4, 1), 0)
del buf163
triton_poi_fused_add_div_sum_17[grid(16)](buf144, buf118, buf173,
16, XBLOCK=16, num_warps=1, num_stages=1)
buf174 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_20, buf172, reinterpret_tensor(
primals_19, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf174)
buf175 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_22, buf173, reinterpret_tensor(
primals_21, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf175)
buf176 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_relu_18[grid(64)](buf170, primals_18, buf116,
buf176, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf177 = empty_strided_cuda((16, 12), (12, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf176, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_23, (4, 12), (1, 4), 0), out=buf177)
buf179 = empty_strided_cuda((16, 12), (12, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf178, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_25, (4, 12), (1, 4), 0), out=buf179)
buf180 = reinterpret_tensor(buf177, (4, 4, 12), (48, 12, 1), 0)
del buf177
buf485 = empty_strided_cuda((4, 4, 12), (48, 12, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_19[grid(192)](buf180,
primals_24, buf485, 192, XBLOCK=128, num_warps=4, num_stages=1)
buf181 = reinterpret_tensor(buf179, (4, 4, 12), (48, 12, 1), 0)
del buf179
buf484 = empty_strided_cuda((4, 4, 12), (48, 12, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_19[grid(192)](buf181,
primals_26, buf484, 192, XBLOCK=128, num_warps=4, num_stages=1)
buf182 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf183 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf194 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_mul_20[grid(64)](buf175, buf180, buf182,
buf183, buf194, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf184 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
triton_poi_fused_bmm_3[grid(16)](buf182, buf184, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf185 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32)
triton_poi_fused_bmm_3[grid(16)](buf183, buf185, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf186 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf184, buf185, out=buf186)
buf187 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf188 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf195 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_mul_20[grid(64)](buf174, buf181, buf187,
buf188, buf195, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf189 = reinterpret_tensor(buf185, (4, 4, 1), (4, 1, 16), 0)
del buf185
triton_poi_fused_bmm_3[grid(16)](buf187, buf189, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf190 = reinterpret_tensor(buf184, (4, 1, 4), (4, 16, 1), 0)
del buf184
triton_poi_fused_bmm_3[grid(16)](buf188, buf190, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf191 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf189, buf190, out=buf191)
buf192 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf186, buf192, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf193 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf191, buf193, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf196 = reinterpret_tensor(buf190, (4, 4, 1), (4, 1, 16), 0)
del buf190
triton_poi_fused_bmm_6[grid(16)](buf182, buf196, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf197 = reinterpret_tensor(buf189, (4, 1, 4), (4, 16, 1), 0)
del buf189
triton_poi_fused_bmm_6[grid(16)](buf183, buf197, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf198 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf196, buf197, out=buf198)
buf199 = reinterpret_tensor(buf197, (4, 4, 1), (4, 1, 16), 0)
del buf197
triton_poi_fused_bmm_6[grid(16)](buf187, buf199, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf200 = reinterpret_tensor(buf196, (4, 1, 4), (4, 16, 1), 0)
del buf196
triton_poi_fused_bmm_6[grid(16)](buf188, buf200, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf201 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf199, buf200, out=buf201)
buf202 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf198, buf202, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf203 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf201, buf203, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf204 = buf157
del buf157
triton_poi_fused_cat_21[grid(32)](buf192, buf194, buf202, buf204,
32, XBLOCK=32, num_warps=1, num_stages=1)
buf205 = buf90
del buf90
triton_poi_fused_cat_21[grid(32)](buf193, buf195, buf203, buf205,
32, XBLOCK=32, num_warps=1, num_stages=1)
buf206 = reinterpret_tensor(buf200, (4, 4, 1), (4, 1, 16), 0)
del buf200
triton_poi_fused_bmm_9[grid(16)](buf182, buf206, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf207 = reinterpret_tensor(buf199, (4, 1, 4), (4, 16, 1), 0)
del buf199
triton_poi_fused_bmm_9[grid(16)](buf183, buf207, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf208 = buf203
del buf203
extern_kernels.bmm(buf206, buf207, out=buf208)
buf209 = reinterpret_tensor(buf207, (4, 4, 1), (4, 1, 16), 0)
del buf207
triton_poi_fused_bmm_9[grid(16)](buf187, buf209, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf210 = reinterpret_tensor(buf206, (4, 1, 4), (4, 16, 1), 0)
del buf206
triton_poi_fused_bmm_9[grid(16)](buf188, buf210, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf211 = buf193
del buf193
extern_kernels.bmm(buf209, buf210, out=buf211)
buf212 = buf202
del buf202
triton_poi_fused__softmax_5[grid(64)](buf208, buf212, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf213 = buf192
del buf192
triton_poi_fused__softmax_5[grid(64)](buf211, buf213, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf214 = buf162
del buf162
triton_poi_fused_cat_22[grid(48)](buf204, buf212, buf194, buf214,
48, XBLOCK=64, num_warps=1, num_stages=1)
buf215 = buf100
del buf100
triton_poi_fused_cat_22[grid(48)](buf205, buf213, buf195, buf215,
48, XBLOCK=64, num_warps=1, num_stages=1)
buf216 = reinterpret_tensor(buf210, (4, 4, 1), (4, 1, 16), 0)
del buf210
triton_poi_fused_bmm_12[grid(16)](buf182, buf216, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf217 = reinterpret_tensor(buf209, (4, 1, 4), (4, 16, 1), 0)
del buf209
triton_poi_fused_bmm_12[grid(16)](buf183, buf217, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf218 = buf213
del buf213
extern_kernels.bmm(buf216, buf217, out=buf218)
buf219 = reinterpret_tensor(buf217, (4, 4, 1), (4, 1, 16), 0)
del buf217
triton_poi_fused_bmm_12[grid(16)](buf187, buf219, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf220 = reinterpret_tensor(buf216, (4, 1, 4), (4, 16, 1), 0)
del buf216
triton_poi_fused_bmm_12[grid(16)](buf188, buf220, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf221 = buf212
del buf212
extern_kernels.bmm(buf219, buf220, out=buf221)
buf222 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf218, buf222, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf223 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf221, buf223, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf224 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf226 = buf224
del buf224
triton_poi_fused_add_cat_23[grid(64)](buf226, buf214, buf222,
buf194, buf176, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf225 = buf222
del buf222
buf228 = buf225
del buf225
triton_poi_fused_add_cat_23[grid(64)](buf228, buf215, buf223,
buf195, buf178, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf227 = reinterpret_tensor(buf223, (16, 4), (4, 1), 0)
del buf223
extern_kernels.mm(reinterpret_tensor(buf226, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_27, (4, 4), (1, 4), 0), out=buf227)
buf229 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf228, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_29, (4, 4), (1, 4), 0), out=buf229)
buf230 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf283 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
buf282 = reinterpret_tensor(buf283, (4, 4, 4), (32, 8, 1), 0)
triton_poi_fused_add_cat_relu_24[grid(64)](buf227, primals_28,
buf170, primals_18, buf116, buf230, buf282, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf231 = empty_strided_cuda((16, 8), (8, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf230, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_7, (4, 8), (1, 4), 0), out=buf231)
buf232 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf256 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
buf255 = reinterpret_tensor(buf256, (4, 4, 4), (32, 8, 1), 0)
triton_poi_fused_add_cat_relu_25[grid(64)](buf229, primals_30,
buf144, buf118, buf232, buf255, 64, XBLOCK=64, num_warps=1,
num_stages=1)
buf233 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf232, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_9, (4, 4), (1, 4), 0), out=buf233)
buf234 = reinterpret_tensor(buf233, (4, 4, 4), (16, 4, 1), 0)
del buf233
buf480 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_1[grid(64)](buf234,
primals_10, buf480, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf235 = reinterpret_tensor(buf231, (4, 4, 8), (32, 8, 1), 0)
del buf231
buf481 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_2[grid(128)](buf235,
primals_8, buf481, 128, XBLOCK=128, num_warps=4, num_stages=1)
buf236 = reinterpret_tensor(buf220, (4, 4, 1), (4, 1, 16), 0)
del buf220
triton_poi_fused_bmm_3[grid(16)](buf234, buf236, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf237 = reinterpret_tensor(buf219, (4, 1, 4), (4, 16, 1), 0)
del buf219
triton_poi_fused_bmm_4[grid(16)](buf235, buf237, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf238 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf236, buf237, out=buf238)
buf239 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf238, buf239, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf240 = reinterpret_tensor(buf237, (4, 4, 1), (4, 1, 16), 0)
del buf237
triton_poi_fused_bmm_6[grid(16)](buf234, buf240, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf241 = reinterpret_tensor(buf236, (4, 1, 4), (4, 16, 1), 0)
del buf236
triton_poi_fused_bmm_7[grid(16)](buf235, buf241, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf242 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf240, buf241, out=buf242)
buf243 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf242, buf243, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf244 = buf205
del buf205
triton_poi_fused_cat_8[grid(32)](buf239, buf235, buf243, buf244, 32,
XBLOCK=32, num_warps=1, num_stages=1)
buf245 = reinterpret_tensor(buf241, (4, 4, 1), (4, 1, 16), 0)
del buf241
triton_poi_fused_bmm_9[grid(16)](buf234, buf245, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf246 = reinterpret_tensor(buf240, (4, 1, 4), (4, 16, 1), 0)
del buf240
triton_poi_fused_bmm_10[grid(16)](buf235, buf246, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf247 = buf243
del buf243
extern_kernels.bmm(buf245, buf246, out=buf247)
buf248 = buf239
del buf239
triton_poi_fused__softmax_5[grid(64)](buf247, buf248, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf249 = buf215
del buf215
triton_poi_fused_cat_11[grid(48)](buf244, buf248, buf235, buf249,
48, XBLOCK=64, num_warps=1, num_stages=1)
buf250 = reinterpret_tensor(buf246, (4, 4, 1), (4, 1, 16), 0)
del buf246
triton_poi_fused_bmm_12[grid(16)](buf234, buf250, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf251 = reinterpret_tensor(buf245, (4, 1, 4), (4, 16, 1), 0)
del buf245
triton_poi_fused_bmm_13[grid(16)](buf235, buf251, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf252 = buf248
del buf248
extern_kernels.bmm(buf250, buf251, out=buf252)
buf253 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf252, buf253, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf254 = reinterpret_tensor(buf256, (4, 4, 4), (32, 8, 1), 4)
triton_poi_fused_cat_14[grid(64)](buf249, buf253, buf235, buf254,
64, XBLOCK=64, num_warps=1, num_stages=1)
buf257 = reinterpret_tensor(buf253, (16, 4), (4, 1), 0)
del buf253
extern_kernels.mm(reinterpret_tensor(buf256, (16, 8), (8, 1), 0),
reinterpret_tensor(primals_11, (8, 4), (1, 8), 0), out=buf257)
buf258 = reinterpret_tensor(buf257, (4, 4, 4), (16, 4, 1), 0)
del buf257
buf292 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_relu_15[grid(64)](buf258, primals_12, buf232,
buf292, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf259 = empty_strided_cuda((16, 8), (8, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf258, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_13, (4, 8), (1, 4), 0), out=buf259)
buf260 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf230, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_15, (4, 4), (1, 4), 0), out=buf260)
buf261 = reinterpret_tensor(buf260, (4, 4, 4), (16, 4, 1), 0)
del buf260
buf477 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_1[grid(64)](buf261,
primals_16, buf477, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf262 = reinterpret_tensor(buf259, (4, 4, 8), (32, 8, 1), 0)
del buf259
buf478 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_2[grid(128)](buf262,
primals_14, buf478, 128, XBLOCK=128, num_warps=4, num_stages=1)
buf263 = reinterpret_tensor(buf251, (4, 4, 1), (4, 1, 16), 0)
del buf251
triton_poi_fused_bmm_3[grid(16)](buf261, buf263, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf264 = reinterpret_tensor(buf250, (4, 1, 4), (4, 16, 1), 0)
del buf250
triton_poi_fused_bmm_4[grid(16)](buf262, buf264, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf265 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf263, buf264, out=buf265)
buf266 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf265, buf266, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf267 = reinterpret_tensor(buf264, (4, 4, 1), (4, 1, 16), 0)
del buf264
triton_poi_fused_bmm_6[grid(16)](buf261, buf267, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf268 = reinterpret_tensor(buf263, (4, 1, 4), (4, 16, 1), 0)
del buf263
triton_poi_fused_bmm_7[grid(16)](buf262, buf268, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf269 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf267, buf268, out=buf269)
buf270 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf269, buf270, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf271 = buf244
del buf244
triton_poi_fused_cat_8[grid(32)](buf266, buf262, buf270, buf271, 32,
XBLOCK=32, num_warps=1, num_stages=1)
buf272 = reinterpret_tensor(buf268, (4, 4, 1), (4, 1, 16), 0)
del buf268
triton_poi_fused_bmm_9[grid(16)](buf261, buf272, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf273 = reinterpret_tensor(buf267, (4, 1, 4), (4, 16, 1), 0)
del buf267
triton_poi_fused_bmm_10[grid(16)](buf262, buf273, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf274 = buf270
del buf270
extern_kernels.bmm(buf272, buf273, out=buf274)
buf275 = buf266
del buf266
triton_poi_fused__softmax_5[grid(64)](buf274, buf275, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf276 = buf249
del buf249
triton_poi_fused_cat_11[grid(48)](buf271, buf275, buf262, buf276,
48, XBLOCK=64, num_warps=1, num_stages=1)
buf277 = reinterpret_tensor(buf273, (4, 4, 1), (4, 1, 16), 0)
del buf273
triton_poi_fused_bmm_12[grid(16)](buf261, buf277, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf278 = reinterpret_tensor(buf272, (4, 1, 4), (4, 16, 1), 0)
del buf272
triton_poi_fused_bmm_13[grid(16)](buf262, buf278, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf279 = buf275
del buf275
extern_kernels.bmm(buf277, buf278, out=buf279)
buf280 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf279, buf280, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf281 = reinterpret_tensor(buf283, (4, 4, 4), (32, 8, 1), 4)
triton_poi_fused_cat_14[grid(64)](buf276, buf280, buf262, buf281,
64, XBLOCK=64, num_warps=1, num_stages=1)
buf284 = reinterpret_tensor(buf280, (16, 4), (4, 1), 0)
del buf280
extern_kernels.mm(reinterpret_tensor(buf283, (16, 8), (8, 1), 0),
reinterpret_tensor(primals_17, (8, 4), (1, 8), 0), out=buf284)
buf285 = reinterpret_tensor(buf278, (4, 4), (4, 1), 0)
del buf278
buf286 = buf285
del buf285
triton_poi_fused_add_div_relu_sum_16[grid(16)](buf286, buf284,
primals_18, buf230, 16, XBLOCK=16, num_warps=1, num_stages=1)
buf287 = reinterpret_tensor(buf277, (4, 4), (4, 1), 0)
del buf277
triton_poi_fused_add_div_sum_17[grid(16)](buf258, buf232, buf287,
16, XBLOCK=16, num_warps=1, num_stages=1)
buf288 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_20, buf286, reinterpret_tensor(
primals_19, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf288)
buf289 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_22, buf287, reinterpret_tensor(
primals_21, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf289)
buf290 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_relu_18[grid(64)](buf284, primals_18, buf230,
buf290, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf291 = empty_strided_cuda((16, 12), (12, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf290, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_23, (4, 12), (1, 4), 0), out=buf291)
buf293 = empty_strided_cuda((16, 12), (12, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf292, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_25, (4, 12), (1, 4), 0), out=buf293)
buf294 = reinterpret_tensor(buf291, (4, 4, 12), (48, 12, 1), 0)
del buf291
buf475 = empty_strided_cuda((4, 4, 12), (48, 12, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_19[grid(192)](buf294,
primals_24, buf475, 192, XBLOCK=128, num_warps=4, num_stages=1)
buf295 = reinterpret_tensor(buf293, (4, 4, 12), (48, 12, 1), 0)
del buf293
buf474 = empty_strided_cuda((4, 4, 12), (48, 12, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_19[grid(192)](buf295,
primals_26, buf474, 192, XBLOCK=128, num_warps=4, num_stages=1)
buf296 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf297 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf308 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_mul_20[grid(64)](buf289, buf294, buf296,
buf297, buf308, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf298 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
triton_poi_fused_bmm_3[grid(16)](buf296, buf298, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf299 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32)
triton_poi_fused_bmm_3[grid(16)](buf297, buf299, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf300 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf298, buf299, out=buf300)
buf301 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf302 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf309 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_mul_20[grid(64)](buf288, buf295, buf301,
buf302, buf309, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf303 = reinterpret_tensor(buf299, (4, 4, 1), (4, 1, 16), 0)
del buf299
triton_poi_fused_bmm_3[grid(16)](buf301, buf303, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf304 = reinterpret_tensor(buf298, (4, 1, 4), (4, 16, 1), 0)
del buf298
triton_poi_fused_bmm_3[grid(16)](buf302, buf304, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf305 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf303, buf304, out=buf305)
buf306 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf300, buf306, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf307 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf305, buf307, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf310 = reinterpret_tensor(buf304, (4, 4, 1), (4, 1, 16), 0)
del buf304
triton_poi_fused_bmm_6[grid(16)](buf296, buf310, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf311 = reinterpret_tensor(buf303, (4, 1, 4), (4, 16, 1), 0)
del buf303
triton_poi_fused_bmm_6[grid(16)](buf297, buf311, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf312 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf310, buf311, out=buf312)
buf313 = reinterpret_tensor(buf311, (4, 4, 1), (4, 1, 16), 0)
del buf311
triton_poi_fused_bmm_6[grid(16)](buf301, buf313, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf314 = reinterpret_tensor(buf310, (4, 1, 4), (4, 16, 1), 0)
del buf310
triton_poi_fused_bmm_6[grid(16)](buf302, buf314, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf315 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf313, buf314, out=buf315)
buf316 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf312, buf316, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf317 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf315, buf317, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf318 = buf271
del buf271
triton_poi_fused_cat_21[grid(32)](buf306, buf308, buf316, buf318,
32, XBLOCK=32, num_warps=1, num_stages=1)
buf319 = buf204
del buf204
triton_poi_fused_cat_21[grid(32)](buf307, buf309, buf317, buf319,
32, XBLOCK=32, num_warps=1, num_stages=1)
buf320 = reinterpret_tensor(buf314, (4, 4, 1), (4, 1, 16), 0)
del buf314
triton_poi_fused_bmm_9[grid(16)](buf296, buf320, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf321 = reinterpret_tensor(buf313, (4, 1, 4), (4, 16, 1), 0)
del buf313
triton_poi_fused_bmm_9[grid(16)](buf297, buf321, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf322 = buf317
del buf317
extern_kernels.bmm(buf320, buf321, out=buf322)
buf323 = reinterpret_tensor(buf321, (4, 4, 1), (4, 1, 16), 0)
del buf321
triton_poi_fused_bmm_9[grid(16)](buf301, buf323, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf324 = reinterpret_tensor(buf320, (4, 1, 4), (4, 16, 1), 0)
del buf320
triton_poi_fused_bmm_9[grid(16)](buf302, buf324, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf325 = buf307
del buf307
extern_kernels.bmm(buf323, buf324, out=buf325)
buf326 = buf316
del buf316
triton_poi_fused__softmax_5[grid(64)](buf322, buf326, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf327 = buf306
del buf306
triton_poi_fused__softmax_5[grid(64)](buf325, buf327, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf328 = buf276
del buf276
triton_poi_fused_cat_22[grid(48)](buf318, buf326, buf308, buf328,
48, XBLOCK=64, num_warps=1, num_stages=1)
buf329 = buf214
del buf214
triton_poi_fused_cat_22[grid(48)](buf319, buf327, buf309, buf329,
48, XBLOCK=64, num_warps=1, num_stages=1)
buf330 = reinterpret_tensor(buf324, (4, 4, 1), (4, 1, 16), 0)
del buf324
triton_poi_fused_bmm_12[grid(16)](buf296, buf330, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf331 = reinterpret_tensor(buf323, (4, 1, 4), (4, 16, 1), 0)
del buf323
triton_poi_fused_bmm_12[grid(16)](buf297, buf331, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf332 = buf327
del buf327
extern_kernels.bmm(buf330, buf331, out=buf332)
buf333 = reinterpret_tensor(buf331, (4, 4, 1), (4, 1, 16), 0)
del buf331
triton_poi_fused_bmm_12[grid(16)](buf301, buf333, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf334 = reinterpret_tensor(buf330, (4, 1, 4), (4, 16, 1), 0)
del buf330
triton_poi_fused_bmm_12[grid(16)](buf302, buf334, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf335 = buf326
del buf326
extern_kernels.bmm(buf333, buf334, out=buf335)
buf336 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf332, buf336, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf337 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf335, buf337, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf338 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf340 = buf338
del buf338
triton_poi_fused_add_cat_23[grid(64)](buf340, buf328, buf336,
buf308, buf290, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf339 = buf336
del buf336
buf342 = buf339
del buf339
triton_poi_fused_add_cat_23[grid(64)](buf342, buf329, buf337,
buf309, buf292, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf341 = reinterpret_tensor(buf337, (16, 4), (4, 1), 0)
del buf337
extern_kernels.mm(reinterpret_tensor(buf340, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_27, (4, 4), (1, 4), 0), out=buf341)
buf343 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf342, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_29, (4, 4), (1, 4), 0), out=buf343)
buf344 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf397 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
buf396 = reinterpret_tensor(buf397, (4, 4, 4), (32, 8, 1), 0)
triton_poi_fused_add_cat_relu_24[grid(64)](buf341, primals_28,
buf284, primals_18, buf230, buf344, buf396, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf345 = empty_strided_cuda((16, 8), (8, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf344, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_7, (4, 8), (1, 4), 0), out=buf345)
buf346 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf370 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
buf369 = reinterpret_tensor(buf370, (4, 4, 4), (32, 8, 1), 0)
triton_poi_fused_add_cat_relu_25[grid(64)](buf343, primals_30,
buf258, buf232, buf346, buf369, 64, XBLOCK=64, num_warps=1,
num_stages=1)
buf347 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf346, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_9, (4, 4), (1, 4), 0), out=buf347)
buf348 = reinterpret_tensor(buf347, (4, 4, 4), (16, 4, 1), 0)
del buf347
buf470 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_1[grid(64)](buf348,
primals_10, buf470, 64, XBLOCK=64, num_warps=1, num_stages=1)
del primals_10
buf349 = reinterpret_tensor(buf345, (4, 4, 8), (32, 8, 1), 0)
del buf345
buf471 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_2[grid(128)](buf349,
primals_8, buf471, 128, XBLOCK=128, num_warps=4, num_stages=1)
del primals_8
buf350 = reinterpret_tensor(buf334, (4, 4, 1), (4, 1, 16), 0)
del buf334
triton_poi_fused_bmm_3[grid(16)](buf348, buf350, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf351 = reinterpret_tensor(buf333, (4, 1, 4), (4, 16, 1), 0)
del buf333
triton_poi_fused_bmm_4[grid(16)](buf349, buf351, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf352 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf350, buf351, out=buf352)
buf353 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf352, buf353, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf354 = reinterpret_tensor(buf351, (4, 4, 1), (4, 1, 16), 0)
del buf351
triton_poi_fused_bmm_6[grid(16)](buf348, buf354, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf355 = reinterpret_tensor(buf350, (4, 1, 4), (4, 16, 1), 0)
del buf350
triton_poi_fused_bmm_7[grid(16)](buf349, buf355, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf356 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf354, buf355, out=buf356)
buf357 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf356, buf357, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf358 = buf319
del buf319
triton_poi_fused_cat_8[grid(32)](buf353, buf349, buf357, buf358, 32,
XBLOCK=32, num_warps=1, num_stages=1)
buf359 = reinterpret_tensor(buf355, (4, 4, 1), (4, 1, 16), 0)
del buf355
triton_poi_fused_bmm_9[grid(16)](buf348, buf359, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf360 = reinterpret_tensor(buf354, (4, 1, 4), (4, 16, 1), 0)
del buf354
triton_poi_fused_bmm_10[grid(16)](buf349, buf360, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf361 = buf357
del buf357
extern_kernels.bmm(buf359, buf360, out=buf361)
buf362 = buf353
del buf353
triton_poi_fused__softmax_5[grid(64)](buf361, buf362, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf363 = buf329
del buf329
triton_poi_fused_cat_11[grid(48)](buf358, buf362, buf349, buf363,
48, XBLOCK=64, num_warps=1, num_stages=1)
buf364 = reinterpret_tensor(buf360, (4, 4, 1), (4, 1, 16), 0)
del buf360
triton_poi_fused_bmm_12[grid(16)](buf348, buf364, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf365 = reinterpret_tensor(buf359, (4, 1, 4), (4, 16, 1), 0)
del buf359
triton_poi_fused_bmm_13[grid(16)](buf349, buf365, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf366 = buf362
del buf362
extern_kernels.bmm(buf364, buf365, out=buf366)
buf367 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf366, buf367, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf368 = reinterpret_tensor(buf370, (4, 4, 4), (32, 8, 1), 4)
triton_poi_fused_cat_14[grid(64)](buf363, buf367, buf349, buf368,
64, XBLOCK=64, num_warps=1, num_stages=1)
buf371 = reinterpret_tensor(buf367, (16, 4), (4, 1), 0)
del buf367
extern_kernels.mm(reinterpret_tensor(buf370, (16, 8), (8, 1), 0),
reinterpret_tensor(primals_11, (8, 4), (1, 8), 0), out=buf371)
buf372 = reinterpret_tensor(buf371, (4, 4, 4), (16, 4, 1), 0)
del buf371
buf406 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_relu_15[grid(64)](buf372, primals_12, buf346,
buf406, 64, XBLOCK=64, num_warps=1, num_stages=1)
del primals_12
buf373 = empty_strided_cuda((16, 8), (8, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf372, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_13, (4, 8), (1, 4), 0), out=buf373)
buf374 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf344, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_15, (4, 4), (1, 4), 0), out=buf374)
buf375 = reinterpret_tensor(buf374, (4, 4, 4), (16, 4, 1), 0)
del buf374
buf467 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_1[grid(64)](buf375,
primals_16, buf467, 64, XBLOCK=64, num_warps=1, num_stages=1)
del primals_16
buf376 = reinterpret_tensor(buf373, (4, 4, 8), (32, 8, 1), 0)
del buf373
buf468 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_2[grid(128)](buf376,
primals_14, buf468, 128, XBLOCK=128, num_warps=4, num_stages=1)
del primals_14
buf377 = reinterpret_tensor(buf365, (4, 4, 1), (4, 1, 16), 0)
del buf365
triton_poi_fused_bmm_3[grid(16)](buf375, buf377, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf378 = reinterpret_tensor(buf364, (4, 1, 4), (4, 16, 1), 0)
del buf364
triton_poi_fused_bmm_4[grid(16)](buf376, buf378, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf379 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf377, buf378, out=buf379)
buf380 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf379, buf380, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf381 = reinterpret_tensor(buf378, (4, 4, 1), (4, 1, 16), 0)
del buf378
triton_poi_fused_bmm_6[grid(16)](buf375, buf381, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf382 = reinterpret_tensor(buf377, (4, 1, 4), (4, 16, 1), 0)
del buf377
triton_poi_fused_bmm_7[grid(16)](buf376, buf382, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf383 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf381, buf382, out=buf383)
buf384 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf383, buf384, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf385 = buf358
del buf358
triton_poi_fused_cat_8[grid(32)](buf380, buf376, buf384, buf385, 32,
XBLOCK=32, num_warps=1, num_stages=1)
buf386 = reinterpret_tensor(buf382, (4, 4, 1), (4, 1, 16), 0)
del buf382
triton_poi_fused_bmm_9[grid(16)](buf375, buf386, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf387 = reinterpret_tensor(buf381, (4, 1, 4), (4, 16, 1), 0)
del buf381
triton_poi_fused_bmm_10[grid(16)](buf376, buf387, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf388 = buf384
del buf384
extern_kernels.bmm(buf386, buf387, out=buf388)
buf389 = buf380
del buf380
triton_poi_fused__softmax_5[grid(64)](buf388, buf389, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf390 = buf363
del buf363
triton_poi_fused_cat_11[grid(48)](buf385, buf389, buf376, buf390,
48, XBLOCK=64, num_warps=1, num_stages=1)
buf391 = reinterpret_tensor(buf387, (4, 4, 1), (4, 1, 16), 0)
del buf387
triton_poi_fused_bmm_12[grid(16)](buf375, buf391, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf392 = reinterpret_tensor(buf386, (4, 1, 4), (4, 16, 1), 0)
del buf386
triton_poi_fused_bmm_13[grid(16)](buf376, buf392, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf393 = buf389
del buf389
extern_kernels.bmm(buf391, buf392, out=buf393)
buf394 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf393, buf394, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf395 = reinterpret_tensor(buf397, (4, 4, 4), (32, 8, 1), 4)
triton_poi_fused_cat_14[grid(64)](buf390, buf394, buf376, buf395,
64, XBLOCK=64, num_warps=1, num_stages=1)
buf398 = reinterpret_tensor(buf394, (16, 4), (4, 1), 0)
del buf394
extern_kernels.mm(reinterpret_tensor(buf397, (16, 8), (8, 1), 0),
reinterpret_tensor(primals_17, (8, 4), (1, 8), 0), out=buf398)
buf399 = reinterpret_tensor(buf392, (4, 4), (4, 1), 0)
del buf392
buf400 = buf399
del buf399
triton_poi_fused_add_div_relu_sum_16[grid(16)](buf400, buf398,
primals_18, buf344, 16, XBLOCK=16, num_warps=1, num_stages=1)
buf401 = reinterpret_tensor(buf391, (4, 4), (4, 1), 0)
del buf391
triton_poi_fused_add_div_sum_17[grid(16)](buf372, buf346, buf401,
16, XBLOCK=16, num_warps=1, num_stages=1)
buf402 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_20, buf400, reinterpret_tensor(
primals_19, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf402)
del primals_20
buf403 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_22, buf401, reinterpret_tensor(
primals_21, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf403)
del primals_22
buf404 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_relu_18[grid(64)](buf398, primals_18, buf344,
buf404, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf405 = empty_strided_cuda((16, 12), (12, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf404, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_23, (4, 12), (1, 4), 0), out=buf405)
buf407 = empty_strided_cuda((16, 12), (12, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf406, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_25, (4, 12), (1, 4), 0), out=buf407)
buf408 = reinterpret_tensor(buf405, (4, 4, 12), (48, 12, 1), 0)
del buf405
buf465 = empty_strided_cuda((4, 4, 12), (48, 12, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_19[grid(192)](buf408,
primals_24, buf465, 192, XBLOCK=128, num_warps=4, num_stages=1)
del primals_24
buf409 = reinterpret_tensor(buf407, (4, 4, 12), (48, 12, 1), 0)
del buf407
buf464 = empty_strided_cuda((4, 4, 12), (48, 12, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_19[grid(192)](buf409,
primals_26, buf464, 192, XBLOCK=128, num_warps=4, num_stages=1)
del primals_26
buf410 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf411 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf422 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_mul_20[grid(64)](buf403, buf408, buf410,
buf411, buf422, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf412 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
triton_poi_fused_bmm_3[grid(16)](buf410, buf412, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf413 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32)
triton_poi_fused_bmm_3[grid(16)](buf411, buf413, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf414 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf412, buf413, out=buf414)
buf415 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf416 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf423 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_mul_20[grid(64)](buf402, buf409, buf415,
buf416, buf423, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf417 = reinterpret_tensor(buf413, (4, 4, 1), (4, 1, 16), 0)
del buf413
triton_poi_fused_bmm_3[grid(16)](buf415, buf417, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf418 = reinterpret_tensor(buf412, (4, 1, 4), (4, 16, 1), 0)
del buf412
triton_poi_fused_bmm_3[grid(16)](buf416, buf418, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf419 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf417, buf418, out=buf419)
buf420 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf414, buf420, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf421 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf419, buf421, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf424 = reinterpret_tensor(buf418, (4, 4, 1), (4, 1, 16), 0)
del buf418
triton_poi_fused_bmm_6[grid(16)](buf410, buf424, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf425 = reinterpret_tensor(buf417, (4, 1, 4), (4, 16, 1), 0)
del buf417
triton_poi_fused_bmm_6[grid(16)](buf411, buf425, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf426 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf424, buf425, out=buf426)
buf427 = reinterpret_tensor(buf425, (4, 4, 1), (4, 1, 16), 0)
del buf425
triton_poi_fused_bmm_6[grid(16)](buf415, buf427, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf428 = reinterpret_tensor(buf424, (4, 1, 4), (4, 16, 1), 0)
del buf424
triton_poi_fused_bmm_6[grid(16)](buf416, buf428, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf429 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf427, buf428, out=buf429)
buf430 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf426, buf430, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf431 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf429, buf431, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf432 = buf385
del buf385
triton_poi_fused_cat_21[grid(32)](buf420, buf422, buf430, buf432,
32, XBLOCK=32, num_warps=1, num_stages=1)
buf433 = buf318
del buf318
triton_poi_fused_cat_21[grid(32)](buf421, buf423, buf431, buf433,
32, XBLOCK=32, num_warps=1, num_stages=1)
buf434 = reinterpret_tensor(buf428, (4, 4, 1), (4, 1, 16), 0)
del buf428
triton_poi_fused_bmm_9[grid(16)](buf410, buf434, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf435 = reinterpret_tensor(buf427, (4, 1, 4), (4, 16, 1), 0)
del buf427
triton_poi_fused_bmm_9[grid(16)](buf411, buf435, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf436 = buf431
del buf431
extern_kernels.bmm(buf434, buf435, out=buf436)
buf437 = reinterpret_tensor(buf435, (4, 4, 1), (4, 1, 16), 0)
del buf435
triton_poi_fused_bmm_9[grid(16)](buf415, buf437, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf438 = reinterpret_tensor(buf434, (4, 1, 4), (4, 16, 1), 0)
del buf434
triton_poi_fused_bmm_9[grid(16)](buf416, buf438, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf439 = buf421
del buf421
extern_kernels.bmm(buf437, buf438, out=buf439)
buf440 = buf430
del buf430
triton_poi_fused__softmax_5[grid(64)](buf436, buf440, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf441 = buf420
del buf420
triton_poi_fused__softmax_5[grid(64)](buf439, buf441, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf442 = buf390
del buf390
triton_poi_fused_cat_22[grid(48)](buf432, buf440, buf422, buf442,
48, XBLOCK=64, num_warps=1, num_stages=1)
del buf432
buf443 = buf328
del buf328
triton_poi_fused_cat_22[grid(48)](buf433, buf441, buf423, buf443,
48, XBLOCK=64, num_warps=1, num_stages=1)
del buf433
buf444 = reinterpret_tensor(buf438, (4, 4, 1), (4, 1, 16), 0)
del buf438
triton_poi_fused_bmm_12[grid(16)](buf410, buf444, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf445 = reinterpret_tensor(buf437, (4, 1, 4), (4, 16, 1), 0)
del buf437
triton_poi_fused_bmm_12[grid(16)](buf411, buf445, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf446 = buf441
del buf441
extern_kernels.bmm(buf444, buf445, out=buf446)
buf447 = reinterpret_tensor(buf445, (4, 4, 1), (4, 1, 16), 0)
del buf445
triton_poi_fused_bmm_12[grid(16)](buf415, buf447, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf448 = reinterpret_tensor(buf444, (4, 1, 4), (4, 16, 1), 0)
del buf444
triton_poi_fused_bmm_12[grid(16)](buf416, buf448, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf449 = buf440
del buf440
extern_kernels.bmm(buf447, buf448, out=buf449)
del buf447
del buf448
buf450 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf446, buf450, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf451 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_5[grid(64)](buf449, buf451, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf452 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf454 = buf452
del buf452
triton_poi_fused_add_cat_23[grid(64)](buf454, buf442, buf450,
buf422, buf404, 64, XBLOCK=64, num_warps=1, num_stages=1)
del buf442
buf453 = buf450
del buf450
buf456 = buf453
del buf453
triton_poi_fused_add_cat_23[grid(64)](buf456, buf443, buf451,
buf423, buf406, 64, XBLOCK=64, num_warps=1, num_stages=1)
del buf443
buf455 = reinterpret_tensor(buf451, (16, 4), (4, 1), 0)
del buf451
extern_kernels.mm(reinterpret_tensor(buf454, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_27, (4, 4), (1, 4), 0), out=buf455)
buf457 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf456, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_29, (4, 4), (1, 4), 0), out=buf457)
buf458 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
buf459 = buf458
del buf458
buf463 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
buf466 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
buf473 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
buf476 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
buf483 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
buf486 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
buf493 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
buf496 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
buf503 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
triton_poi_fused_add_relu_threshold_backward_26[grid(64)](buf459,
buf2, buf56, primals_18, buf113, primals_28, buf170, buf227,
buf284, buf341, buf398, buf455, buf463, buf466, buf473, buf476,
buf483, buf486, buf493, buf496, buf503, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del buf113
del buf170
del buf227
del buf284
del buf341
del buf398
del buf455
del primals_18
del primals_28
buf460 = reinterpret_tensor(buf56, (4, 4, 4), (16, 4, 1), 0)
del buf56
buf461 = buf460
del buf460
buf462 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
buf472 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
buf482 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
buf492 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
buf469 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
buf479 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
buf489 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
buf499 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
buf502 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
triton_poi_fused_add_relu_threshold_backward_27[grid(64)](buf461,
buf4, buf30, buf115, primals_30, buf144, buf229, buf258, buf343,
buf372, buf457, buf462, buf472, buf482, buf492, buf469, buf479,
buf489, buf499, buf502, 64, XBLOCK=64, num_warps=1, num_stages=1)
del buf115
del buf229
del buf343
del buf457
del primals_30
return (buf459, buf461, reinterpret_tensor(primals_3, (16, 4), (4, 1),
0), reinterpret_tensor(primals_6, (16, 4), (4, 1), 0),
reinterpret_tensor(buf2, (16, 4), (4, 1), 0), reinterpret_tensor(
buf4, (16, 4), (4, 1), 0), buf10, reinterpret_tensor(buf7, (4, 1, 4,
1), (32, 32, 8, 1), 4), buf14, reinterpret_tensor(buf7, (4, 1, 4, 1
), (32, 32, 8, 1), 5), buf19, reinterpret_tensor(buf7, (4, 1, 4, 1),
(32, 32, 8, 1), 6), buf24, reinterpret_tensor(buf7, (4, 1, 4, 1), (
32, 32, 8, 1), 7), reinterpret_tensor(buf28, (16, 8), (8, 1), 0),
reinterpret_tensor(buf30, (16, 4), (4, 1), 0), buf37,
reinterpret_tensor(buf34, (4, 1, 4, 1), (32, 32, 8, 1), 4), buf41,
reinterpret_tensor(buf34, (4, 1, 4, 1), (32, 32, 8, 1), 5), buf46,
reinterpret_tensor(buf34, (4, 1, 4, 1), (32, 32, 8, 1), 6), buf51,
reinterpret_tensor(buf34, (4, 1, 4, 1), (32, 32, 8, 1), 7),
reinterpret_tensor(buf55, (16, 8), (8, 1), 0), buf58, buf59, buf60,
buf61, reinterpret_tensor(buf62, (16, 4), (4, 1), 0),
reinterpret_tensor(buf64, (16, 4), (4, 1), 0), reinterpret_tensor(
buf66, (4, 4, 4), (48, 12, 1), 0), reinterpret_tensor(buf66, (4, 4,
4), (48, 12, 1), 4), reinterpret_tensor(buf66, (4, 4, 4), (48, 12,
1), 8), reinterpret_tensor(buf67, (4, 4, 4), (48, 12, 1), 0),
reinterpret_tensor(buf67, (4, 4, 4), (48, 12, 1), 4),
reinterpret_tensor(buf67, (4, 4, 4), (48, 12, 1), 8), buf72, buf77,
reinterpret_tensor(buf80, (4, 1, 4, 1), (16, 16, 4, 1), 0),
reinterpret_tensor(buf81, (4, 1, 4, 1), (16, 16, 4, 1), 0), buf84,
buf87, reinterpret_tensor(buf80, (4, 1, 4, 1), (16, 16, 4, 1), 1),
reinterpret_tensor(buf81, (4, 1, 4, 1), (16, 16, 4, 1), 1), buf94,
buf97, reinterpret_tensor(buf80, (4, 1, 4, 1), (16, 16, 4, 1), 2),
reinterpret_tensor(buf81, (4, 1, 4, 1), (16, 16, 4, 1), 2), buf104,
buf107, reinterpret_tensor(buf80, (4, 1, 4, 1), (16, 16, 4, 1), 3),
reinterpret_tensor(buf81, (4, 1, 4, 1), (16, 16, 4, 1), 3),
reinterpret_tensor(buf112, (16, 4), (4, 1), 0), reinterpret_tensor(
buf114, (16, 4), (4, 1), 0), reinterpret_tensor(buf116, (16, 4), (4,
1), 0), reinterpret_tensor(buf118, (16, 4), (4, 1), 0), buf124,
reinterpret_tensor(buf121, (4, 1, 4, 1), (32, 32, 8, 1), 4), buf128,
reinterpret_tensor(buf121, (4, 1, 4, 1), (32, 32, 8, 1), 5), buf133,
reinterpret_tensor(buf121, (4, 1, 4, 1), (32, 32, 8, 1), 6), buf138,
reinterpret_tensor(buf121, (4, 1, 4, 1), (32, 32, 8, 1), 7),
reinterpret_tensor(buf142, (16, 8), (8, 1), 0), reinterpret_tensor(
buf144, (16, 4), (4, 1), 0), buf151, reinterpret_tensor(buf148, (4,
1, 4, 1), (32, 32, 8, 1), 4), buf155, reinterpret_tensor(buf148, (4,
1, 4, 1), (32, 32, 8, 1), 5), buf160, reinterpret_tensor(buf148, (4,
1, 4, 1), (32, 32, 8, 1), 6), buf165, reinterpret_tensor(buf148, (4,
1, 4, 1), (32, 32, 8, 1), 7), reinterpret_tensor(buf169, (16, 8), (
8, 1), 0), buf172, buf173, buf174, buf175, reinterpret_tensor(
buf176, (16, 4), (4, 1), 0), reinterpret_tensor(buf178, (16, 4), (4,
1), 0), reinterpret_tensor(buf180, (4, 4, 4), (48, 12, 1), 0),
reinterpret_tensor(buf180, (4, 4, 4), (48, 12, 1), 4),
reinterpret_tensor(buf180, (4, 4, 4), (48, 12, 1), 8),
reinterpret_tensor(buf181, (4, 4, 4), (48, 12, 1), 0),
reinterpret_tensor(buf181, (4, 4, 4), (48, 12, 1), 4),
reinterpret_tensor(buf181, (4, 4, 4), (48, 12, 1), 8), buf186,
buf191, reinterpret_tensor(buf194, (4, 1, 4, 1), (16, 16, 4, 1), 0),
reinterpret_tensor(buf195, (4, 1, 4, 1), (16, 16, 4, 1), 0), buf198,
buf201, reinterpret_tensor(buf194, (4, 1, 4, 1), (16, 16, 4, 1), 1),
reinterpret_tensor(buf195, (4, 1, 4, 1), (16, 16, 4, 1), 1), buf208,
buf211, reinterpret_tensor(buf194, (4, 1, 4, 1), (16, 16, 4, 1), 2),
reinterpret_tensor(buf195, (4, 1, 4, 1), (16, 16, 4, 1), 2), buf218,
buf221, reinterpret_tensor(buf194, (4, 1, 4, 1), (16, 16, 4, 1), 3),
reinterpret_tensor(buf195, (4, 1, 4, 1), (16, 16, 4, 1), 3),
reinterpret_tensor(buf226, (16, 4), (4, 1), 0), reinterpret_tensor(
buf228, (16, 4), (4, 1), 0), reinterpret_tensor(buf230, (16, 4), (4,
1), 0), reinterpret_tensor(buf232, (16, 4), (4, 1), 0), buf238,
reinterpret_tensor(buf235, (4, 1, 4, 1), (32, 32, 8, 1), 4), buf242,
reinterpret_tensor(buf235, (4, 1, 4, 1), (32, 32, 8, 1), 5), buf247,
reinterpret_tensor(buf235, (4, 1, 4, 1), (32, 32, 8, 1), 6), buf252,
reinterpret_tensor(buf235, (4, 1, 4, 1), (32, 32, 8, 1), 7),
reinterpret_tensor(buf256, (16, 8), (8, 1), 0), reinterpret_tensor(
buf258, (16, 4), (4, 1), 0), buf265, reinterpret_tensor(buf262, (4,
1, 4, 1), (32, 32, 8, 1), 4), buf269, reinterpret_tensor(buf262, (4,
1, 4, 1), (32, 32, 8, 1), 5), buf274, reinterpret_tensor(buf262, (4,
1, 4, 1), (32, 32, 8, 1), 6), buf279, reinterpret_tensor(buf262, (4,
1, 4, 1), (32, 32, 8, 1), 7), reinterpret_tensor(buf283, (16, 8), (
8, 1), 0), buf286, buf287, buf288, buf289, reinterpret_tensor(
buf290, (16, 4), (4, 1), 0), reinterpret_tensor(buf292, (16, 4), (4,
1), 0), reinterpret_tensor(buf294, (4, 4, 4), (48, 12, 1), 0),
reinterpret_tensor(buf294, (4, 4, 4), (48, 12, 1), 4),
reinterpret_tensor(buf294, (4, 4, 4), (48, 12, 1), 8),
reinterpret_tensor(buf295, (4, 4, 4), (48, 12, 1), 0),
reinterpret_tensor(buf295, (4, 4, 4), (48, 12, 1), 4),
reinterpret_tensor(buf295, (4, 4, 4), (48, 12, 1), 8), buf300,
buf305, reinterpret_tensor(buf308, (4, 1, 4, 1), (16, 16, 4, 1), 0),
reinterpret_tensor(buf309, (4, 1, 4, 1), (16, 16, 4, 1), 0), buf312,
buf315, reinterpret_tensor(buf308, (4, 1, 4, 1), (16, 16, 4, 1), 1),
reinterpret_tensor(buf309, (4, 1, 4, 1), (16, 16, 4, 1), 1), buf322,
buf325, reinterpret_tensor(buf308, (4, 1, 4, 1), (16, 16, 4, 1), 2),
reinterpret_tensor(buf309, (4, 1, 4, 1), (16, 16, 4, 1), 2), buf332,
buf335, reinterpret_tensor(buf308, (4, 1, 4, 1), (16, 16, 4, 1), 3),
reinterpret_tensor(buf309, (4, 1, 4, 1), (16, 16, 4, 1), 3),
reinterpret_tensor(buf340, (16, 4), (4, 1), 0), reinterpret_tensor(
buf342, (16, 4), (4, 1), 0), reinterpret_tensor(buf344, (16, 4), (4,
1), 0), reinterpret_tensor(buf346, (16, 4), (4, 1), 0), buf352,
reinterpret_tensor(buf349, (4, 1, 4, 1), (32, 32, 8, 1), 4), buf356,
reinterpret_tensor(buf349, (4, 1, 4, 1), (32, 32, 8, 1), 5), buf361,
reinterpret_tensor(buf349, (4, 1, 4, 1), (32, 32, 8, 1), 6), buf366,
reinterpret_tensor(buf349, (4, 1, 4, 1), (32, 32, 8, 1), 7),
reinterpret_tensor(buf370, (16, 8), (8, 1), 0), reinterpret_tensor(
buf372, (16, 4), (4, 1), 0), buf379, reinterpret_tensor(buf376, (4,
1, 4, 1), (32, 32, 8, 1), 4), buf383, reinterpret_tensor(buf376, (4,
1, 4, 1), (32, 32, 8, 1), 5), buf388, reinterpret_tensor(buf376, (4,
1, 4, 1), (32, 32, 8, 1), 6), buf393, reinterpret_tensor(buf376, (4,
1, 4, 1), (32, 32, 8, 1), 7), reinterpret_tensor(buf397, (16, 8), (
8, 1), 0), buf400, buf401, buf402, buf403, reinterpret_tensor(
buf404, (16, 4), (4, 1), 0), reinterpret_tensor(buf406, (16, 4), (4,
1), 0), reinterpret_tensor(buf408, (4, 4, 4), (48, 12, 1), 0),
reinterpret_tensor(buf408, (4, 4, 4), (48, 12, 1), 4),
reinterpret_tensor(buf408, (4, 4, 4), (48, 12, 1), 8),
reinterpret_tensor(buf409, (4, 4, 4), (48, 12, 1), 0),
reinterpret_tensor(buf409, (4, 4, 4), (48, 12, 1), 4),
reinterpret_tensor(buf409, (4, 4, 4), (48, 12, 1), 8), buf414,
buf419, reinterpret_tensor(buf422, (4, 1, 4, 1), (16, 16, 4, 1), 0),
reinterpret_tensor(buf423, (4, 1, 4, 1), (16, 16, 4, 1), 0), buf426,
buf429, reinterpret_tensor(buf422, (4, 1, 4, 1), (16, 16, 4, 1), 1),
reinterpret_tensor(buf423, (4, 1, 4, 1), (16, 16, 4, 1), 1), buf436,
buf439, reinterpret_tensor(buf422, (4, 1, 4, 1), (16, 16, 4, 1), 2),
reinterpret_tensor(buf423, (4, 1, 4, 1), (16, 16, 4, 1), 2), buf446,
buf449, reinterpret_tensor(buf422, (4, 1, 4, 1), (16, 16, 4, 1), 3),
reinterpret_tensor(buf423, (4, 1, 4, 1), (16, 16, 4, 1), 3),
reinterpret_tensor(buf454, (16, 4), (4, 1), 0), reinterpret_tensor(
buf456, (16, 4), (4, 1), 0), buf462, primals_29, buf463, primals_27,
reinterpret_tensor(buf415, (4, 1, 4), (16, 1, 4), 3),
reinterpret_tensor(buf416, (4, 4, 1), (16, 4, 1), 3),
reinterpret_tensor(buf410, (4, 1, 4), (16, 1, 4), 3),
reinterpret_tensor(buf411, (4, 4, 1), (16, 4, 1), 3),
reinterpret_tensor(buf415, (4, 1, 4), (16, 1, 4), 2),
reinterpret_tensor(buf416, (4, 4, 1), (16, 4, 1), 2),
reinterpret_tensor(buf410, (4, 1, 4), (16, 1, 4), 2),
reinterpret_tensor(buf411, (4, 4, 1), (16, 4, 1), 2),
reinterpret_tensor(buf415, (4, 1, 4), (16, 1, 4), 1),
reinterpret_tensor(buf416, (4, 4, 1), (16, 4, 1), 1),
reinterpret_tensor(buf410, (4, 1, 4), (16, 1, 4), 1),
reinterpret_tensor(buf411, (4, 4, 1), (16, 4, 1), 1),
reinterpret_tensor(buf415, (4, 1, 4), (16, 1, 4), 0),
reinterpret_tensor(buf416, (4, 4, 1), (16, 4, 1), 0),
reinterpret_tensor(buf410, (4, 1, 4), (16, 1, 4), 0),
reinterpret_tensor(buf411, (4, 4, 1), (16, 4, 1), 0), buf464,
primals_25, buf465, primals_23, primals_21, primals_19, buf466,
primals_17, reinterpret_tensor(buf375, (4, 1, 4), (16, 1, 4), 3),
reinterpret_tensor(buf376, (4, 4, 1), (32, 8, 1), 3),
reinterpret_tensor(buf375, (4, 1, 4), (16, 1, 4), 2),
reinterpret_tensor(buf376, (4, 4, 1), (32, 8, 1), 2),
reinterpret_tensor(buf375, (4, 1, 4), (16, 1, 4), 1),
reinterpret_tensor(buf376, (4, 4, 1), (32, 8, 1), 1),
reinterpret_tensor(buf375, (4, 1, 4), (16, 1, 4), 0),
reinterpret_tensor(buf376, (4, 4, 1), (32, 8, 1), 0), buf467,
primals_15, buf468, primals_13, buf469, primals_11,
reinterpret_tensor(buf348, (4, 1, 4), (16, 1, 4), 3),
reinterpret_tensor(buf349, (4, 4, 1), (32, 8, 1), 3),
reinterpret_tensor(buf348, (4, 1, 4), (16, 1, 4), 2),
reinterpret_tensor(buf349, (4, 4, 1), (32, 8, 1), 2),
reinterpret_tensor(buf348, (4, 1, 4), (16, 1, 4), 1),
reinterpret_tensor(buf349, (4, 4, 1), (32, 8, 1), 1),
reinterpret_tensor(buf348, (4, 1, 4), (16, 1, 4), 0),
reinterpret_tensor(buf349, (4, 4, 1), (32, 8, 1), 0), buf470,
primals_9, buf471, primals_7, buf472, buf473, reinterpret_tensor(
buf301, (4, 1, 4), (16, 1, 4), 3), reinterpret_tensor(buf302, (4, 4,
1), (16, 4, 1), 3), reinterpret_tensor(buf296, (4, 1, 4), (16, 1, 4
), 3), reinterpret_tensor(buf297, (4, 4, 1), (16, 4, 1), 3),
reinterpret_tensor(buf301, (4, 1, 4), (16, 1, 4), 2),
reinterpret_tensor(buf302, (4, 4, 1), (16, 4, 1), 2),
reinterpret_tensor(buf296, (4, 1, 4), (16, 1, 4), 2),
reinterpret_tensor(buf297, (4, 4, 1), (16, 4, 1), 2),
reinterpret_tensor(buf301, (4, 1, 4), (16, 1, 4), 1),
reinterpret_tensor(buf302, (4, 4, 1), (16, 4, 1), 1),
reinterpret_tensor(buf296, (4, 1, 4), (16, 1, 4), 1),
reinterpret_tensor(buf297, (4, 4, 1), (16, 4, 1), 1),
reinterpret_tensor(buf301, (4, 1, 4), (16, 1, 4), 0),
reinterpret_tensor(buf302, (4, 4, 1), (16, 4, 1), 0),
reinterpret_tensor(buf296, (4, 1, 4), (16, 1, 4), 0),
reinterpret_tensor(buf297, (4, 4, 1), (16, 4, 1), 0), buf474,
buf475, buf476, reinterpret_tensor(buf261, (4, 1, 4), (16, 1, 4), 3
), reinterpret_tensor(buf262, (4, 4, 1), (32, 8, 1), 3),
reinterpret_tensor(buf261, (4, 1, 4), (16, 1, 4), 2),
reinterpret_tensor(buf262, (4, 4, 1), (32, 8, 1), 2),
reinterpret_tensor(buf261, (4, 1, 4), (16, 1, 4), 1),
reinterpret_tensor(buf262, (4, 4, 1), (32, 8, 1), 1),
reinterpret_tensor(buf261, (4, 1, 4), (16, 1, 4), 0),
reinterpret_tensor(buf262, (4, 4, 1), (32, 8, 1), 0), buf477,
buf478, buf479, reinterpret_tensor(buf234, (4, 1, 4), (16, 1, 4), 3
), reinterpret_tensor(buf235, (4, 4, 1), (32, 8, 1), 3),
reinterpret_tensor(buf234, (4, 1, 4), (16, 1, 4), 2),
reinterpret_tensor(buf235, (4, 4, 1), (32, 8, 1), 2),
reinterpret_tensor(buf234, (4, 1, 4), (16, 1, 4), 1),
reinterpret_tensor(buf235, (4, 4, 1), (32, 8, 1), 1),
reinterpret_tensor(buf234, (4, 1, 4), (16, 1, 4), 0),
reinterpret_tensor(buf235, (4, 4, 1), (32, 8, 1), 0), buf480,
buf481, buf482, buf483, reinterpret_tensor(buf187, (4, 1, 4), (16,
1, 4), 3), reinterpret_tensor(buf188, (4, 4, 1), (16, 4, 1), 3),
reinterpret_tensor(buf182, (4, 1, 4), (16, 1, 4), 3),
reinterpret_tensor(buf183, (4, 4, 1), (16, 4, 1), 3),
reinterpret_tensor(buf187, (4, 1, 4), (16, 1, 4), 2),
reinterpret_tensor(buf188, (4, 4, 1), (16, 4, 1), 2),
reinterpret_tensor(buf182, (4, 1, 4), (16, 1, 4), 2),
reinterpret_tensor(buf183, (4, 4, 1), (16, 4, 1), 2),
reinterpret_tensor(buf187, (4, 1, 4), (16, 1, 4), 1),
reinterpret_tensor(buf188, (4, 4, 1), (16, 4, 1), 1),
reinterpret_tensor(buf182, (4, 1, 4), (16, 1, 4), 1),
reinterpret_tensor(buf183, (4, 4, 1), (16, 4, 1), 1),
reinterpret_tensor(buf187, (4, 1, 4), (16, 1, 4), 0),
reinterpret_tensor(buf188, (4, 4, 1), (16, 4, 1), 0),
reinterpret_tensor(buf182, (4, 1, 4), (16, 1, 4), 0),
reinterpret_tensor(buf183, (4, 4, 1), (16, 4, 1), 0), buf484,
buf485, buf486, reinterpret_tensor(buf147, (4, 1, 4), (16, 1, 4), 3
), reinterpret_tensor(buf148, (4, 4, 1), (32, 8, 1), 3),
reinterpret_tensor(buf147, (4, 1, 4), (16, 1, 4), 2),
reinterpret_tensor(buf148, (4, 4, 1), (32, 8, 1), 2),
reinterpret_tensor(buf147, (4, 1, 4), (16, 1, 4), 1),
reinterpret_tensor(buf148, (4, 4, 1), (32, 8, 1), 1),
reinterpret_tensor(buf147, (4, 1, 4), (16, 1, 4), 0),
reinterpret_tensor(buf148, (4, 4, 1), (32, 8, 1), 0), buf487,
buf488, buf489, reinterpret_tensor(buf120, (4, 1, 4), (16, 1, 4), 3
), reinterpret_tensor(buf121, (4, 4, 1), (32, 8, 1), 3),
reinterpret_tensor(buf120, (4, 1, 4), (16, 1, 4), 2),
reinterpret_tensor(buf121, (4, 4, 1), (32, 8, 1), 2),
reinterpret_tensor(buf120, (4, 1, 4), (16, 1, 4), 1),
reinterpret_tensor(buf121, (4, 4, 1), (32, 8, 1), 1),
reinterpret_tensor(buf120, (4, 1, 4), (16, 1, 4), 0),
reinterpret_tensor(buf121, (4, 4, 1), (32, 8, 1), 0), buf490,
buf491, buf492, buf493, reinterpret_tensor(buf73, (4, 1, 4), (16, 1,
4), 3), reinterpret_tensor(buf74, (4, 4, 1), (16, 4, 1), 3),
reinterpret_tensor(buf68, (4, 1, 4), (16, 1, 4), 3),
reinterpret_tensor(buf69, (4, 4, 1), (16, 4, 1), 3),
reinterpret_tensor(buf73, (4, 1, 4), (16, 1, 4), 2),
reinterpret_tensor(buf74, (4, 4, 1), (16, 4, 1), 2),
reinterpret_tensor(buf68, (4, 1, 4), (16, 1, 4), 2),
reinterpret_tensor(buf69, (4, 4, 1), (16, 4, 1), 2),
reinterpret_tensor(buf73, (4, 1, 4), (16, 1, 4), 1),
reinterpret_tensor(buf74, (4, 4, 1), (16, 4, 1), 1),
reinterpret_tensor(buf68, (4, 1, 4), (16, 1, 4), 1),
reinterpret_tensor(buf69, (4, 4, 1), (16, 4, 1), 1),
reinterpret_tensor(buf73, (4, 1, 4), (16, 1, 4), 0),
reinterpret_tensor(buf74, (4, 4, 1), (16, 4, 1), 0),
reinterpret_tensor(buf68, (4, 1, 4), (16, 1, 4), 0),
reinterpret_tensor(buf69, (4, 4, 1), (16, 4, 1), 0), buf494, buf495,
buf496, reinterpret_tensor(buf33, (4, 1, 4), (16, 1, 4), 3),
reinterpret_tensor(buf34, (4, 4, 1), (32, 8, 1), 3),
reinterpret_tensor(buf33, (4, 1, 4), (16, 1, 4), 2),
reinterpret_tensor(buf34, (4, 4, 1), (32, 8, 1), 2),
reinterpret_tensor(buf33, (4, 1, 4), (16, 1, 4), 1),
reinterpret_tensor(buf34, (4, 4, 1), (32, 8, 1), 1),
reinterpret_tensor(buf33, (4, 1, 4), (16, 1, 4), 0),
reinterpret_tensor(buf34, (4, 4, 1), (32, 8, 1), 0), buf497, buf498,
buf499, reinterpret_tensor(buf6, (4, 1, 4), (16, 1, 4), 3),
reinterpret_tensor(buf7, (4, 4, 1), (32, 8, 1), 3),
reinterpret_tensor(buf6, (4, 1, 4), (16, 1, 4), 2),
reinterpret_tensor(buf7, (4, 4, 1), (32, 8, 1), 2),
reinterpret_tensor(buf6, (4, 1, 4), (16, 1, 4), 1),
reinterpret_tensor(buf7, (4, 4, 1), (32, 8, 1), 1),
reinterpret_tensor(buf6, (4, 1, 4), (16, 1, 4), 0),
reinterpret_tensor(buf7, (4, 4, 1), (32, 8, 1), 0), buf500, buf501,
buf502, buf503)
class FCNet(nn.Module):
def __init__(self, in_size, out_size, activate=None, drop=0.0):
super(FCNet, self).__init__()
self.lin = nn.Linear(in_size, out_size)
self.drop_value = drop
self.drop = nn.Dropout(drop)
self.activate = activate.lower() if activate is not None else None
if activate == 'relu':
self.ac_fn = nn.ReLU()
elif activate == 'sigmoid':
self.ac_fn = nn.Sigmoid()
elif activate == 'tanh':
self.ac_fn = nn.Tanh()
def forward(self, x):
if self.drop_value > 0:
x = self.drop(x)
x = self.lin(x)
if self.activate is not None:
x = self.ac_fn(x)
return x
class OneSideInterModalityUpdate(nn.Module):
"""
one-side Inter-Modality Attention Flow
according to the paper, instead of parallel V->Q & Q->V, we first to V->Q and then Q->V
"""
def __init__(self, src_size, tgt_size, output_size, num_head, drop=0.0):
super(OneSideInterModalityUpdate, self).__init__()
self.src_size = src_size
self.tgt_size = tgt_size
self.output_size = output_size
self.num_head = num_head
self.src_lin = FCNet(src_size, output_size * 2, drop=drop, activate
='relu')
self.tgt_lin = FCNet(tgt_size, output_size, drop=drop, activate='relu')
self.tgt_output = FCNet(output_size + tgt_size, output_size, drop=
drop, activate='relu')
def forward(self, src, tgt):
"""
:param src: eeg feature [batch, regions, feature_size]
:param tgt: eye feature [batch, regions, feature_size]
:return:
"""
_batch_size, _num_src = src.shape[0], src.shape[1]
tgt.shape[1]
src_tran = self.src_lin(src)
tgt_tran = self.tgt_lin(tgt)
src_key, src_val = torch.split(src_tran, src_tran.size(2) // 2, dim=2)
tgt_query = tgt_tran
src_key_set = torch.split(src_key, src_key.size(2) // self.num_head,
dim=2)
src_val_set = torch.split(src_val, src_val.size(2) // self.num_head,
dim=2)
tgt_query_set = torch.split(tgt_query, tgt_query.size(2) // self.
num_head, dim=2)
for i in range(self.num_head):
src_key_slice, tgt_query_slice, src_val_slice = src_key_set[i
], tgt_query_set[i], src_val_set[i]
src2tgt = tgt_query_slice @ src_key_slice.transpose(1, 2) / (self
.output_size // self.num_head) ** 0.5
interMAF_src2tgt = F.softmax(src2tgt, dim=2).unsqueeze(3)
tgt_update = (interMAF_src2tgt * src_val_slice.unsqueeze(1)).sum(2
) if i == 0 else torch.cat((tgt_update, (interMAF_src2tgt *
src_val_slice.unsqueeze(1)).sum(2)), dim=2)
cat_tgt = torch.cat((tgt, tgt_update), dim=2)
tgt_updated = self.tgt_output(cat_tgt)
return tgt_updated
class DyIntraModalityUpdate(nn.Module):
"""
Dynamic Intra-Modality Attention Flow
"""
def __init__(self, v_size, q_size, output_size, num_head, drop=0.0):
super(DyIntraModalityUpdate, self).__init__()
self.v_size = v_size
self.q_size = q_size
self.output_size = output_size
self.num_head = num_head
self.v4q_gate_lin = FCNet(v_size, output_size, drop=drop)
self.q4v_gate_lin = FCNet(q_size, output_size, drop=drop)
self.v_lin = FCNet(v_size, output_size * 3, drop=drop, activate='relu')
self.q_lin = FCNet(q_size, output_size * 3, drop=drop, activate='relu')
self.v_output = FCNet(output_size, output_size, drop=drop, activate
='relu')
self.q_output = FCNet(output_size, output_size, drop=drop, activate
='relu')
self.relu = nn.ReLU()
self.tanh = nn.Tanh()
self.sigmoid = nn.Sigmoid()
def forward(self, v, q):
"""
:param v: [batch_size, num_obj, feature_size]
:param q: [batch_size, max_len, feature_size]
:return:
"""
_batch_size, num_obj = v.shape[0], v.shape[1]
max_len = q.shape[1]
v_mean = v.sum(1) / num_obj
q_mean = q.sum(1) / max_len
v4q_gate = self.sigmoid(self.v4q_gate_lin(v_mean)).unsqueeze(1)
q4v_gate = self.sigmoid(self.q4v_gate_lin(q_mean)).unsqueeze(1)
v_tran = self.v_lin(v)
q_tran = self.q_lin(q)
v_key, v_query, v_val = torch.split(v_tran, v_tran.size(2) // 3, dim=2)
q_key, q_query, q_val = torch.split(q_tran, q_tran.size(2) // 3, dim=2)
gated_v_query = (1 + q4v_gate) * v_query
gated_v_key = (1 + q4v_gate) * v_key
gated_v_val = (1 + q4v_gate) * v_val
gated_q_query = (1 + v4q_gate) * q_query
gated_q_key = (1 + v4q_gate) * q_key
gated_q_val = (1 + v4q_gate) * q_val
v_key_set = torch.split(gated_v_key, gated_v_key.size(2) // self.
num_head, dim=2)
v_query_set = torch.split(gated_v_query, gated_v_query.size(2) //
self.num_head, dim=2)
v_val_set = torch.split(gated_v_val, gated_v_val.size(2) // self.
num_head, dim=2)
q_key_set = torch.split(gated_q_key, gated_q_key.size(2) // self.
num_head, dim=2)
q_query_set = torch.split(gated_q_query, gated_q_query.size(2) //
self.num_head, dim=2)
q_val_set = torch.split(gated_q_val, gated_q_val.size(2) // self.
num_head, dim=2)
for i in range(self.num_head):
v_key_slice, v_query_slice, v_val_slice = v_key_set[i
], v_query_set[i], v_val_set[i]
q_key_slice, q_query_slice, q_val_slice = q_key_set[i
], q_query_set[i], q_val_set[i]
v2v = v_query_slice @ v_key_slice.transpose(1, 2) / (self.
output_size // self.num_head) ** 0.5
q2q = q_query_slice @ q_key_slice.transpose(1, 2) / (self.
output_size // self.num_head) ** 0.5
dyIntranMAF_v2v = F.softmax(v2v, dim=2).unsqueeze(3)
dyIntranMAF_q2q = F.softmax(q2q, dim=2).unsqueeze(3)
v_update = (dyIntranMAF_v2v * v_val_slice.unsqueeze(1)).sum(2
) if i == 0 else torch.cat((v_update, (dyIntranMAF_v2v *
v_val_slice.unsqueeze(1)).sum(2)), dim=2)
q_update = (dyIntranMAF_q2q * q_val_slice.unsqueeze(1)).sum(2
) if i == 0 else torch.cat((q_update, (dyIntranMAF_q2q *
q_val_slice.unsqueeze(1)).sum(2)), dim=2)
updated_v = self.v_output(v + v_update)
updated_q = self.q_output(q + q_update)
return updated_v, updated_q
class SingleBlockNew(nn.Module):
"""
Single Block Inter- and Intra modality stack multiple times, in such circumstance, all the
basic blocks share the same parameters in the model
"""
def __init__(self, num_blocks, v_size, q_size, output_size,
num_inter_head, num_intra_head, drop=0.0):
super(SingleBlockNew, self).__init__()
self.v_size = v_size
self.q_size = q_size
self.output_size = output_size
self.num_inter_head = num_inter_head
self.num_intra_head = num_intra_head
self.num_block = num_blocks
self.v_lin = FCNet(v_size, output_size, drop=drop, activate='relu')
self.q_lin = FCNet(q_size, output_size, drop=drop, activate='relu')
self.v2q_interBlock = OneSideInterModalityUpdate(output_size,
output_size, output_size, num_inter_head, drop)
self.q2v_interBlock = OneSideInterModalityUpdate(output_size,
output_size, output_size, num_inter_head, drop)
self.intraBlock = DyIntraModalityUpdate(output_size, output_size,
output_size, num_intra_head, drop)
def forward(self, input_0, input_1):
primals_1 = self.v_lin.lin.weight
primals_2 = self.v_lin.lin.bias
primals_4 = self.q_lin.lin.weight
primals_5 = self.q_lin.lin.bias
primals_7 = self.v2q_interBlock.src_lin.lin.weight
primals_8 = self.v2q_interBlock.src_lin.lin.bias
primals_9 = self.v2q_interBlock.tgt_lin.lin.weight
primals_10 = self.v2q_interBlock.tgt_lin.lin.bias
primals_11 = self.v2q_interBlock.tgt_output.lin.weight
primals_12 = self.v2q_interBlock.tgt_output.lin.bias
primals_13 = self.q2v_interBlock.src_lin.lin.weight
primals_14 = self.q2v_interBlock.src_lin.lin.bias
primals_15 = self.q2v_interBlock.tgt_lin.lin.weight
primals_16 = self.q2v_interBlock.tgt_lin.lin.bias
primals_17 = self.q2v_interBlock.tgt_output.lin.weight
primals_18 = self.q2v_interBlock.tgt_output.lin.bias
primals_19 = self.intraBlock.v4q_gate_lin.lin.weight
primals_20 = self.intraBlock.v4q_gate_lin.lin.bias
primals_21 = self.intraBlock.q4v_gate_lin.lin.weight
primals_22 = self.intraBlock.q4v_gate_lin.lin.bias
primals_23 = self.intraBlock.v_lin.lin.weight
primals_24 = self.intraBlock.v_lin.lin.bias
primals_25 = self.intraBlock.q_lin.lin.weight
primals_26 = self.intraBlock.q_lin.lin.bias
primals_27 = self.intraBlock.v_output.lin.weight
primals_28 = self.intraBlock.v_output.lin.bias
primals_29 = self.intraBlock.q_output.lin.weight
primals_30 = self.intraBlock.q_output.lin.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, primals_23, primals_24,
primals_25, primals_26, primals_27, primals_28, primals_29,
primals_30])
return output[0], output[1]
|
Ruiver/CTCNet
|
SingleBlock
| false
| 17,954
|
[
"Apache-2.0"
] | 6
|
539e55ec9fed06028379d35dfd5cd4074755ffd8
|
https://github.com/Ruiver/CTCNet/tree/539e55ec9fed06028379d35dfd5cd4074755ffd8
|
Subtract
|
import torch
import torch.nn
import torch.utils.data
import torch.utils.tensorboard._pytorch_graph
import torch.onnx.symbolic_caffe2
class Subtract(torch.nn.Module):
""" Subtract module for a functional subtract"""
def forward(self, x, y):
"""
Forward-pass routine for subtact op
"""
return x - y
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn
import torch.utils.data
import torch.utils.tensorboard._pytorch_graph
import torch.onnx.symbolic_caffe2
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_sub_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask)
tmp2 = tmp0 - tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_sub_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 SubtractNew(torch.nn.Module):
""" Subtract module for a functional subtract"""
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
Rohan-Chaudhury/aimet
|
Subtract
| false
| 17,955
|
[
"BSD-3-Clause"
] | 3
|
1c38cac8cc0fd32dca40ce5e39940805d29f7a4a
|
https://github.com/Rohan-Chaudhury/aimet/tree/1c38cac8cc0fd32dca40ce5e39940805d29f7a4a
|
SpectralConvergence
|
import torch
import torch.nn as nn
import torch.utils.data
class SpectralConvergence(nn.Module):
def __init__(self):
"""Initilize spectral convergence loss module."""
super().__init__()
def forward(self, predicts_mag, targets_mag):
"""Calculate norm of difference operator.
Args:
predicts_mag (Tensor): Magnitude spectrogram of predicted signal (B, #frames, #freq_bins).
targets_mag (Tensor): Magnitude spectrogram of groundtruth signal (B, #frames, #freq_bins).
Returns:
Tensor: Spectral convergence loss value.
"""
return torch.mean(torch.norm(targets_mag - predicts_mag, dim=(1, 2),
p='fro') / torch.norm(targets_mag, dim=(1, 2), p='fro'))
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.nn as nn
import torch.utils.data
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_linalg_vector_norm_sub_0(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r2 = rindex
x0 = xindex % 4
x1 = xindex // 4
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4 * r2 + 64 * x1), xmask, other=0.0)
tmp1 = tl.load(in_ptr1 + (x0 + 4 * r2 + 64 * x1), xmask, other=0.0)
tmp2 = tmp0 - tmp1
tmp3 = tmp2 * tmp2
tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
tmp6 = tl.where(xmask, tmp4, 0)
tmp7 = tl.sum(tmp6, 1)[:, None]
tmp8 = tmp0 * tmp0
tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK])
tmp11 = tl.where(xmask, tmp9, 0)
tmp12 = tl.sum(tmp11, 1)[:, None]
tl.store(out_ptr0 + x3, tmp7, xmask)
tl.store(out_ptr1 + x3, tmp12, xmask)
@triton.jit
def triton_per_fused_div_linalg_vector_norm_mean_1(in_out_ptr0, in_ptr0,
in_ptr1, 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 = libdevice.sqrt(tmp0)
tmp3 = libdevice.sqrt(tmp2)
tmp4 = tmp1 / tmp3
tmp5 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK])
tmp7 = tl.sum(tmp5, 1)[:, None]
tmp8 = 16.0
tmp9 = tmp7 / tmp8
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp9, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
get_raw_stream(0)
triton_per_fused_linalg_vector_norm_sub_0[grid(16)](arg0_1, arg1_1,
buf0, buf1, 16, 16, XBLOCK=1, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
buf2 = empty_strided_cuda((), (), torch.float32)
buf3 = buf2
del buf2
triton_per_fused_div_linalg_vector_norm_mean_1[grid(1)](buf3, buf0,
buf1, 1, 16, XBLOCK=1, num_warps=2, num_stages=1)
del buf0
del buf1
return buf3,
class SpectralConvergenceNew(nn.Module):
def __init__(self):
"""Initilize spectral convergence loss module."""
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]
|
SolomidHero/speech-regeneration-enhancer
|
SpectralConvergence
| false
| 17,956
|
[
"MIT"
] | 8
|
eb43907ff085d68a707ff7bc3af14e93ff66fd65
|
https://github.com/SolomidHero/speech-regeneration-enhancer/tree/eb43907ff085d68a707ff7bc3af14e93ff66fd65
|
GumbelSoftmaxLayer
|
import torch
import torch.nn as nn
from torch.distributions import RelaxedOneHotCategorical
import torch.nn.parallel
import torch.utils.data
import torch.distributions
def gumbel_softmax_sample(logits: 'torch.Tensor', temperature: 'float'=1.0,
training: 'bool'=True, straight_through: 'bool'=False):
size = logits.size()
if not training:
indexes = logits.argmax(dim=-1)
one_hot = torch.zeros_like(logits).view(-1, size[-1])
one_hot.scatter_(1, indexes.view(-1, 1), 1)
one_hot = one_hot.view(*size)
return one_hot
sample = RelaxedOneHotCategorical(logits=logits, temperature=temperature
).rsample()
if straight_through:
size = sample.size()
indexes = sample.argmax(dim=-1)
hard_sample = torch.zeros_like(sample).view(-1, size[-1])
hard_sample.scatter_(1, indexes.view(-1, 1), 1)
hard_sample = hard_sample.view(*size)
sample = sample + (hard_sample - sample).detach()
return sample
class GumbelSoftmaxLayer(nn.Module):
def __init__(self, temperature: 'float'=1.0, trainable_temperature:
'bool'=False, straight_through: 'bool'=False):
super(GumbelSoftmaxLayer, self).__init__()
self.straight_through = straight_through
if not trainable_temperature:
self.temperature = temperature
else:
self.temperature = torch.nn.Parameter(torch.tensor([temperature
]), requires_grad=True)
def forward(self, logits: 'torch.Tensor'):
return gumbel_softmax_sample(logits, self.temperature, self.
training, self.straight_through)
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
from torch.distributions import RelaxedOneHotCategorical
import torch.nn.parallel
import torch.utils.data
import torch.distributions
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_argmax_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')
tmp17 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp32 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
)
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)
@triton.jit
def triton_poi_fused_scatter_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
x1 = xindex // 4
x0 = xindex % 4
x4 = xindex
tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp1 = x0
tmp2 = tmp0 == tmp1
tmp3 = 1.0
tmp4 = 0.0
tmp5 = tl.where(tmp2, tmp3, tmp4)
tl.store(in_out_ptr0 + x4, tmp5, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.int64)
get_raw_stream(0)
triton_poi_fused_argmax_0[grid(64)](arg0_1, buf0, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del arg0_1
buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
buf2 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf1
triton_poi_fused_scatter_1[grid(256)](buf2, buf0, 256, XBLOCK=128,
num_warps=4, num_stages=1)
del buf0
return buf2,
def gumbel_softmax_sample(logits: 'torch.Tensor', temperature: 'float'=1.0,
training: 'bool'=True, straight_through: 'bool'=False):
size = logits.size()
if not training:
indexes = logits.argmax(dim=-1)
one_hot = torch.zeros_like(logits).view(-1, size[-1])
one_hot.scatter_(1, indexes.view(-1, 1), 1)
one_hot = one_hot.view(*size)
return one_hot
sample = RelaxedOneHotCategorical(logits=logits, temperature=temperature
).rsample()
if straight_through:
size = sample.size()
indexes = sample.argmax(dim=-1)
hard_sample = torch.zeros_like(sample).view(-1, size[-1])
hard_sample.scatter_(1, indexes.view(-1, 1), 1)
hard_sample = hard_sample.view(*size)
sample = sample + (hard_sample - sample).detach()
return sample
class GumbelSoftmaxLayerNew(nn.Module):
def __init__(self, temperature: 'float'=1.0, trainable_temperature:
'bool'=False, straight_through: 'bool'=False):
super(GumbelSoftmaxLayerNew, self).__init__()
self.straight_through = straight_through
if not trainable_temperature:
self.temperature = temperature
else:
self.temperature = torch.nn.Parameter(torch.tensor([temperature
]), requires_grad=True)
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
Slowika/GameBias-EmeCom2020
|
GumbelSoftmaxLayer
| false
| 17,957
|
[
"MIT"
] | 5
|
5b94c47559f8202bca99c26fc1bcb078dd0509a6
|
https://github.com/Slowika/GameBias-EmeCom2020/tree/5b94c47559f8202bca99c26fc1bcb078dd0509a6
|
Hsigmoid
|
import torch
import torch.nn as nn
from torch.quantization import QuantStub
from torch.quantization import DeQuantStub
class Hsigmoid(nn.Module):
def __init__(self, add_stub=False):
super().__init__()
self.quant = QuantStub()
self.dequant = DeQuantStub()
self.add_stub = add_stub
self.hsigmoid = nn.Hardsigmoid()
def forward(self, x):
if self.add_stub:
x = self.quant(x)
x = self.hsigmoid(x)
if self.add_stub:
x = self.dequant(x)
return x
def fuse_model(self):
pass
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
from torch.quantization import QuantStub
from torch.quantization import DeQuantStub
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_hardsigmoid_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 3.0
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = triton_helpers.maximum(tmp2, tmp3)
tmp5 = 6.0
tmp6 = triton_helpers.minimum(tmp4, tmp5)
tmp7 = 0.16666666666666666
tmp8 = tmp6 * tmp7
tl.store(out_ptr0 + x0, tmp8, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_hardsigmoid_0[grid(256)](arg0_1, buf0, 256, XBLOCK
=256, num_warps=4, num_stages=1)
del arg0_1
return buf0,
class HsigmoidNew(nn.Module):
def __init__(self, add_stub=False):
super().__init__()
self.quant = QuantStub()
self.dequant = DeQuantStub()
self.add_stub = add_stub
self.hsigmoid = nn.Hardsigmoid()
def fuse_model(self):
pass
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
T-head-Semi/tvm
|
Hsigmoid
| false
| 17,958
|
[
"Apache-2.0"
] | 4
|
c1b8e06685c92fb7cacbe989e147b0622aee4503
|
https://github.com/T-head-Semi/tvm/tree/c1b8e06685c92fb7cacbe989e147b0622aee4503
|
_TestNetStrided
|
import torch
import torch.nn.functional as F
import torch.nn
import torch.utils.data
import torch.utils.tensorboard._pytorch_graph
import torch.onnx.symbolic_caffe2
class _TestNetStrided(torch.nn.Module):
def __init__(self):
super(_TestNetStrided, self).__init__()
self.conv1 = torch.nn.Conv2d(1, 20, kernel_size=5)
self.conv2 = torch.nn.Conv2d(20, 50, kernel_size=5, stride=(2, 2))
self.fc1 = torch.nn.Linear(200, 500)
self.fc2 = torch.nn.Linear(500, 10)
def forward(self, x):
x = F.relu(F.max_pool2d(self.conv1(x), 2))
x = F.relu(F.max_pool2d(self.conv2(x), 2))
x = x.view(-1, 200)
x = F.relu(self.fc1(x))
x = self.fc2(x)
return F.log_softmax(x, dim=1)
def get_inputs():
return [torch.rand([4, 1, 64, 64])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn
import torch.utils.data
import torch.utils.tensorboard._pytorch_graph
import torch.onnx.symbolic_caffe2
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 = 288000
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 3600 % 20
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, xnumel, XBLOCK: tl.constexpr):
xnumel = 72000
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 30
x3 = xindex // 30
x2 = xindex // 18000
x4 = xindex % 18000
x5 = xindex
tmp0 = tl.load(in_ptr0 + (2 * x0 + 120 * x3), xmask, eviction_policy=
'evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 120 * x3), xmask,
eviction_policy='evict_last')
tmp7 = tl.load(in_ptr0 + (60 + 2 * x0 + 120 * x3), xmask,
eviction_policy='evict_last')
tmp12 = tl.load(in_ptr0 + (61 + 2 * x0 + 120 * x3), xmask,
eviction_policy='evict_last')
tmp2 = tmp1 > tmp0
tmp3 = tl.full([1], 1, tl.int8)
tmp4 = tl.full([1], 0, tl.int8)
tmp5 = tl.where(tmp2, tmp3, tmp4)
tmp6 = triton_helpers.maximum(tmp1, tmp0)
tmp8 = tmp7 > tmp6
tmp9 = tl.full([1], 2, tl.int8)
tmp10 = tl.where(tmp8, tmp9, tmp5)
tmp11 = triton_helpers.maximum(tmp7, tmp6)
tmp13 = tmp12 > tmp11
tmp14 = tl.full([1], 3, tl.int8)
tmp15 = tl.where(tmp13, tmp14, tmp10)
tmp16 = triton_helpers.maximum(tmp12, tmp11)
tmp17 = tl.full([1], 0, tl.int32)
tmp18 = triton_helpers.maximum(tmp17, tmp16)
tl.store(out_ptr0 + (x4 + 18048 * x2), tmp15, xmask)
tl.store(out_ptr1 + x5, tmp18, xmask)
@triton.jit
def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 33800
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 169 % 50
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_threshold_backward_3(in_ptr0,
out_ptr0, out_ptr1, out_ptr2, xnumel, XBLOCK: tl.constexpr):
xnumel = 7200
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 6
x1 = xindex // 6 % 6
x5 = xindex // 36
x3 = xindex // 1800
x4 = xindex % 1800
tmp0 = tl.load(in_ptr0 + (2 * x0 + 26 * x1 + 169 * x5), xmask,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 26 * x1 + 169 * x5), xmask,
eviction_policy='evict_last')
tmp7 = tl.load(in_ptr0 + (13 + 2 * x0 + 26 * x1 + 169 * x5), xmask,
eviction_policy='evict_last')
tmp12 = tl.load(in_ptr0 + (14 + 2 * x0 + 26 * x1 + 169 * x5), 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)
tmp17 = tl.full([1], 0, tl.int32)
tmp18 = triton_helpers.maximum(tmp17, tmp16)
tmp19 = 0.0
tmp20 = tmp18 <= tmp19
tl.store(out_ptr0 + (x4 + 1920 * x3), tmp15, xmask)
tl.store(out_ptr1 + (x4 + 1824 * x3), tmp18, xmask)
tl.store(out_ptr2 + (x4 + 1920 * x3), tmp20, xmask)
@triton.jit
def triton_poi_fused_max_pool2d_with_indices_relu_view_4(in_ptr0, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 7200
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + (1824 * (x0 // 1800) + x0 % 1800), xmask)
tl.store(out_ptr0 + x0, tmp0, xmask)
@triton.jit
def triton_poi_fused_relu_5(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 18000
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 500
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x2, tmp4, xmask)
@triton.jit
def triton_per_fused__log_softmax_6(in_ptr0, out_ptr2, xnumel, rnumel,
XBLOCK: tl.constexpr):
xnumel = 36
rnumel = 10
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
rmask = rindex < rnumel
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 10 * x0), rmask & xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(rmask & xmask, tmp1, float('-inf'))
tmp4 = triton_helpers.max2(tmp3, 1)[:, None]
tmp5 = tmp0 - tmp4
tmp6 = tl_math.exp(tmp5)
tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
tmp9 = tl.where(rmask & xmask, tmp7, 0)
tmp10 = tl.sum(tmp9, 1)[:, None]
tmp11 = tl_math.log(tmp10)
tmp12 = tmp5 - tmp11
tl.store(out_ptr2 + (r1 + 10 * x0), tmp12, rmask & xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9) = args
args.clear()
assert_size_stride(primals_1, (20, 1, 5, 5), (25, 25, 5, 1))
assert_size_stride(primals_2, (20,), (1,))
assert_size_stride(primals_3, (4, 1, 64, 64), (4096, 4096, 64, 1))
assert_size_stride(primals_4, (50, 20, 5, 5), (500, 25, 5, 1))
assert_size_stride(primals_5, (50,), (1,))
assert_size_stride(primals_6, (500, 200), (200, 1))
assert_size_stride(primals_7, (500,), (1,))
assert_size_stride(primals_8, (10, 500), (500, 1))
assert_size_stride(primals_9, (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, 20, 60, 60), (72000, 3600, 60, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(288000)](buf1, primals_2,
288000, XBLOCK=512, num_warps=8, num_stages=1)
del primals_2
buf2 = empty_strided_cuda((4, 20, 30, 30), (18048, 900, 30, 1),
torch.int8)
buf3 = empty_strided_cuda((4, 20, 30, 30), (18000, 900, 30, 1),
torch.float32)
triton_poi_fused_max_pool2d_with_indices_relu_1[grid(72000)](buf1,
buf2, buf3, 72000, XBLOCK=512, num_warps=8, num_stages=1)
buf4 = extern_kernels.convolution(buf3, primals_4, stride=(2, 2),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 50, 13, 13), (8450, 169, 13, 1))
buf5 = buf4
del buf4
triton_poi_fused_convolution_2[grid(33800)](buf5, primals_5, 33800,
XBLOCK=512, num_warps=4, num_stages=1)
del primals_5
buf6 = empty_strided_cuda((4, 50, 6, 6), (1920, 36, 6, 1), torch.int8)
buf7 = empty_strided_cuda((4, 50, 6, 6), (1824, 36, 6, 1), torch.
float32)
buf15 = empty_strided_cuda((4, 50, 6, 6), (1920, 36, 6, 1), torch.bool)
triton_poi_fused_max_pool2d_with_indices_relu_threshold_backward_3[grid
(7200)](buf5, buf6, buf7, buf15, 7200, XBLOCK=128, num_warps=4,
num_stages=1)
buf8 = empty_strided_cuda((36, 200), (200, 1), torch.float32)
triton_poi_fused_max_pool2d_with_indices_relu_view_4[grid(7200)](buf7,
buf8, 7200, XBLOCK=256, num_warps=4, num_stages=1)
del buf7
buf9 = empty_strided_cuda((36, 500), (500, 1), torch.float32)
extern_kernels.mm(buf8, reinterpret_tensor(primals_6, (200, 500), (
1, 200), 0), out=buf9)
buf10 = buf9
del buf9
triton_poi_fused_relu_5[grid(18000)](buf10, primals_7, 18000,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_7
buf11 = empty_strided_cuda((36, 10), (10, 1), torch.float32)
extern_kernels.addmm(primals_9, buf10, reinterpret_tensor(primals_8,
(500, 10), (1, 500), 0), alpha=1, beta=1, out=buf11)
del primals_9
buf14 = empty_strided_cuda((36, 10), (10, 1), torch.float32)
triton_per_fused__log_softmax_6[grid(36)](buf11, buf14, 36, 10,
XBLOCK=32, num_warps=4, num_stages=1)
del buf11
return (buf14, primals_1, primals_3, primals_4, buf1, buf2, buf3, buf5,
buf6, buf8, buf10, buf14, primals_8, primals_6, buf15)
class _TestNetStridedNew(torch.nn.Module):
def __init__(self):
super(_TestNetStridedNew, self).__init__()
self.conv1 = torch.nn.Conv2d(1, 20, kernel_size=5)
self.conv2 = torch.nn.Conv2d(20, 50, kernel_size=5, stride=(2, 2))
self.fc1 = torch.nn.Linear(200, 500)
self.fc2 = torch.nn.Linear(500, 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_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]
|
Rohan-Chaudhury/aimet
|
_TestNetStrided
| false
| 17,959
|
[
"BSD-3-Clause"
] | 3
|
1c38cac8cc0fd32dca40ce5e39940805d29f7a4a
|
https://github.com/Rohan-Chaudhury/aimet/tree/1c38cac8cc0fd32dca40ce5e39940805d29f7a4a
|
Divide
|
import torch
import torch.nn
import torch.utils.data
import torch.utils.tensorboard._pytorch_graph
import torch.onnx.symbolic_caffe2
class Divide(torch.nn.Module):
""" Divide module for a functional divide"""
def forward(self, x, y):
"""
Forward-pass routine for divide op
"""
return torch.div(x, y)
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn
import torch.utils.data
import torch.utils.tensorboard._pytorch_graph
import torch.onnx.symbolic_caffe2
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_div_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask)
tmp2 = tmp0 / tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_div_0[grid(256)](arg1_1, arg0_1, buf0, 256, XBLOCK
=128, num_warps=4, num_stages=1)
del arg0_1
del arg1_1
return buf0,
class DivideNew(torch.nn.Module):
""" Divide module for a functional divide"""
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
Rohan-Chaudhury/aimet
|
Divide
| false
| 17,960
|
[
"BSD-3-Clause"
] | 3
|
1c38cac8cc0fd32dca40ce5e39940805d29f7a4a
|
https://github.com/Rohan-Chaudhury/aimet/tree/1c38cac8cc0fd32dca40ce5e39940805d29f7a4a
|
Hswish
|
import torch
import torch.nn as nn
from torch.quantization import QuantStub
from torch.quantization import DeQuantStub
class Hswish(nn.Module):
def __init__(self, add_stub=False):
super().__init__()
self.quant = QuantStub()
self.dequant = DeQuantStub()
self.add_stub = add_stub
self.hswish = nn.Hardswish()
def forward(self, x):
if self.add_stub:
x = self.quant(x)
x = self.hswish(x)
if self.add_stub:
x = self.dequant(x)
return x
def fuse_model(self):
pass
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
from torch.quantization import QuantStub
from torch.quantization import DeQuantStub
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_hardswish_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 3.0
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = triton_helpers.maximum(tmp2, tmp3)
tmp5 = 6.0
tmp6 = triton_helpers.minimum(tmp4, tmp5)
tmp7 = tmp0 * tmp6
tmp8 = 0.16666666666666666
tmp9 = tmp7 * tmp8
tl.store(out_ptr0 + x0, tmp9, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_hardswish_0[grid(256)](arg0_1, buf0, 256, XBLOCK=
256, num_warps=4, num_stages=1)
del arg0_1
return buf0,
class HswishNew(nn.Module):
def __init__(self, add_stub=False):
super().__init__()
self.quant = QuantStub()
self.dequant = DeQuantStub()
self.add_stub = add_stub
self.hswish = nn.Hardswish()
def fuse_model(self):
pass
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
T-head-Semi/tvm
|
Hswish
| false
| 17,961
|
[
"Apache-2.0"
] | 4
|
c1b8e06685c92fb7cacbe989e147b0622aee4503
|
https://github.com/T-head-Semi/tvm/tree/c1b8e06685c92fb7cacbe989e147b0622aee4503
|
VirtualBatchNormNN
|
from torch.nn import Module
import torch
import torch.utils
import torch.utils.data
from torch.nn.parameter import Parameter
from torch.nn.modules import Module
class VirtualBatchNormNN(Module):
"""
Module for Virtual Batch Normalization.
Implementation borrowed and modified from Rafael_Valle's code + help of SimonW from this discussion thread:
https://discuss.pytorch.org/t/parameter-grad-of-conv-weight-is-none-after-virtual-batch-normalization/9036
"""
def __init__(self, num_features: 'int', eps: 'float'=1e-05):
super().__init__()
self.num_features = num_features
self.eps = eps
self.ref_mean = self.register_parameter('ref_mean', None)
self.ref_mean_sq = self.register_parameter('ref_mean_sq', None)
gamma = torch.normal(mean=torch.ones(1, num_features), std=0.02)
self.gamma = Parameter(gamma.float())
self.beta = Parameter(torch.FloatTensor(1, num_features).fill_(0))
def get_stats(self, x):
"""
Calculates mean and mean square for given batch x.
Args:
x: tensor containing batch of activations
Returns:
mean: mean tensor over features
mean_sq: squared mean tensor over features
"""
mean = x.mean(0, keepdim=True)
mean_sq = (x ** 2).mean(0, keepdim=True)
return mean, mean_sq
def forward(self, x, ref_mean: 'None', ref_mean_sq: 'None'):
"""
Forward pass of virtual batch normalization.
Virtual batch normalization require two forward passes
for reference batch and train batch, respectively.
The input parameter is_reference should indicate whether it is a forward pass
for reference batch or not.
Args:
x: input tensor
is_reference(bool): True if forwarding for reference batch
Result:
x: normalized batch tensor
"""
mean, mean_sq = self.get_stats(x)
if ref_mean is None or ref_mean_sq is None:
mean = mean.clone().detach()
mean_sq = mean_sq.clone().detach()
out = self._normalize(x, mean, mean_sq)
else:
batch_size = x.size(0)
new_coeff = 1.0 / (batch_size + 1.0)
old_coeff = 1.0 - new_coeff
mean = new_coeff * mean + old_coeff * ref_mean
mean_sq = new_coeff * mean_sq + old_coeff * ref_mean_sq
out = self._normalize(x, mean, mean_sq)
return out, mean, mean_sq
def _normalize(self, x, mean, mean_sq):
"""
Normalize tensor x given the statistics.
Args:
x: input tensor
mean: mean over features. it has size [1:num_features:]
mean_sq: squared means over features.
Result:
x: normalized batch tensor
"""
assert mean_sq is not None
assert mean is not None
if mean.size(1) != self.num_features:
raise Exception(
'Mean size not equal to number of featuers : given {}, expected {}'
.format(mean.size(1), self.num_features))
if mean_sq.size(1) != self.num_features:
raise Exception(
'Squared mean tensor size not equal to number of features : given {}, expected {}'
.format(mean_sq.size(1), self.num_features))
std = torch.sqrt(self.eps + mean_sq - mean ** 2)
x = x - mean
x = x / std
x = x * self.gamma
x = x + self.beta
return x
def __repr__(self):
return '{name}(num_features={num_features}, eps={eps}'.format(name=
self.__class__.__name__, **self.__dict__)
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 [[], {'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
from torch.nn import Module
import torch.utils
import torch.utils.data
from torch.nn.parameter import Parameter
from torch.nn.modules import Module
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_add_div_mean_mul_pow_sqrt_sub_0(in_ptr0, in_ptr1,
in_ptr2, in_ptr3, in_ptr4, out_ptr0, out_ptr1, out_ptr2, out_ptr3,
xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 64
x2 = xindex
x3 = xindex % 4
tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (64 + x0), xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (128 + x0), xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (192 + x0), xmask, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr1 + x2, xmask)
tmp24 = tl.load(in_ptr2 + x2, xmask)
tmp27 = tl.load(in_ptr0 + x2, xmask)
tmp35 = tl.load(in_ptr3 + x3, xmask, eviction_policy='evict_last')
tmp37 = tl.load(in_ptr4 + x3, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp7 = 4.0
tmp8 = tmp6 / tmp7
tmp9 = 0.2
tmp10 = tmp8 * tmp9
tmp12 = 0.8
tmp13 = tmp11 * tmp12
tmp14 = tmp10 + tmp13
tmp15 = tmp0 * tmp0
tmp16 = tmp1 * tmp1
tmp17 = tmp15 + tmp16
tmp18 = tmp3 * tmp3
tmp19 = tmp17 + tmp18
tmp20 = tmp5 * tmp5
tmp21 = tmp19 + tmp20
tmp22 = tmp21 / tmp7
tmp23 = tmp22 * tmp9
tmp25 = tmp24 * tmp12
tmp26 = tmp23 + tmp25
tmp28 = tmp27 - tmp14
tmp29 = 1e-05
tmp30 = tmp26 + tmp29
tmp31 = tmp14 * tmp14
tmp32 = tmp30 - tmp31
tmp33 = libdevice.sqrt(tmp32)
tmp34 = tmp28 / tmp33
tmp36 = tmp34 * tmp35
tmp38 = tmp36 + tmp37
tl.store(out_ptr0 + x2, tmp14, xmask)
tl.store(out_ptr1 + x2, tmp26, xmask)
tl.store(out_ptr2 + x2, tmp34, xmask)
tl.store(out_ptr3 + x2, tmp38, 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, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (1, 4), (4, 1))
assert_size_stride(primals_5, (1, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_add_div_mean_mul_pow_sqrt_sub_0[grid(256)](primals_1,
primals_2, primals_3, primals_4, primals_5, buf0, buf1, buf2,
buf3, 256, XBLOCK=128, num_warps=4, num_stages=1)
del primals_1
del primals_2
del primals_3
del primals_4
del primals_5
return buf3, buf0, buf1, buf2
class VirtualBatchNormNNNew(Module):
"""
Module for Virtual Batch Normalization.
Implementation borrowed and modified from Rafael_Valle's code + help of SimonW from this discussion thread:
https://discuss.pytorch.org/t/parameter-grad-of-conv-weight-is-none-after-virtual-batch-normalization/9036
"""
def __init__(self, num_features: 'int', eps: 'float'=1e-05):
super().__init__()
self.num_features = num_features
self.eps = eps
self.ref_mean = self.register_parameter('ref_mean', None)
self.ref_mean_sq = self.register_parameter('ref_mean_sq', None)
gamma = torch.normal(mean=torch.ones(1, num_features), std=0.02)
self.gamma = Parameter(gamma.float())
self.beta = Parameter(torch.FloatTensor(1, num_features).fill_(0))
def get_stats(self, x):
"""
Calculates mean and mean square for given batch x.
Args:
x: tensor containing batch of activations
Returns:
mean: mean tensor over features
mean_sq: squared mean tensor over features
"""
mean = x.mean(0, keepdim=True)
mean_sq = (x ** 2).mean(0, keepdim=True)
return mean, mean_sq
def _normalize(self, x, mean, mean_sq):
"""
Normalize tensor x given the statistics.
Args:
x: input tensor
mean: mean over features. it has size [1:num_features:]
mean_sq: squared means over features.
Result:
x: normalized batch tensor
"""
assert mean_sq is not None
assert mean is not None
if mean.size(1) != self.num_features:
raise Exception(
'Mean size not equal to number of featuers : given {}, expected {}'
.format(mean.size(1), self.num_features))
if mean_sq.size(1) != self.num_features:
raise Exception(
'Squared mean tensor size not equal to number of features : given {}, expected {}'
.format(mean_sq.size(1), self.num_features))
std = torch.sqrt(self.eps + mean_sq - mean ** 2)
x = x - mean
x = x / std
x = x * self.gamma
x = x + self.beta
return x
def __repr__(self):
return '{name}(num_features={num_features}, eps={eps}'.format(name=
self.__class__.__name__, **self.__dict__)
def forward(self, input_0, input_1, input_2):
primals_4 = self.gamma
primals_5 = self.beta
primals_1 = input_0
primals_2 = input_1
primals_3 = input_2
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0], output[1], output[2]
|
Silent-Zebra/JEM
|
VirtualBatchNormNN
| false
| 17,962
|
[
"Apache-2.0"
] | 6
|
33440aff8429d9a24a8ba858d0209f4b48be8e05
|
https://github.com/Silent-Zebra/JEM/tree/33440aff8429d9a24a8ba858d0209f4b48be8e05
|
GEGLU
|
import torch
import torch.nn.functional as F
from torch import nn
class GEGLU(nn.Module):
def forward(self, x):
x, gates = x.chunk(2, dim=-1)
return x * F.gelu(gates)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
from torch import nn
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_gelu_mul_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 2
x1 = xindex // 2
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4 * x1), xmask)
tmp1 = tl.load(in_ptr0 + (2 + x0 + 4 * x1), xmask)
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
tmp10 = tmp0 * tmp9
tl.store(out_ptr0 + x2, tmp10, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 2), (32, 8, 2, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_gelu_mul_0[grid(128)](arg0_1, buf0, 128, XBLOCK=
128, num_warps=4, num_stages=1)
del arg0_1
return buf0,
class GEGLUNew(nn.Module):
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
TabbenBenchmark/tabben
|
GEGLU
| false
| 17,963
|
[
"MIT"
] | 5
|
d74114afc4b6f67be488ab6bf8ad6fd316fdb888
|
https://github.com/TabbenBenchmark/tabben/tree/d74114afc4b6f67be488ab6bf8ad6fd316fdb888
|
Conv3x3
|
import torch
import torch.nn as nn
class Conv3x3(nn.Module):
"""Layer to pad and convolve input
"""
def __init__(self, in_channels, out_channels, use_refl=True):
super(Conv3x3, self).__init__()
if use_refl:
self.pad = nn.ReflectionPad2d(1)
else:
self.pad = nn.ZeroPad2d(1)
self.conv = nn.Conv2d(int(in_channels), int(out_channels), 3)
def forward(self, x):
out = self.pad(x)
out = self.conv(out)
return out
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'out_channels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_reflection_pad2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 576
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 6
x1 = xindex // 6 % 6
x2 = xindex // 36
x3 = xindex
tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2),
xmask, eviction_policy='evict_last')
tl.store(out_ptr0 + x3, tmp0, xmask)
@triton.jit
def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_3, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_reflection_pad2d_0[grid(576)](primals_1, buf0, 576,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_1
buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1))
buf2 = buf1
del buf1
triton_poi_fused_convolution_1[grid(256)](buf2, primals_3, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_3
return buf2, primals_2, buf0
class Conv3x3New(nn.Module):
"""Layer to pad and convolve input
"""
def __init__(self, in_channels, out_channels, use_refl=True):
super(Conv3x3New, self).__init__()
if use_refl:
self.pad = nn.ReflectionPad2d(1)
else:
self.pad = nn.ZeroPad2d(1)
self.conv = nn.Conv2d(int(in_channels), int(out_channels), 3)
def forward(self, input_0):
primals_2 = self.conv.weight
primals_3 = self.conv.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
Sid1057/sid1057.github.io
|
Conv3x3
| false
| 17,964
|
[
"MIT"
] | 4
|
623d1731e308b42b6f86304dcfd671a061b414bf
|
https://github.com/Sid1057/sid1057.github.io/tree/623d1731e308b42b6f86304dcfd671a061b414bf
|
ReinforcedReceiver
|
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.nn.parallel
import torch.utils.data
from torch.distributions import Bernoulli
import torch.distributions
class ReinforcedReceiver(nn.Module):
def __init__(self, n_bits, n_hidden):
super(ReinforcedReceiver, self).__init__()
self.emb_column = nn.Linear(n_bits, n_hidden)
self.fc1 = nn.Linear(2 * n_hidden, 2 * n_hidden)
self.fc2 = nn.Linear(2 * n_hidden, n_bits)
def forward(self, embedded_message, bits):
embedded_bits = self.emb_column(bits.float())
x = torch.cat([embedded_bits, embedded_message], dim=1)
x = self.fc1(x)
x = F.leaky_relu(x)
x = self.fc2(x)
probs = x.sigmoid()
distr = Bernoulli(probs=probs)
entropy = distr.entropy()
if self.training:
sample = distr.sample()
else:
sample = (probs > 0.5).float()
log_prob = distr.log_prob(sample).sum(dim=1)
return sample, log_prob, entropy
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4])]
def get_init_inputs():
return [[], {'n_bits': 4, '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 torch.nn as nn
import torch.nn.parallel
import torch.utils.data
import torch.distributions
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 = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tl.store(out_ptr0 + (x0 + 8 * x1), tmp0, xmask)
@triton.jit
def triton_poi_fused_leaky_relu_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 = 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_sigmoid_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.sigmoid(tmp2)
tl.store(in_out_ptr0 + x2, tmp3, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8) = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (8, 8), (8, 1))
assert_size_stride(primals_6, (8,), (1,))
assert_size_stride(primals_7, (4, 8), (8, 1))
assert_size_stride(primals_8, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf2 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
buf0 = reinterpret_tensor(buf2, (4, 4), (8, 1), 0)
extern_kernels.addmm(primals_3, primals_1, reinterpret_tensor(
primals_2, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf0)
del primals_2
del primals_3
buf1 = reinterpret_tensor(buf2, (4, 4), (8, 1), 4)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(16)](primals_4, buf1, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del primals_4
buf3 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
extern_kernels.mm(buf2, reinterpret_tensor(primals_5, (8, 8), (1, 8
), 0), out=buf3)
buf4 = empty_strided_cuda((4, 8), (8, 1), torch.bool)
buf5 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
triton_poi_fused_leaky_relu_1[grid(32)](buf3, primals_6, buf4, buf5,
32, XBLOCK=32, num_warps=1, num_stages=1)
del buf3
del primals_6
buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf5, reinterpret_tensor(primals_7, (8, 4), (1, 8
), 0), out=buf6)
buf7 = buf6
del buf6
triton_poi_fused_sigmoid_2[grid(16)](buf7, primals_8, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del primals_8
return buf7, buf7, primals_1, buf2, buf4, buf5, buf7, primals_7, primals_5
class ReinforcedReceiverNew(nn.Module):
def __init__(self, n_bits, n_hidden):
super(ReinforcedReceiverNew, self).__init__()
self.emb_column = nn.Linear(n_bits, n_hidden)
self.fc1 = nn.Linear(2 * n_hidden, 2 * n_hidden)
self.fc2 = nn.Linear(2 * n_hidden, n_bits)
def forward(self, input_0, input_1):
primals_1 = self.emb_column.weight
primals_3 = self.emb_column.bias
primals_5 = self.fc1.weight
primals_6 = self.fc1.bias
primals_7 = self.fc2.weight
primals_8 = self.fc2.bias
primals_2 = 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], output[1], output[2]
|
Slowika/GameBias-EmeCom2020
|
ReinforcedReceiver
| false
| 17,965
|
[
"MIT"
] | 5
|
5b94c47559f8202bca99c26fc1bcb078dd0509a6
|
https://github.com/Slowika/GameBias-EmeCom2020/tree/5b94c47559f8202bca99c26fc1bcb078dd0509a6
|
VonmisesLossBiternion
|
import torch
class VonmisesLossBiternion(torch.nn.Module):
"""Von mises loss function for biternion inputs
see: Beyer et al.: Biternion Nets: Continuous Head Pose Regression from
Discrete Training Labels, GCPR 2015.
"""
def __init__(self, kappa):
super(VonmisesLossBiternion, self).__init__()
self._kappa = kappa
def forward(self, prediction, target):
cos_angles = torch.bmm(prediction[..., None].permute(0, 2, 1),
target[..., None])
cos_angles = torch.exp(self._kappa * (cos_angles - 1))
score = 1 - cos_angles
return score[:, 0, 0]
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4])]
def get_init_inputs():
return [[], {'kappa': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import math as tl_math
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_exp_mul_rsub_sub_0(in_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_out_ptr0 + x0, xmask)
tmp1 = 1.0
tmp2 = tmp0 - tmp1
tmp3 = 4.0
tmp4 = tmp2 * tmp3
tmp5 = tl_math.exp(tmp4)
tmp6 = tmp1 - tmp5
tl.store(in_out_ptr0 + x0, tmp6, 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, 1, 1), (1, 1, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(arg0_1, (4, 1, 4), (4, 1, 1),
0), reinterpret_tensor(arg1_1, (4, 4, 1), (4, 1, 1), 0), out=buf0)
del arg0_1
del arg1_1
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_exp_mul_rsub_sub_0[grid(4)](buf1, 4, XBLOCK=4,
num_warps=1, num_stages=1)
return reinterpret_tensor(buf1, (4,), (1,), 0),
class VonmisesLossBiternionNew(torch.nn.Module):
"""Von mises loss function for biternion inputs
see: Beyer et al.: Biternion Nets: Continuous Head Pose Regression from
Discrete Training Labels, GCPR 2015.
"""
def __init__(self, kappa):
super(VonmisesLossBiternionNew, self).__init__()
self._kappa = kappa
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
TUI-NICR/multi-task-person-perception
|
VonmisesLossBiternion
| false
| 17,966
|
[
"BSD-3-Clause"
] | 4
|
81666eb42be9522fd726448e82e8bbf04138ffa3
|
https://github.com/TUI-NICR/multi-task-person-perception/tree/81666eb42be9522fd726448e82e8bbf04138ffa3
|
MulScalarNegative
|
import torch
import torch.nn as nn
from torch.quantization import QuantStub
from torch.quantization import DeQuantStub
class MulScalarNegative(nn.Module):
def __init__(self):
super().__init__()
self.float_op = nn.quantized.FloatFunctional()
self.quant = QuantStub()
self.dequant = DeQuantStub()
def forward(self, x):
x = self.quant(x)
mul = self.float_op.mul_scalar(x, -0.3)
return self.dequant(mul)
def fuse_model(self):
pass
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
from torch.quantization import QuantStub
from torch.quantization import DeQuantStub
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_mul_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = -0.3
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_mul_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del arg0_1
return buf0,
class MulScalarNegativeNew(nn.Module):
def __init__(self):
super().__init__()
self.float_op = nn.quantized.FloatFunctional()
self.quant = QuantStub()
self.dequant = DeQuantStub()
def fuse_model(self):
pass
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
T-head-Semi/tvm
|
MulScalarNegative
| false
| 17,967
|
[
"Apache-2.0"
] | 4
|
c1b8e06685c92fb7cacbe989e147b0622aee4503
|
https://github.com/T-head-Semi/tvm/tree/c1b8e06685c92fb7cacbe989e147b0622aee4503
|
InformedSender
|
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.nn.parallel
import torch.utils.data
import torch.distributions
class InformedSender(nn.Module):
def __init__(self, game_size, feat_size, embedding_size, hidden_size,
vocab_size=100, temp=1.0):
super(InformedSender, self).__init__()
self.game_size = game_size
self.embedding_size = embedding_size
self.hidden_size = hidden_size
self.vocab_size = vocab_size
self.temp = temp
self.lin1 = nn.Linear(feat_size, embedding_size, bias=False)
self.conv2 = nn.Conv2d(1, hidden_size, kernel_size=(game_size, 1),
stride=(game_size, 1), bias=False)
self.conv3 = nn.Conv2d(1, 1, kernel_size=(hidden_size, 1), stride=(
hidden_size, 1), bias=False)
self.lin4 = nn.Linear(embedding_size, vocab_size, bias=False)
def forward(self, x, return_embeddings=False):
emb = self.return_embeddings(x)
h = self.conv2(emb)
h = torch.sigmoid(h)
h = h.transpose(1, 2)
h = self.conv3(h)
h = torch.sigmoid(h)
h = h.squeeze(dim=1)
h = h.squeeze(dim=1)
h = self.lin4(h)
h = h.mul(1.0 / self.temp)
logits = F.log_softmax(h, dim=1)
return logits
def return_embeddings(self, x):
embs = []
for i in range(self.game_size):
h = x[i]
if len(h.size()) == 3:
h = h.squeeze(dim=-1)
h_i = self.lin1(h)
h_i = h_i.unsqueeze(dim=1)
h_i = h_i.unsqueeze(dim=1)
embs.append(h_i)
h = torch.cat(embs, dim=2)
return h
def get_inputs():
return [torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'game_size': 4, 'feat_size': 4, 'embedding_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
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
import torch.nn.parallel
import torch.utils.data
import torch.distributions
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, in_ptr3, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 4 % 4
x0 = xindex % 4
x2 = xindex // 16
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 1, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 4 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tmp0 >= tmp3
tmp7 = tl.full([1], 2, tl.int64)
tmp8 = tmp0 < tmp7
tmp9 = tmp6 & tmp8
tmp10 = tl.load(in_ptr1 + (x0 + 4 * x2), tmp9 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp11 = tmp0 >= tmp7
tmp12 = tl.full([1], 3, tl.int64)
tmp13 = tmp0 < tmp12
tmp14 = tmp11 & tmp13
tmp15 = tl.load(in_ptr2 + (x0 + 4 * x2), tmp14 & xmask, eviction_policy
='evict_last', other=0.0)
tmp16 = tmp0 >= tmp12
tl.full([1], 4, tl.int64)
tmp19 = tl.load(in_ptr3 + (x0 + 4 * x2), tmp16 & xmask, eviction_policy
='evict_last', other=0.0)
tmp20 = tl.where(tmp14, tmp15, tmp19)
tmp21 = tl.where(tmp9, tmp10, tmp20)
tmp22 = tl.where(tmp4, tmp5, tmp21)
tl.store(out_ptr0 + x3, tmp22, xmask)
@triton.jit
def triton_poi_fused_sigmoid_1(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 = tl.sigmoid(tmp0)
tl.store(in_out_ptr0 + x0, tmp1, xmask)
@triton.jit
def triton_poi_fused_sigmoid_2(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.sigmoid(tmp0)
tl.store(in_out_ptr0 + x0, tmp1, xmask)
@triton.jit
def triton_per_fused__log_softmax_3(in_ptr0, out_ptr2, xnumel, rnumel,
XBLOCK: tl.constexpr):
xnumel = 4
rnumel = 100
RBLOCK: tl.constexpr = 128
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 + 100 * x0), rmask & xmask, other=0.0)
tmp1 = 1.0
tmp2 = tmp0 * tmp1
tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
tmp5 = tl.where(rmask & xmask, tmp3, float('-inf'))
tmp6 = triton_helpers.max2(tmp5, 1)[:, None]
tmp7 = tmp2 - tmp6
tmp8 = tmp7 * tmp1
tmp9 = tl_math.exp(tmp8)
tmp10 = tl.broadcast_to(tmp9, [XBLOCK, RBLOCK])
tmp12 = tl.where(rmask & xmask, tmp10, 0)
tmp13 = tl.sum(tmp12, 1)[:, None]
tmp14 = tl_math.log(tmp13)
tmp15 = tmp8 - tmp14
tl.store(out_ptr2 + (r1 + 100 * x0), tmp15, rmask & xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4, 1, 4, 1), (4, 4, 1, 1))
assert_size_stride(primals_4, (1, 1, 4, 1), (4, 4, 1, 1))
assert_size_stride(primals_5, (100, 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(reinterpret_tensor(primals_1, (4, 4), (4, 1), 0),
reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0)
buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (4, 4), (4, 1), 16),
reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf1)
buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (4, 4), (4, 1), 32),
reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf2)
buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (4, 4), (4, 1), 48),
reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf3)
del primals_2
buf4 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(64)](buf0, buf1, buf2, buf3, buf4, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del buf0
del buf1
del buf2
del buf3
buf5 = extern_kernels.convolution(buf4, primals_3, stride=(4, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf5, (4, 4, 1, 4), (16, 4, 4, 1))
buf6 = buf5
del buf5
triton_poi_fused_sigmoid_1[grid(64)](buf6, 64, XBLOCK=64, num_warps
=1, num_stages=1)
buf7 = extern_kernels.convolution(reinterpret_tensor(buf6, (4, 1, 4,
4), (16, 4, 4, 1), 0), primals_4, stride=(4, 1), padding=(0, 0),
dilation=(1, 1), transposed=False, output_padding=(0, 0),
groups=1, bias=None)
assert_size_stride(buf7, (4, 1, 1, 4), (4, 4, 4, 1))
buf8 = buf7
del buf7
triton_poi_fused_sigmoid_2[grid(16)](buf8, 16, XBLOCK=16, num_warps
=1, num_stages=1)
buf9 = empty_strided_cuda((4, 100), (100, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf8, (4, 4), (4, 1), 0),
reinterpret_tensor(primals_5, (4, 100), (1, 4), 0), out=buf9)
buf12 = empty_strided_cuda((4, 100), (100, 1), torch.float32)
triton_per_fused__log_softmax_3[grid(4)](buf9, buf12, 4, 100,
XBLOCK=1, num_warps=2, num_stages=1)
del buf9
return buf12, primals_3, primals_4, reinterpret_tensor(primals_1, (4, 4
), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (4, 1), 16
), reinterpret_tensor(primals_1, (4, 4), (4, 1), 32
), reinterpret_tensor(primals_1, (4, 4), (4, 1), 48
), buf4, buf6, buf8, buf12, primals_5
class InformedSenderNew(nn.Module):
def __init__(self, game_size, feat_size, embedding_size, hidden_size,
vocab_size=100, temp=1.0):
super(InformedSenderNew, self).__init__()
self.game_size = game_size
self.embedding_size = embedding_size
self.hidden_size = hidden_size
self.vocab_size = vocab_size
self.temp = temp
self.lin1 = nn.Linear(feat_size, embedding_size, bias=False)
self.conv2 = nn.Conv2d(1, hidden_size, kernel_size=(game_size, 1),
stride=(game_size, 1), bias=False)
self.conv3 = nn.Conv2d(1, 1, kernel_size=(hidden_size, 1), stride=(
hidden_size, 1), bias=False)
self.lin4 = nn.Linear(embedding_size, vocab_size, bias=False)
def return_embeddings(self, x):
embs = []
for i in range(self.game_size):
h = x[i]
if len(h.size()) == 3:
h = h.squeeze(dim=-1)
h_i = self.lin1(h)
h_i = h_i.unsqueeze(dim=1)
h_i = h_i.unsqueeze(dim=1)
embs.append(h_i)
h = torch.cat(embs, dim=2)
return h
def forward(self, input_0):
primals_2 = self.lin1.weight
primals_3 = self.conv2.weight
primals_4 = self.conv3.weight
primals_5 = self.lin4.weight
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
Slowika/GameBias-EmeCom2020
|
InformedSender
| false
| 17,968
|
[
"MIT"
] | 5
|
5b94c47559f8202bca99c26fc1bcb078dd0509a6
|
https://github.com/Slowika/GameBias-EmeCom2020/tree/5b94c47559f8202bca99c26fc1bcb078dd0509a6
|
UpsamplingBilinear
|
import torch
import torch.nn as nn
from torch.quantization import QuantStub
from torch.quantization import DeQuantStub
class UpsamplingBilinear(nn.Module):
def __init__(self):
super().__init__()
self.quant = QuantStub()
self.dequant = DeQuantStub()
def forward(self, x):
x = self.quant(x)
upsample = nn.functional.interpolate(x, scale_factor=2, mode=
'bilinear', align_corners=True)
return self.dequant(upsample)
def fuse_model(self):
pass
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
from torch.quantization import QuantStub
from torch.quantization import DeQuantStub
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0(
in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr):
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.42857142857142855
tmp3 = tmp1 * tmp2
tmp4 = 0.0
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp6 = tmp5.to(tl.int32)
tmp7 = tl.full([1], 1, tl.int64)
tmp8 = tmp6 + tmp7
tmp9 = tl.full([1], 3, tl.int64)
tmp10 = triton_helpers.minimum(tmp8, tmp9)
tmp11 = x0
tmp12 = tmp11.to(tl.float32)
tmp13 = tmp12 * tmp2
tmp14 = triton_helpers.maximum(tmp13, tmp4)
tmp15 = tmp14.to(tl.int32)
tmp16 = tl.load(in_ptr0 + (tmp15 + 4 * tmp10 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp17 = tmp15 + tmp7
tmp18 = triton_helpers.minimum(tmp17, tmp9)
tmp19 = tl.load(in_ptr0 + (tmp18 + 4 * tmp10 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp20 = tmp19 - tmp16
tmp21 = tmp15.to(tl.float32)
tmp22 = tmp14 - tmp21
tmp23 = triton_helpers.maximum(tmp22, tmp4)
tmp24 = 1.0
tmp25 = triton_helpers.minimum(tmp23, tmp24)
tmp26 = tmp20 * tmp25
tmp27 = tmp16 + tmp26
tmp28 = tl.load(in_ptr0 + (tmp15 + 4 * tmp6 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp29 = tl.load(in_ptr0 + (tmp18 + 4 * tmp6 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp30 = tmp29 - tmp28
tmp31 = tmp30 * tmp25
tmp32 = tmp28 + tmp31
tmp33 = tmp27 - tmp32
tmp34 = tmp6.to(tl.float32)
tmp35 = tmp5 - tmp34
tmp36 = triton_helpers.maximum(tmp35, tmp4)
tmp37 = triton_helpers.minimum(tmp36, tmp24)
tmp38 = tmp33 * tmp37
tmp39 = tmp32 + tmp38
tl.store(in_out_ptr0 + x4, tmp39, 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, 8, 8), (256, 64, 8, 1), torch.float32)
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0[grid
(1024)](buf1, arg0_1, 1024, XBLOCK=128, num_warps=4, num_stages=1)
del arg0_1
return buf1,
class UpsamplingBilinearNew(nn.Module):
def __init__(self):
super().__init__()
self.quant = QuantStub()
self.dequant = DeQuantStub()
def fuse_model(self):
pass
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
T-head-Semi/tvm
|
UpsamplingBilinear
| false
| 17,969
|
[
"Apache-2.0"
] | 4
|
c1b8e06685c92fb7cacbe989e147b0622aee4503
|
https://github.com/T-head-Semi/tvm/tree/c1b8e06685c92fb7cacbe989e147b0622aee4503
|
SmallMnistNoDropoutWithPassThrough
|
import torch
import torch.nn as nn
import torch.nn
import torch.utils.data
import torch.utils.tensorboard._pytorch_graph
import torch.onnx.symbolic_caffe2
class PassThroughOp(torch.nn.Module):
"""
This is a pass-through op, used for purpose of making an op a no-op
"""
def forward(self, inputx):
return inputx
class SmallMnistNoDropoutWithPassThrough(nn.Module):
def __init__(self):
super(SmallMnistNoDropoutWithPassThrough, self).__init__()
self.conv1 = nn.Conv2d(1, 10, kernel_size=5)
self.pt1 = PassThroughOp()
self.relu1 = nn.ReLU()
self.conv2 = nn.Conv2d(10, 20, kernel_size=5)
self.pt2 = PassThroughOp()
self.relu2 = nn.ReLU()
self.fc1 = nn.Linear(320, 50)
self.relu3 = nn.ReLU()
self.fc2 = nn.Linear(50, 10)
self.log_softmax = nn.LogSoftmax(dim=1)
def forward(self, x):
x = self.relu1(self.pt1(self.conv1(x)))
x = self.conv2(x)
x = self.relu2(self.pt2(x))
x = x.view(-1, 320)
x = self.relu3(self.fc1(x))
x = self.fc2(x)
return self.log_softmax(x)
def get_inputs():
return [torch.rand([4, 1, 64, 64])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
import torch.nn
import torch.utils.data
import torch.utils.tensorboard._pytorch_graph
import torch.onnx.symbolic_caffe2
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 = 144000
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 3600 % 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_relu_threshold_backward_1(in_out_ptr0,
in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 250880
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x4 = xindex
x1 = xindex // 3136 % 20
x0 = xindex % 3136
x3 = xindex // 3136
tmp0 = tl.load(in_out_ptr0 + x4, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x4, tmp4, xmask)
tl.store(out_ptr0 + (x0 + 3200 * x3), tmp6, xmask)
@triton.jit
def triton_poi_fused_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 39200
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 50
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x2, tmp4, xmask)
@triton.jit
def triton_per_fused__log_softmax_3(in_ptr0, out_ptr2, xnumel, rnumel,
XBLOCK: tl.constexpr):
xnumel = 784
rnumel = 10
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
rmask = rindex < rnumel
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 10 * x0), rmask & xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(rmask & xmask, tmp1, float('-inf'))
tmp4 = triton_helpers.max2(tmp3, 1)[:, None]
tmp5 = tmp0 - tmp4
tmp6 = tl_math.exp(tmp5)
tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
tmp9 = tl.where(rmask & xmask, tmp7, 0)
tmp10 = tl.sum(tmp9, 1)[:, None]
tmp11 = tl_math.log(tmp10)
tmp12 = tmp5 - tmp11
tl.store(out_ptr2 + (r1 + 10 * x0), tmp12, rmask & xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9) = args
args.clear()
assert_size_stride(primals_1, (10, 1, 5, 5), (25, 25, 5, 1))
assert_size_stride(primals_2, (10,), (1,))
assert_size_stride(primals_3, (4, 1, 64, 64), (4096, 4096, 64, 1))
assert_size_stride(primals_4, (20, 10, 5, 5), (250, 25, 5, 1))
assert_size_stride(primals_5, (20,), (1,))
assert_size_stride(primals_6, (50, 320), (320, 1))
assert_size_stride(primals_7, (50,), (1,))
assert_size_stride(primals_8, (10, 50), (50, 1))
assert_size_stride(primals_9, (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, 10, 60, 60), (36000, 3600, 60, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_relu_0[grid(144000)](buf1, primals_2,
144000, 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, 20, 56, 56), (62720, 3136, 56, 1))
buf3 = buf2
del buf2
buf10 = empty_strided_cuda((4, 20, 56, 56), (64000, 3200, 56, 1),
torch.bool)
triton_poi_fused_convolution_relu_threshold_backward_1[grid(250880)](
buf3, primals_5, buf10, 250880, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_5
buf4 = empty_strided_cuda((784, 50), (50, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf3, (784, 320), (320, 1), 0),
reinterpret_tensor(primals_6, (320, 50), (1, 320), 0), out=buf4)
buf5 = buf4
del buf4
triton_poi_fused_relu_2[grid(39200)](buf5, primals_7, 39200, XBLOCK
=512, num_warps=4, num_stages=1)
del primals_7
buf6 = empty_strided_cuda((784, 10), (10, 1), torch.float32)
extern_kernels.addmm(primals_9, buf5, reinterpret_tensor(primals_8,
(50, 10), (1, 50), 0), alpha=1, beta=1, out=buf6)
del primals_9
buf9 = empty_strided_cuda((784, 10), (10, 1), torch.float32)
triton_per_fused__log_softmax_3[grid(784)](buf6, buf9, 784, 10,
XBLOCK=32, num_warps=4, num_stages=1)
del buf6
return buf9, primals_1, primals_3, primals_4, buf1, reinterpret_tensor(buf3
, (784, 320), (320, 1), 0), buf5, buf9, primals_8, primals_6, buf10
class PassThroughOp(torch.nn.Module):
"""
This is a pass-through op, used for purpose of making an op a no-op
"""
def forward(self, inputx):
return inputx
class SmallMnistNoDropoutWithPassThroughNew(nn.Module):
def __init__(self):
super(SmallMnistNoDropoutWithPassThroughNew, self).__init__()
self.conv1 = nn.Conv2d(1, 10, kernel_size=5)
self.pt1 = PassThroughOp()
self.relu1 = nn.ReLU()
self.conv2 = nn.Conv2d(10, 20, kernel_size=5)
self.pt2 = PassThroughOp()
self.relu2 = nn.ReLU()
self.fc1 = nn.Linear(320, 50)
self.relu3 = nn.ReLU()
self.fc2 = nn.Linear(50, 10)
self.log_softmax = nn.LogSoftmax(dim=1)
def forward(self, input_0):
primals_1 = self.conv1.weight
primals_2 = self.conv1.bias
primals_4 = self.conv2.weight
primals_5 = self.conv2.bias
primals_6 = self.fc1.weight
primals_7 = self.fc1.bias
primals_8 = self.fc2.weight
primals_9 = self.fc2.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9])
return output[0]
|
Rohan-Chaudhury/aimet
|
SmallMnistNoDropoutWithPassThrough
| false
| 17,970
|
[
"BSD-3-Clause"
] | 3
|
1c38cac8cc0fd32dca40ce5e39940805d29f7a4a
|
https://github.com/Rohan-Chaudhury/aimet/tree/1c38cac8cc0fd32dca40ce5e39940805d29f7a4a
|
CovSepBlock
|
import torch
import torch.nn as M
def DepthwiseConv(in_channels, kernel_size, stride, padding):
return M.Conv2d(in_channels=in_channels, out_channels=in_channels,
kernel_size=kernel_size, stride=stride, padding=padding, groups=
in_channels, bias=False)
def PointwiseConv(in_channels, out_channels):
return M.Conv2d(in_channels=in_channels, out_channels=out_channels,
kernel_size=1, padding=0, bias=True)
class CovSepBlock(M.Module):
def __init__(self, in_channels, out_channels, kernel_size=5, stride=1,
padding=2):
super().__init__()
self.dc = DepthwiseConv(in_channels, kernel_size, stride=stride,
padding=padding)
self.pc = PointwiseConv(in_channels, out_channels)
def forward(self, x):
x = self.dc(x)
x = self.pc(x)
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'out_channels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as M
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
@triton.jit
def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (4, 1, 5, 5), (25, 25, 5, 1))
assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_3, (4, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_4, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_2, primals_1, stride=(1,
1), padding=(2, 2), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=4, bias=None)
assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1))
buf1 = extern_kernels.convolution(buf0, primals_3, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1))
buf2 = buf1
del buf1
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(256)](buf2, primals_4, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_4
return buf2, primals_1, primals_2, primals_3, buf0
def DepthwiseConv(in_channels, kernel_size, stride, padding):
return M.Conv2d(in_channels=in_channels, out_channels=in_channels,
kernel_size=kernel_size, stride=stride, padding=padding, groups=
in_channels, bias=False)
def PointwiseConv(in_channels, out_channels):
return M.Conv2d(in_channels=in_channels, out_channels=out_channels,
kernel_size=1, padding=0, bias=True)
class CovSepBlockNew(M.Module):
def __init__(self, in_channels, out_channels, kernel_size=5, stride=1,
padding=2):
super().__init__()
self.dc = DepthwiseConv(in_channels, kernel_size, stride=stride,
padding=padding)
self.pc = PointwiseConv(in_channels, out_channels)
def forward(self, input_0):
primals_1 = self.dc.weight
primals_3 = self.pc.weight
primals_4 = self.pc.bias
primals_2 = input_0
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
SuperbTUM/RAW-image-denoising
|
CovSepBlock
| false
| 17,971
|
[
"MIT"
] | 4
|
9f81be8da6a576f641022707d98b8c37f5c599ab
|
https://github.com/SuperbTUM/RAW-image-denoising/tree/9f81be8da6a576f641022707d98b8c37f5c599ab
|
Upsample
|
import torch
import torch.nn as M
class Upsample(M.Module):
def __init__(self, in_channels, out_channels):
super(Upsample, self).__init__()
self.upsample = M.Upsample(scale_factor=2, mode='bilinear',
align_corners=True)
self.ordinaryConv = M.Conv2d(in_channels=in_channels, out_channels=
out_channels, kernel_size=1)
def forward(self, x):
x = self.upsample(x)
x = self.ordinaryConv(x)
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'out_channels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as M
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0(
in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr):
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.42857142857142855
tmp3 = tmp1 * tmp2
tmp4 = 0.0
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp6 = tmp5.to(tl.int32)
tmp7 = tl.full([1], 1, tl.int64)
tmp8 = tmp6 + tmp7
tmp9 = tl.full([1], 3, tl.int64)
tmp10 = triton_helpers.minimum(tmp8, tmp9)
tmp11 = x0
tmp12 = tmp11.to(tl.float32)
tmp13 = tmp12 * tmp2
tmp14 = triton_helpers.maximum(tmp13, tmp4)
tmp15 = tmp14.to(tl.int32)
tmp16 = tl.load(in_ptr0 + (tmp15 + 4 * tmp10 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp17 = tmp15 + tmp7
tmp18 = triton_helpers.minimum(tmp17, tmp9)
tmp19 = tl.load(in_ptr0 + (tmp18 + 4 * tmp10 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp20 = tmp19 - tmp16
tmp21 = tmp15.to(tl.float32)
tmp22 = tmp14 - tmp21
tmp23 = triton_helpers.maximum(tmp22, tmp4)
tmp24 = 1.0
tmp25 = triton_helpers.minimum(tmp23, tmp24)
tmp26 = tmp20 * tmp25
tmp27 = tmp16 + tmp26
tmp28 = tl.load(in_ptr0 + (tmp15 + 4 * tmp6 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp29 = tl.load(in_ptr0 + (tmp18 + 4 * tmp6 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp30 = tmp29 - tmp28
tmp31 = tmp30 * tmp25
tmp32 = tmp28 + tmp31
tmp33 = tmp27 - tmp32
tmp34 = tmp6.to(tl.float32)
tmp35 = tmp5 - tmp34
tmp36 = triton_helpers.maximum(tmp35, tmp4)
tmp37 = triton_helpers.minimum(tmp36, tmp24)
tmp38 = tmp33 * tmp37
tmp39 = tmp32 + tmp38
tl.store(in_out_ptr0 + x4, tmp39, xmask)
@triton.jit
def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 64 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4, 1, 1), (4, 1, 1, 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)
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0[grid
(1024)](buf1, primals_1, 1024, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_1
buf2 = extern_kernels.convolution(buf1, primals_2, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 4, 8, 8), (256, 64, 8, 1))
buf3 = buf2
del buf2
triton_poi_fused_convolution_1[grid(1024)](buf3, primals_3, 1024,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_3
return buf3, primals_2, buf1
class UpsampleNew(M.Module):
def __init__(self, in_channels, out_channels):
super(UpsampleNew, self).__init__()
self.upsample = M.Upsample(scale_factor=2, mode='bilinear',
align_corners=True)
self.ordinaryConv = M.Conv2d(in_channels=in_channels, out_channels=
out_channels, kernel_size=1)
def forward(self, input_0):
primals_2 = self.ordinaryConv.weight
primals_3 = self.ordinaryConv.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
SuperbTUM/RAW-image-denoising
|
Upsample
| false
| 17,972
|
[
"MIT"
] | 4
|
9f81be8da6a576f641022707d98b8c37f5c599ab
|
https://github.com/SuperbTUM/RAW-image-denoising/tree/9f81be8da6a576f641022707d98b8c37f5c599ab
|
DownSample
|
import torch
import torch.nn as M
def DepthwiseConv(in_channels, kernel_size, stride, padding):
return M.Conv2d(in_channels=in_channels, out_channels=in_channels,
kernel_size=kernel_size, stride=stride, padding=padding, groups=
in_channels, bias=False)
def PointwiseConv(in_channels, out_channels):
return M.Conv2d(in_channels=in_channels, out_channels=out_channels,
kernel_size=1, padding=0, bias=True)
class CovSepBlock(M.Module):
def __init__(self, in_channels, out_channels, kernel_size=5, stride=1,
padding=2):
super().__init__()
self.dc = DepthwiseConv(in_channels, kernel_size, stride=stride,
padding=padding)
self.pc = PointwiseConv(in_channels, out_channels)
def forward(self, x):
x = self.dc(x)
x = self.pc(x)
return x
class DownSample(M.Module):
def __init__(self, in_channels, out_channels):
super().__init__()
self.ordinaryConv1 = CovSepBlock(in_channels=in_channels,
out_channels=out_channels // 4, stride=2)
self.activate = M.ReLU(inplace=True)
self.ordinaryConv2 = CovSepBlock(in_channels=out_channels // 4,
out_channels=out_channels)
self.skipconnect = CovSepBlock(in_channels=in_channels,
out_channels=out_channels, kernel_size=3, stride=2, padding=1)
self.activate2 = M.ReLU(inplace=True)
def forward(self, x):
branch = x
x = self.ordinaryConv1(x)
x = self.activate(x)
x = self.ordinaryConv2(x)
branch = self.skipconnect(branch)
x += branch
x = self.activate2(x)
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'out_channels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as M
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 = 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.load(in_ptr0 + 0)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
tmp3 = tmp0 + tmp2
tmp4 = tl.full([1], 0, tl.int32)
tmp5 = triton_helpers.maximum(tmp4, tmp3)
tl.store(in_out_ptr0 + x0, tmp5, xmask)
@triton.jit
def triton_poi_fused_add_convolution_relu_threshold_backward_1(in_out_ptr0,
in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 4 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x3, xmask)
tmp4 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp5 = tmp3 + tmp4
tmp6 = tmp2 + tmp5
tmp7 = tl.full([1], 0, tl.int32)
tmp8 = triton_helpers.maximum(tmp7, tmp6)
tmp9 = 0.0
tmp10 = tmp8 <= tmp9
tl.store(in_out_ptr0 + x3, tmp8, xmask)
tl.store(out_ptr0 + x3, tmp10, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 1, 5, 5), (25, 25, 5, 1))
assert_size_stride(primals_3, (1, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_4, (1,), (1,))
assert_size_stride(primals_5, (1, 1, 5, 5), (25, 25, 5, 1))
assert_size_stride(primals_6, (4, 1, 1, 1), (1, 1, 1, 1))
assert_size_stride(primals_7, (4,), (1,))
assert_size_stride(primals_8, (4, 1, 3, 3), (9, 9, 3, 1))
assert_size_stride(primals_9, (4, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_10, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(2,
2), padding=(2, 2), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=4, bias=None)
assert_size_stride(buf0, (4, 4, 2, 2), (16, 4, 2, 1))
buf1 = extern_kernels.convolution(buf0, primals_3, 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))
buf2 = buf1
del buf1
get_raw_stream(0)
triton_poi_fused_convolution_relu_0[grid(16)](buf2, primals_4, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del primals_4
buf3 = extern_kernels.convolution(buf2, primals_5, stride=(1, 1),
padding=(2, 2), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf3, (4, 1, 2, 2), (4, 4, 2, 1))
buf4 = extern_kernels.convolution(buf3, primals_6, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 4, 2, 2), (16, 4, 2, 1))
buf5 = extern_kernels.convolution(primals_1, primals_8, stride=(2,
2), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=4, bias=None)
assert_size_stride(buf5, (4, 4, 2, 2), (16, 4, 2, 1))
buf6 = extern_kernels.convolution(buf5, primals_9, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf6, (4, 4, 2, 2), (16, 4, 2, 1))
buf7 = buf4
del buf4
buf8 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.bool)
triton_poi_fused_add_convolution_relu_threshold_backward_1[grid(64)](
buf7, primals_7, buf6, primals_10, buf8, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del buf6
del primals_10
del primals_7
return (buf7, primals_1, primals_2, primals_3, primals_5, primals_6,
primals_8, primals_9, buf0, buf2, buf3, buf5, buf8)
def DepthwiseConv(in_channels, kernel_size, stride, padding):
return M.Conv2d(in_channels=in_channels, out_channels=in_channels,
kernel_size=kernel_size, stride=stride, padding=padding, groups=
in_channels, bias=False)
def PointwiseConv(in_channels, out_channels):
return M.Conv2d(in_channels=in_channels, out_channels=out_channels,
kernel_size=1, padding=0, bias=True)
class CovSepBlock(M.Module):
def __init__(self, in_channels, out_channels, kernel_size=5, stride=1,
padding=2):
super().__init__()
self.dc = DepthwiseConv(in_channels, kernel_size, stride=stride,
padding=padding)
self.pc = PointwiseConv(in_channels, out_channels)
def forward(self, x):
x = self.dc(x)
x = self.pc(x)
return x
class DownSampleNew(M.Module):
def __init__(self, in_channels, out_channels):
super().__init__()
self.ordinaryConv1 = CovSepBlock(in_channels=in_channels,
out_channels=out_channels // 4, stride=2)
self.activate = M.ReLU(inplace=True)
self.ordinaryConv2 = CovSepBlock(in_channels=out_channels // 4,
out_channels=out_channels)
self.skipconnect = CovSepBlock(in_channels=in_channels,
out_channels=out_channels, kernel_size=3, stride=2, padding=1)
self.activate2 = M.ReLU(inplace=True)
def forward(self, input_0):
primals_2 = self.ordinaryConv1.dc.weight
primals_3 = self.ordinaryConv1.pc.weight
primals_4 = self.ordinaryConv1.pc.bias
primals_5 = self.ordinaryConv2.dc.weight
primals_6 = self.ordinaryConv2.pc.weight
primals_7 = self.ordinaryConv2.pc.bias
primals_8 = self.skipconnect.dc.weight
primals_9 = self.skipconnect.pc.weight
primals_10 = self.skipconnect.pc.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9, primals_10])
return output[0]
|
SuperbTUM/RAW-image-denoising
|
DownSample
| false
| 17,973
|
[
"MIT"
] | 4
|
9f81be8da6a576f641022707d98b8c37f5c599ab
|
https://github.com/SuperbTUM/RAW-image-denoising/tree/9f81be8da6a576f641022707d98b8c37f5c599ab
|
Net_1
|
import torch
from torch import nn
import torch.nn.functional as F
class Net_1(nn.Module):
def __init__(self):
super(Net_1, self).__init__()
self.conv1 = nn.Conv1d(1, 25, 9, padding=4)
self.conv2 = nn.Conv1d(25, 16, 7, padding=3)
self.conv3 = nn.Conv1d(16, 10, 7, padding=3)
self.conv4 = nn.Conv1d(10, 1, 1)
def forward(self, x):
leaky_relu = nn.LeakyReLU(0.05)
nn.Dropout(0.9)
x = torch.unsqueeze(x, 1)
x = leaky_relu(self.conv1(x))
x = leaky_relu(self.conv2(x))
x = leaky_relu(self.conv3(x))
x = F.relu(self.conv4(x))
x = x.squeeze(1)
return x
def get_inputs():
return [torch.rand([4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch 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_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, 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 // 4 % 25
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp5 = 0.05
tmp6 = tmp2 * tmp5
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(out_ptr0 + x3, tmp4, xmask)
tl.store(out_ptr1 + x3, tmp7, xmask)
@triton.jit
def triton_poi_fused_convolution_leaky_relu_1(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 4 % 16
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp5 = 0.05
tmp6 = tmp2 * tmp5
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(out_ptr0 + x3, tmp4, xmask)
tl.store(out_ptr1 + x3, tmp7, xmask)
@triton.jit
def triton_poi_fused_convolution_leaky_relu_2(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 160
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 4 % 10
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp5 = 0.05
tmp6 = tmp2 * tmp5
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(out_ptr0 + x3, tmp4, xmask)
tl.store(out_ptr1 + x3, tmp7, xmask)
@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_3(in_out_ptr0,
in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + 0)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
tmp3 = tmp0 + tmp2
tmp4 = tl.full([1], 0, tl.int32)
tmp5 = triton_helpers.maximum(tmp4, tmp3)
tmp6 = 0.0
tmp7 = tmp5 <= tmp6
tl.store(in_out_ptr0 + x0, tmp5, xmask)
tl.store(out_ptr0 + x0, tmp7, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9) = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (25, 1, 9), (9, 9, 1))
assert_size_stride(primals_3, (25,), (1,))
assert_size_stride(primals_4, (16, 25, 7), (175, 7, 1))
assert_size_stride(primals_5, (16,), (1,))
assert_size_stride(primals_6, (10, 16, 7), (112, 7, 1))
assert_size_stride(primals_7, (10,), (1,))
assert_size_stride(primals_8, (1, 10, 1), (10, 1, 1))
assert_size_stride(primals_9, (1,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(reinterpret_tensor(primals_1, (4,
1, 4), (4, 4, 1), 0), primals_2, stride=(1,), padding=(4,),
dilation=(1,), transposed=False, output_padding=(0,), groups=1,
bias=None)
assert_size_stride(buf0, (4, 25, 4), (100, 4, 1))
buf1 = empty_strided_cuda((4, 25, 4), (100, 4, 1), torch.bool)
buf2 = empty_strided_cuda((4, 25, 4), (100, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_convolution_leaky_relu_0[grid(400)](buf0,
primals_3, buf1, buf2, 400, XBLOCK=128, num_warps=4, num_stages=1)
del buf0
del primals_3
buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1,),
padding=(3,), dilation=(1,), transposed=False, output_padding=(
0,), groups=1, bias=None)
assert_size_stride(buf3, (4, 16, 4), (64, 4, 1))
buf4 = empty_strided_cuda((4, 16, 4), (64, 4, 1), torch.bool)
buf5 = empty_strided_cuda((4, 16, 4), (64, 4, 1), torch.float32)
triton_poi_fused_convolution_leaky_relu_1[grid(256)](buf3,
primals_5, buf4, buf5, 256, XBLOCK=256, num_warps=4, num_stages=1)
del buf3
del primals_5
buf6 = extern_kernels.convolution(buf5, primals_6, stride=(1,),
padding=(3,), dilation=(1,), transposed=False, output_padding=(
0,), groups=1, bias=None)
assert_size_stride(buf6, (4, 10, 4), (40, 4, 1))
buf7 = empty_strided_cuda((4, 10, 4), (40, 4, 1), torch.bool)
buf8 = empty_strided_cuda((4, 10, 4), (40, 4, 1), torch.float32)
triton_poi_fused_convolution_leaky_relu_2[grid(160)](buf6,
primals_7, buf7, buf8, 160, XBLOCK=128, num_warps=4, num_stages=1)
del buf6
del primals_7
buf9 = extern_kernels.convolution(buf8, primals_8, stride=(1,),
padding=(0,), dilation=(1,), transposed=False, output_padding=(
0,), groups=1, bias=None)
assert_size_stride(buf9, (4, 1, 4), (4, 4, 1))
buf10 = buf9
del buf9
buf11 = empty_strided_cuda((4, 1, 4), (4, 4, 1), torch.bool)
triton_poi_fused_convolution_relu_threshold_backward_3[grid(16)](buf10,
primals_9, buf11, 16, XBLOCK=16, num_warps=1, num_stages=1)
del primals_9
return reinterpret_tensor(buf10, (4, 4), (4, 1), 0
), primals_2, primals_4, primals_6, primals_8, reinterpret_tensor(
primals_1, (4, 1, 4), (4, 4, 1), 0
), buf1, buf2, buf4, buf5, buf7, buf8, buf11
class Net_1New(nn.Module):
def __init__(self):
super(Net_1New, self).__init__()
self.conv1 = nn.Conv1d(1, 25, 9, padding=4)
self.conv2 = nn.Conv1d(25, 16, 7, padding=3)
self.conv3 = nn.Conv1d(16, 10, 7, padding=3)
self.conv4 = nn.Conv1d(10, 1, 1)
def forward(self, input_0):
primals_2 = self.conv1.weight
primals_3 = self.conv1.bias
primals_4 = self.conv2.weight
primals_5 = self.conv2.bias
primals_6 = self.conv3.weight
primals_7 = self.conv3.bias
primals_8 = self.conv4.weight
primals_9 = self.conv4.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9])
return output[0]
|
TakaraResearch/Signal-Detection-with-Wasserstein-Loss
|
Net_1
| false
| 17,974
|
[
"BSD-3-Clause"
] | 9
|
f210bd0da7492a72bc204a5517e74ba515b5ad12
|
https://github.com/TakaraResearch/Signal-Detection-with-Wasserstein-Loss/tree/f210bd0da7492a72bc204a5517e74ba515b5ad12
|
GCN
|
import torch
import torch.nn.functional as F
import torch.autograd
import torch.nn as nn
class GraphConv(nn.Module):
def __init__(self, in_features, out_features, bias=False):
super(GraphConv, self).__init__()
self.in_features = in_features
self.out_features = out_features
self.W = nn.Parameter(torch.empty(size=(in_features, out_features)))
nn.init.xavier_uniform_(self.W.data, gain=1.414)
def forward(self, input, adj):
support = torch.mm(input, self.W)
output = torch.mm(adj, support)
return output
class GCN(nn.Module):
def __init__(self, nfeat, nhid, nclass, dropout):
super(GCN, self).__init__()
self.gc1 = GraphConv(nfeat, nhid)
self.gc2 = GraphConv(nhid, nclass)
self.dropout = dropout
def forward(self, x, adj):
x1 = F.relu(self.gc1(x, adj))
x2 = F.dropout(x1, self.dropout, training=self.training)
x3 = self.gc2(x2, adj)
return F.log_softmax(x3, dim=1), x2
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4])]
def get_init_inputs():
return [[], {'nfeat': 4, 'nhid': 4, 'nclass': 4, 'dropout': 0.5}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.autograd
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_relu_0(in_out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.full([1], 0, tl.int32)
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tl.store(in_out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused__log_softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused__log_softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp2 = tl_math.exp(tmp1)
tmp4 = tl_math.exp(tmp3)
tmp5 = tmp2 + tmp4
tmp7 = tl_math.exp(tmp6)
tmp8 = tmp5 + tmp7
tmp10 = tl_math.exp(tmp9)
tmp11 = tmp8 + tmp10
tmp12 = tl_math.log(tmp11)
tmp13 = tmp0 - tmp12
tl.store(out_ptr0 + x2, tmp13, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4, 4), (4, 1))
assert_size_stride(primals_4, (4, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_2, primals_1, out=buf0)
del primals_1
buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_3, buf0, out=buf1)
buf2 = buf1
del buf1
get_raw_stream(0)
triton_poi_fused_relu_0[grid(16)](buf2, 16, XBLOCK=16, num_warps=1,
num_stages=1)
buf3 = buf0
del buf0
extern_kernels.mm(buf2, primals_4, out=buf3)
buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_3, buf3, out=buf4)
buf5 = buf3
del buf3
triton_poi_fused__log_softmax_1[grid(16)](buf4, buf5, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf6 = buf4
del buf4
triton_poi_fused__log_softmax_2[grid(16)](buf5, buf6, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del buf5
return buf6, buf2, buf2, buf6, reinterpret_tensor(primals_3, (4, 4), (1,
4), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0
), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0)
class GraphConv(nn.Module):
def __init__(self, in_features, out_features, bias=False):
super(GraphConv, self).__init__()
self.in_features = in_features
self.out_features = out_features
self.W = nn.Parameter(torch.empty(size=(in_features, out_features)))
nn.init.xavier_uniform_(self.W.data, gain=1.414)
def forward(self, input, adj):
support = torch.mm(input, self.W)
output = torch.mm(adj, support)
return output
class GCNNew(nn.Module):
def __init__(self, nfeat, nhid, nclass, dropout):
super(GCNNew, self).__init__()
self.gc1 = GraphConv(nfeat, nhid)
self.gc2 = GraphConv(nhid, nclass)
self.dropout = dropout
def forward(self, input_0, input_1):
primals_1 = self.gc1.W
primals_2 = self.gc2.W
primals_3 = input_0
primals_4 = input_1
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0], output[1]
|
SsGood/MMGL
|
GCN
| false
| 17,975
|
[
"MIT"
] | 6
|
ea769e46fffb42559e764e2912c5b1dc17c10af2
|
https://github.com/SsGood/MMGL/tree/ea769e46fffb42559e764e2912c5b1dc17c10af2
|
PositionwiseFeedForward
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class PositionwiseFeedForward(nn.Module):
def __init__(self, individual_featured):
super(PositionwiseFeedForward, self).__init__()
self.w_1 = nn.Linear(individual_featured, 2 * individual_featured)
self.w_2 = nn.Linear(2 * individual_featured, individual_featured)
self.dropout = nn.Dropout(0.2)
def forward(self, x):
return self.w_2(self.dropout(F.relu(self.w_1(x))))
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'individual_featured': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 512
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 8
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x2, tmp4, xmask)
tl.store(out_ptr0 + x2, tmp6, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (8, 4), (4, 1))
assert_size_stride(primals_2, (8,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4, 8), (8, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 8), (8, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 8), (1, 4), 0), out=buf0)
del primals_1
buf1 = reinterpret_tensor(buf0, (4, 4, 4, 8), (128, 32, 8, 1), 0)
del buf0
buf3 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.bool)
get_raw_stream(0)
triton_poi_fused_relu_threshold_backward_0[grid(512)](buf1,
primals_2, buf3, 512, XBLOCK=128, num_warps=4, num_stages=1)
del primals_2
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 8), (
8, 1), 0), reinterpret_tensor(primals_4, (8, 4), (1, 8), 0),
alpha=1, beta=1, out=buf2)
del primals_5
return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0
), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), reinterpret_tensor(buf1, (64, 8), (8, 1), 0), primals_4, buf3
class PositionwiseFeedForwardNew(nn.Module):
def __init__(self, individual_featured):
super(PositionwiseFeedForwardNew, self).__init__()
self.w_1 = nn.Linear(individual_featured, 2 * individual_featured)
self.w_2 = nn.Linear(2 * individual_featured, individual_featured)
self.dropout = nn.Dropout(0.2)
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]
|
Sunner4nwpu/RA-UWML-AU-Pytorch
|
PositionwiseFeedForward
| false
| 17,976
|
[
"Apache-2.0"
] | 5
|
7d20b2f1ffa8a00595d1e75e0d1c15518a37a920
|
https://github.com/Sunner4nwpu/RA-UWML-AU-Pytorch/tree/7d20b2f1ffa8a00595d1e75e0d1c15518a37a920
|
FeedForwardLayer
|
import torch
import torch.nn.functional as F
import torch.autograd
import torch.nn as nn
class FeedForwardLayer(nn.Module):
def __init__(self, d_in, d_hid, dropout=0.1):
super().__init__()
self.w_1 = nn.Linear(d_in, d_hid)
self.w_2 = nn.Linear(d_hid, d_in)
self.layer_norm = nn.LayerNorm(d_in, eps=1e-06)
self.dropout = nn.Dropout(dropout)
def forward(self, x):
residual = x
x = self.w_2(F.gelu(self.w_1(x)))
x = self.dropout(x)
x += residual
x = self.layer_norm(x)
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'d_in': 4, 'd_hid': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
import torch.autograd
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_gelu_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 0.5
tmp2 = tmp0 * tmp1
tmp3 = 0.7071067811865476
tmp4 = tmp0 * tmp3
tmp5 = libdevice.erf(tmp4)
tmp6 = 1.0
tmp7 = tmp5 + tmp6
tmp8 = tmp2 * tmp7
tl.store(out_ptr0 + x0, tmp8, xmask)
@triton.jit
def triton_poi_fused_add_native_layer_norm_1(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
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_2(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x2, xmask)
tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp4 = tmp2 - tmp3
tmp6 = 1e-06
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) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (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_3, reinterpret_tensor(primals_1, (64,
4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0
), alpha=1, beta=1, out=buf0)
del primals_2
del primals_3
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_gelu_0[grid(256)](buf0, buf1, 256, XBLOCK=128,
num_warps=4, num_stages=1)
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 4), (
4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0),
alpha=1, beta=1, out=buf2)
del primals_5
buf3 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
buf4 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
triton_poi_fused_add_native_layer_norm_1[grid(64)](buf2, primals_1,
buf3, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_add_native_layer_norm_2[grid(256)](buf2, primals_1,
buf3, buf4, primals_6, primals_7, buf5, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del buf3
del buf4
del primals_7
return buf5, primals_1, primals_6, buf0, reinterpret_tensor(buf1, (64,
4), (4, 1), 0), buf2, primals_4
class FeedForwardLayerNew(nn.Module):
def __init__(self, d_in, d_hid, dropout=0.1):
super().__init__()
self.w_1 = nn.Linear(d_in, d_hid)
self.w_2 = nn.Linear(d_hid, d_in)
self.layer_norm = nn.LayerNorm(d_in, eps=1e-06)
self.dropout = nn.Dropout(dropout)
def forward(self, input_0):
primals_2 = self.w_1.weight
primals_3 = self.w_1.bias
primals_4 = self.w_2.weight
primals_5 = self.w_2.bias
primals_6 = self.layer_norm.weight
primals_7 = self.layer_norm.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7])
return output[0]
|
SsGood/MMGL
|
FeedForwardLayer
| false
| 17,977
|
[
"MIT"
] | 6
|
ea769e46fffb42559e764e2912c5b1dc17c10af2
|
https://github.com/SsGood/MMGL/tree/ea769e46fffb42559e764e2912c5b1dc17c10af2
|
Upsampling
|
import torch
import torch.nn as M
class Upsampling(M.Module):
def __init__(self, in_channels, out_channels, kernel_size=2):
super().__init__()
self.upsample = M.ConvTranspose2d(in_channels, out_channels,
kernel_size=kernel_size, stride=2)
def forward(self, x):
return self.upsample(x)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'out_channels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as M
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
@triton.jit
def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 64 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 2, 2), (16, 4, 2, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(2,
2), padding=(0, 0), dilation=(1, 1), transposed=True,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 4, 8, 8), (256, 64, 8, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(1024)](buf1, primals_2, 1024,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_2
return buf1, primals_1, primals_3
class UpsamplingNew(M.Module):
def __init__(self, in_channels, out_channels, kernel_size=2):
super().__init__()
self.upsample = M.ConvTranspose2d(in_channels, out_channels,
kernel_size=kernel_size, stride=2)
def forward(self, input_0):
primals_1 = self.upsample.weight
primals_2 = self.upsample.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
SuperbTUM/RAW-image-denoising
|
Upsampling
| false
| 17,978
|
[
"MIT"
] | 4
|
9f81be8da6a576f641022707d98b8c37f5c599ab
|
https://github.com/SuperbTUM/RAW-image-denoising/tree/9f81be8da6a576f641022707d98b8c37f5c599ab
|
Signal2SH
|
import torch
import numpy as np
import torch.nn as nn
from scipy import special as sci
def cart2sph(x, y, z):
"""
cart2sph(x, y, z) -> theta, phi, r
Computes the corresponding spherical coordinate of the given input parameters :attr:`x`, :attr:`y` and :attr:`x`.
Args:
x (Number): x position
y (Number): y position
z (Number): z position
Example::
>>> cart2sph(1, 1, 1)
(0.78539816339744828, 0.95531661812450919, 1.7320508075688772)
"""
azimuthal_angle = np.arctan2(y, x)
radial_distance = np.sqrt(x ** 2 + y ** 2 + z ** 2)
polar_angle = np.arccos(z / radial_distance)
return azimuthal_angle, polar_angle, radial_distance
class Signal2SH(nn.Module):
"""
Signal2SH(dwi) -> dwi_sh
Computes the corresponding spherical harmonic coefficients
Args:
x_in (5D tensor): input dwi tensor
x_in.size(): (Batchsize x Number of shells * Number of gradients x DimX x DimY x DimZ)
y (5D tensor): corresponding harmonic coefficients tensor
y.size(): (Batchsize x Number of shells*Number of coefficients x DimX x DimY x DimZ)
"""
def __init__(self, sh_order, gradients, lb_lambda=0.006):
super(Signal2SH, self).__init__()
self.sh_order = sh_order
self.lb_lambda = lb_lambda
self.num_gradients = gradients.shape[0]
self.num_coefficients = int((self.sh_order + 1) * (self.sh_order /
2 + 1))
b = np.zeros((self.num_gradients, self.num_coefficients))
l = np.zeros((self.num_coefficients, self.num_coefficients))
for id_gradient in range(self.num_gradients):
id_column = 0
for id_order in range(0, self.sh_order + 1, 2):
for id_degree in range(-id_order, id_order + 1):
gradients_phi, gradients_theta, _gradients_z = cart2sph(
gradients[id_gradient, 0], gradients[id_gradient, 1
], gradients[id_gradient, 2])
y = sci.sph_harm(np.abs(id_degree), id_order,
gradients_phi, gradients_theta)
if id_degree < 0:
b[id_gradient, id_column] = np.real(y) * np.sqrt(2)
elif id_degree == 0:
b[id_gradient, id_column] = np.real(y)
elif id_degree > 0:
b[id_gradient, id_column] = np.imag(y) * np.sqrt(2)
l[id_column, id_column
] = self.lb_lambda * id_order ** 2 * (id_order + 1
) ** 2
id_column += 1
b_inv = np.linalg.pinv(np.matmul(b.transpose(), b) + l)
self.Signal2SHMat = torch.nn.Parameter(torch.from_numpy(np.matmul(
b_inv, b.transpose()).transpose()).float(), requires_grad=False)
def forward(self, x_in):
x = x_in.reshape((-1, np.ceil(x_in.size(1) / self.num_gradients).
astype(int), self.num_gradients, x_in.size(2), x_in.size(3),
x_in.size(4)))
x = x.permute(0, 1, 3, 4, 5, 2)
y = x.matmul(self.Signal2SHMat)
y = y.permute(0, 1, 5, 2, 3, 4).contiguous().reshape((x.size(0), -1,
x_in.size(2), x_in.size(3), x_in.size(4)))
return y
def get_inputs():
return [torch.rand([4, 4, 4, 4, 4])]
def get_init_inputs():
return [[], {'sh_order': 4, 'gradients': torch.rand([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
import numpy as np
import torch.nn as nn
from scipy import special as sci
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 = 256
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 % 64
y1 = yindex // 64
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 64 * x2 + 256 * y1), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_clone_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 60
xnumel = 64
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 % 15
y1 = yindex // 15
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 15 * x2 + 960 * y1), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 64 * y3), tmp0, xmask & ymask)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 15), (1, 4))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 1, 4, 4, 4, 4), (256, 256, 64, 16, 4,
1), torch.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(256, 4)](arg0_1, buf0, 256, 4, XBLOCK
=4, YBLOCK=256, num_warps=4, num_stages=1)
del arg0_1
buf1 = empty_strided_cuda((64, 4, 15), (60, 15, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf0, (64, 4, 4), (16, 4, 1),
0), reinterpret_tensor(arg1_1, (64, 4, 15), (0, 1, 4), 0), out=buf1
)
del arg1_1
del buf0
buf2 = empty_strided_cuda((4, 1, 15, 4, 4, 4), (960, 960, 64, 16, 4,
1), torch.float32)
triton_poi_fused_clone_1[grid(60, 64)](buf1, buf2, 60, 64, XBLOCK=
32, YBLOCK=32, num_warps=4, num_stages=1)
del buf1
return reinterpret_tensor(buf2, (4, 15, 4, 4, 4), (960, 64, 16, 4, 1), 0),
def cart2sph(x, y, z):
"""
cart2sph(x, y, z) -> theta, phi, r
Computes the corresponding spherical coordinate of the given input parameters :attr:`x`, :attr:`y` and :attr:`x`.
Args:
x (Number): x position
y (Number): y position
z (Number): z position
Example::
>>> cart2sph(1, 1, 1)
(0.78539816339744828, 0.95531661812450919, 1.7320508075688772)
"""
azimuthal_angle = np.arctan2(y, x)
radial_distance = np.sqrt(x ** 2 + y ** 2 + z ** 2)
polar_angle = np.arccos(z / radial_distance)
return azimuthal_angle, polar_angle, radial_distance
class Signal2SHNew(nn.Module):
"""
Signal2SH(dwi) -> dwi_sh
Computes the corresponding spherical harmonic coefficients
Args:
x_in (5D tensor): input dwi tensor
x_in.size(): (Batchsize x Number of shells * Number of gradients x DimX x DimY x DimZ)
y (5D tensor): corresponding harmonic coefficients tensor
y.size(): (Batchsize x Number of shells*Number of coefficients x DimX x DimY x DimZ)
"""
def __init__(self, sh_order, gradients, lb_lambda=0.006):
super(Signal2SHNew, self).__init__()
self.sh_order = sh_order
self.lb_lambda = lb_lambda
self.num_gradients = gradients.shape[0]
self.num_coefficients = int((self.sh_order + 1) * (self.sh_order /
2 + 1))
b = np.zeros((self.num_gradients, self.num_coefficients))
l = np.zeros((self.num_coefficients, self.num_coefficients))
for id_gradient in range(self.num_gradients):
id_column = 0
for id_order in range(0, self.sh_order + 1, 2):
for id_degree in range(-id_order, id_order + 1):
gradients_phi, gradients_theta, _gradients_z = cart2sph(
gradients[id_gradient, 0], gradients[id_gradient, 1
], gradients[id_gradient, 2])
y = sci.sph_harm(np.abs(id_degree), id_order,
gradients_phi, gradients_theta)
if id_degree < 0:
b[id_gradient, id_column] = np.real(y) * np.sqrt(2)
elif id_degree == 0:
b[id_gradient, id_column] = np.real(y)
elif id_degree > 0:
b[id_gradient, id_column] = np.imag(y) * np.sqrt(2)
l[id_column, id_column
] = self.lb_lambda * id_order ** 2 * (id_order + 1
) ** 2
id_column += 1
b_inv = np.linalg.pinv(np.matmul(b.transpose(), b) + l)
self.Signal2SHMat = torch.nn.Parameter(torch.from_numpy(np.matmul(
b_inv, b.transpose()).transpose()).float(), requires_grad=False)
def forward(self, input_0):
arg1_1 = self.Signal2SHMat
arg0_1 = input_0
output = call([arg0_1, arg1_1])
return output[0]
|
SimonKoppers/DELIMIT
|
Signal2SH
| false
| 17,979
|
[
"MIT"
] | 7
|
d778a567bbec1beef2395ead60aa1e30086bb07c
|
https://github.com/SimonKoppers/DELIMIT/tree/d778a567bbec1beef2395ead60aa1e30086bb07c
|
TransformerEncoderLayer
|
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.nn.parallel
import torch.utils.data
import torch.distributions
class TransformerEncoderLayer(nn.Module):
def __init__(self, embed_dim, num_heads, hidden_size, dropout=0.0,
attention_dropout=0.0, activation_dropout=0.0):
super().__init__()
self.embed_dim = embed_dim
self.self_attn = torch.nn.MultiheadAttention(embed_dim=self.
embed_dim, num_heads=num_heads, dropout=attention_dropout)
self.self_attn_layer_norm = torch.nn.LayerNorm(self.embed_dim)
self.dropout = dropout
self.activation_dropout = activation_dropout
self.normalize_before = True
self.fc1 = torch.nn.Linear(self.embed_dim, hidden_size)
self.fc2 = torch.nn.Linear(hidden_size, self.embed_dim)
self.layer_norm = torch.nn.LayerNorm(self.embed_dim)
self.init_parameters()
def forward(self, x, key_padding_mask=None, attn_mask=None):
residual = x
x = self.self_attn_layer_norm(x)
x, _att = self.self_attn(query=x, key=x, value=x, key_padding_mask=
key_padding_mask, attn_mask=attn_mask)
x = F.dropout(x, p=self.dropout, training=self.training)
x = residual + x
residual = x
x = self.layer_norm(x)
x = F.relu(self.fc1(x))
x = F.dropout(x, p=self.activation_dropout, training=self.training)
x = self.fc2(x)
x = F.dropout(x, p=self.dropout, training=self.training)
x = residual + x
return x
def init_parameters(self):
nn.init.xavier_uniform_(self.fc1.weight)
nn.init.constant_(self.fc1.bias, 0.0)
nn.init.xavier_uniform_(self.fc2.weight)
nn.init.constant_(self.fc2.bias, 0.0)
def get_inputs():
return [torch.rand([4, 4])]
def get_init_inputs():
return [[], {'embed_dim': 4, 'num_heads': 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
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
import torch.nn as nn
import torch.nn.parallel
import torch.utils.data
import torch.distributions
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_native_layer_norm_0(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp7 = 4.0
tmp8 = tmp6 / tmp7
tmp9 = tmp0 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tmp1 - tmp8
tmp12 = tmp11 * tmp11
tmp13 = tmp10 + tmp12
tmp14 = tmp3 - tmp8
tmp15 = tmp14 * tmp14
tmp16 = tmp13 + tmp15
tmp17 = tmp5 - tmp8
tmp18 = tmp17 * tmp17
tmp19 = tmp16 + tmp18
tmp20 = tmp19 / tmp7
tmp21 = 1e-05
tmp22 = tmp20 + tmp21
tmp23 = libdevice.rsqrt(tmp22)
tl.store(out_ptr0 + x0, tmp8, xmask)
tl.store(out_ptr1 + x0, tmp23, xmask)
@triton.jit
def triton_poi_fused_native_layer_norm_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = tmp2 * tmp3
tmp6 = tmp4 * tmp5
tmp8 = tmp6 + tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused_mul_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 1.0
tmp4 = tmp2 * tmp3
tl.store(in_out_ptr0 + x2, tmp4, xmask)
@triton.jit
def triton_poi_fused__softmax_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x2, tmp9, xmask)
@triton.jit
def triton_poi_fused__softmax_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused_clone_5(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 4
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x1 = xindex
y0 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x1), xmask & ymask)
tl.store(out_ptr0 + (x1 + 4 * y0), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_add_native_layer_norm_6(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_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_7(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x2, xmask)
tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp4 = tmp2 - tmp3
tmp6 = 1e-05
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp4 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tl.store(out_ptr0 + x2, tmp13, xmask)
@triton.jit
def triton_poi_fused_relu_8(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x2, tmp4, xmask)
@triton.jit
def triton_poi_fused_add_9(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel,
XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x2, xmask)
tmp3 = tl.load(in_out_ptr0 + x2, xmask)
tmp4 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp5 = tmp3 + tmp4
tmp6 = tmp2 + tmp5
tl.store(in_out_ptr0 + x2, tmp6, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
primals_13) = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (12, 4), (4, 1))
assert_size_stride(primals_5, (12,), (1,))
assert_size_stride(primals_6, (4, 4), (4, 1))
assert_size_stride(primals_7, (4,), (1,))
assert_size_stride(primals_8, (4,), (1,))
assert_size_stride(primals_9, (4,), (1,))
assert_size_stride(primals_10, (4, 4), (4, 1))
assert_size_stride(primals_11, (4,), (1,))
assert_size_stride(primals_12, (4, 4), (4, 1))
assert_size_stride(primals_13, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
buf1 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
get_raw_stream(0)
triton_poi_fused_native_layer_norm_0[grid(4)](primals_1, buf0, buf1,
4, XBLOCK=4, num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused_native_layer_norm_1[grid(16)](primals_1, buf0,
buf1, primals_2, primals_3, buf2, 16, XBLOCK=16, num_warps=1,
num_stages=1)
del primals_2
del primals_3
buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf2, reinterpret_tensor(primals_4, (4, 4), (1, 4
), 0), out=buf3)
buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(reinterpret_tensor(primals_5, (4,), (1,), 4),
buf2, reinterpret_tensor(primals_4, (4, 4), (1, 4), 16), alpha=
1, beta=1, out=buf4)
buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(reinterpret_tensor(primals_5, (4,), (1,), 8),
buf2, reinterpret_tensor(primals_4, (4, 4), (1, 4), 32), alpha=
1, beta=1, out=buf5)
buf6 = reinterpret_tensor(buf3, (4, 4, 1), (1, 4, 16), 0)
del buf3
triton_poi_fused_mul_2[grid(16)](buf6, primals_5, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del primals_5
buf7 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf6, reinterpret_tensor(buf4, (4, 1, 4), (1, 1,
4), 0), out=buf7)
buf8 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_3[grid(64)](buf7, buf8, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf9 = buf7
del buf7
triton_poi_fused__softmax_4[grid(64)](buf8, buf9, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del buf8
buf10 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32)
extern_kernels.bmm(buf9, reinterpret_tensor(buf5, (4, 4, 1), (1, 4,
1), 0), out=buf10)
buf11 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32)
triton_poi_fused_clone_5[grid(4, 4)](buf10, buf11, 4, 4, XBLOCK=4,
YBLOCK=4, num_warps=1, num_stages=1)
buf12 = reinterpret_tensor(buf10, (4, 4), (4, 1), 0)
del buf10
extern_kernels.addmm(primals_7, reinterpret_tensor(buf11, (4, 4), (
4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0),
alpha=1, beta=1, out=buf12)
del primals_7
buf13 = buf1
del buf1
buf14 = buf0
del buf0
triton_poi_fused_add_native_layer_norm_6[grid(4)](primals_1, buf12,
buf13, buf14, 4, XBLOCK=4, num_warps=1, num_stages=1)
buf15 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused_add_native_layer_norm_7[grid(16)](primals_1, buf12,
buf13, buf14, primals_8, primals_9, buf15, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del buf13
del buf14
del primals_9
buf16 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf15, reinterpret_tensor(primals_10, (4, 4), (1,
4), 0), out=buf16)
buf17 = buf16
del buf16
triton_poi_fused_relu_8[grid(16)](buf17, primals_11, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del primals_11
buf18 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf17, reinterpret_tensor(primals_12, (4, 4), (1,
4), 0), out=buf18)
buf19 = buf18
del buf18
triton_poi_fused_add_9[grid(16)](buf19, primals_1, buf12,
primals_13, 16, XBLOCK=16, num_warps=1, num_stages=1)
del primals_13
return (buf19, primals_1, primals_8, buf2, buf9, reinterpret_tensor(
buf11, (4, 4), (4, 1), 0), buf12, buf15, buf17, primals_12,
primals_10, primals_6, reinterpret_tensor(buf5, (4, 1, 4), (1, 1, 4
), 0), reinterpret_tensor(buf6, (4, 1, 4), (1, 1, 4), 0),
reinterpret_tensor(buf4, (4, 4, 1), (1, 4, 1), 0),
reinterpret_tensor(primals_4, (4, 4), (4, 1), 32),
reinterpret_tensor(primals_4, (4, 4), (4, 1), 16),
reinterpret_tensor(primals_4, (4, 4), (4, 1), 0))
class TransformerEncoderLayerNew(nn.Module):
def __init__(self, embed_dim, num_heads, hidden_size, dropout=0.0,
attention_dropout=0.0, activation_dropout=0.0):
super().__init__()
self.embed_dim = embed_dim
self.self_attn = torch.nn.MultiheadAttention(embed_dim=self.
embed_dim, num_heads=num_heads, dropout=attention_dropout)
self.self_attn_layer_norm = torch.nn.LayerNorm(self.embed_dim)
self.dropout = dropout
self.activation_dropout = activation_dropout
self.normalize_before = True
self.fc1 = torch.nn.Linear(self.embed_dim, hidden_size)
self.fc2 = torch.nn.Linear(hidden_size, self.embed_dim)
self.layer_norm = torch.nn.LayerNorm(self.embed_dim)
self.init_parameters()
def init_parameters(self):
nn.init.xavier_uniform_(self.fc1.weight)
nn.init.constant_(self.fc1.bias, 0.0)
nn.init.xavier_uniform_(self.fc2.weight)
nn.init.constant_(self.fc2.bias, 0.0)
def forward(self, input_0):
primals_4 = self.self_attn.in_proj_weight
primals_5 = self.self_attn.in_proj_bias
primals_1 = self.self_attn.out_proj.weight
primals_2 = self.self_attn.out_proj.bias
primals_3 = self.self_attn_layer_norm.weight
primals_7 = self.self_attn_layer_norm.bias
primals_6 = self.fc1.weight
primals_8 = self.fc1.bias
primals_10 = self.fc2.weight
primals_9 = self.fc2.bias
primals_11 = self.layer_norm.weight
primals_13 = self.layer_norm.bias
primals_12 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11, primals_12, primals_13])
return output[0]
|
Slowika/GameBias-EmeCom2020
|
TransformerEncoderLayer
| false
| 17,980
|
[
"MIT"
] | 5
|
5b94c47559f8202bca99c26fc1bcb078dd0509a6
|
https://github.com/Slowika/GameBias-EmeCom2020/tree/5b94c47559f8202bca99c26fc1bcb078dd0509a6
|
PartialConv
|
import math
import torch
from itertools import product as product
import torch.nn as nn
def weights_init(init_type='gaussian'):
def init_fun(m):
classname = m.__class__.__name__
if (classname.find('Conv') == 0 or classname.find('Linear') == 0
) and hasattr(m, 'weight'):
if init_type == 'gaussian':
nn.init.normal_(m.weight, 0.0, 0.02)
elif init_type == 'xavier':
nn.init.xavier_normal_(m.weight, gain=math.sqrt(2))
elif init_type == 'kaiming':
nn.init.kaiming_normal_(m.weight, a=0, mode='fan_in')
elif init_type == 'orthogonal':
nn.init.orthogonal_(m.weight, gain=math.sqrt(2))
elif init_type == 'default':
pass
else:
assert 0, 'Unsupported initialization: {}'.format(init_type)
if hasattr(m, 'bias') and m.bias is not None:
nn.init.constant_(m.bias, 0.0)
return init_fun
class PartialConv(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size, stride=1,
padding=0, dilation=1, groups=1, bias=True):
super().__init__()
self.input_conv = nn.Conv2d(in_channels, out_channels, kernel_size,
stride, padding, dilation, groups, bias)
self.mask_conv = nn.Conv2d(in_channels, out_channels, kernel_size,
stride, padding, dilation, groups, False)
self.input_conv.apply(weights_init('kaiming'))
torch.nn.init.constant_(self.mask_conv.weight, 1.0)
for param in self.mask_conv.parameters():
param.requires_grad = False
def forward(self, input, mask):
output = self.input_conv(input * mask)
if self.input_conv.bias is not None:
output_bias = self.input_conv.bias.view(1, -1, 1, 1).expand_as(
output)
else:
output_bias = torch.zeros_like(output)
with torch.no_grad():
output_mask = self.mask_conv(mask)
no_update_holes = output_mask == 0
mask_sum = output_mask.masked_fill_(no_update_holes, 1.0)
output_pre = (output - output_bias) / mask_sum + output_bias
output = output_pre.masked_fill_(no_update_holes, 0.0)
new_mask = torch.ones_like(output)
new_mask = new_mask.masked_fill_(no_update_holes, 0.0)
return output, new_mask
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'out_channels': 4, '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 math
from itertools import product as product
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 + x0, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask)
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused_add_convolution_div_eq_masked_fill_ones_like_sub_1(
in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp3 = tl.load(in_out_ptr0 + x2, xmask)
tmp4 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp1 = 0.0
tmp2 = tmp0 == tmp1
tmp5 = tmp3 + tmp4
tmp6 = tmp5 - tmp4
tmp7 = 1.0
tmp8 = tl.where(tmp2, tmp7, tmp0)
tmp9 = tmp6 / tmp8
tmp10 = tmp9 + tmp4
tmp11 = tl.where(tmp2, tmp1, tmp10)
tmp12 = tl.where(tmp2, tmp1, tmp7)
tl.store(in_out_ptr0 + x2, tmp11, xmask)
tl.store(out_ptr0 + x2, tmp12, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4,), (1,))
assert_size_stride(primals_5, (4, 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=128, num_warps=4, num_stages=1)
del primals_1
buf1 = extern_kernels.convolution(buf0, primals_3, 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))
buf2 = extern_kernels.convolution(primals_2, primals_5, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 4, 1, 1), (4, 1, 1, 1))
del primals_2
del primals_5
buf3 = buf1
del buf1
buf4 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32)
triton_poi_fused_add_convolution_div_eq_masked_fill_ones_like_sub_1[
grid(16)](buf3, buf2, primals_4, buf4, 16, XBLOCK=16, num_warps
=1, num_stages=1)
del primals_4
return buf3, buf4, primals_3, buf0, buf2
def weights_init(init_type='gaussian'):
def init_fun(m):
classname = m.__class__.__name__
if (classname.find('Conv') == 0 or classname.find('Linear') == 0
) and hasattr(m, 'weight'):
if init_type == 'gaussian':
nn.init.normal_(m.weight, 0.0, 0.02)
elif init_type == 'xavier':
nn.init.xavier_normal_(m.weight, gain=math.sqrt(2))
elif init_type == 'kaiming':
nn.init.kaiming_normal_(m.weight, a=0, mode='fan_in')
elif init_type == 'orthogonal':
nn.init.orthogonal_(m.weight, gain=math.sqrt(2))
elif init_type == 'default':
pass
else:
assert 0, 'Unsupported initialization: {}'.format(init_type)
if hasattr(m, 'bias') and m.bias is not None:
nn.init.constant_(m.bias, 0.0)
return init_fun
class PartialConvNew(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size, stride=1,
padding=0, dilation=1, groups=1, bias=True):
super().__init__()
self.input_conv = nn.Conv2d(in_channels, out_channels, kernel_size,
stride, padding, dilation, groups, bias)
self.mask_conv = nn.Conv2d(in_channels, out_channels, kernel_size,
stride, padding, dilation, groups, False)
self.input_conv.apply(weights_init('kaiming'))
torch.nn.init.constant_(self.mask_conv.weight, 1.0)
for param in self.mask_conv.parameters():
param.requires_grad = False
def forward(self, input_0, input_1):
primals_1 = self.input_conv.weight
primals_4 = self.input_conv.bias
primals_2 = self.mask_conv.weight
primals_3 = input_0
primals_5 = input_1
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0], output[1]
|
TaroNakasendo/MaskEraser
|
PartialConv
| false
| 17,981
|
[
"MIT"
] | 3
|
373af686194aff716f53785e40252beae7b26cff
|
https://github.com/TaroNakasendo/MaskEraser/tree/373af686194aff716f53785e40252beae7b26cff
|
NaiveGroupNorm
|
from torch.nn import Module
import torch
from torch.nn import Parameter
from torch.nn import init
import torch.nn.parallel
class NaiveGroupNorm(Module):
"""NaiveGroupNorm implements Group Normalization with the high-level matrix operations in PyTorch.
It is a temporary solution to export GN by ONNX before the official GN can be exported by ONNX.
The usage of NaiveGroupNorm is exactly the same as the official :class:`torch.nn.GroupNorm`.
Args:
num_groups (int): number of groups to separate the channels into
num_channels (int): number of channels expected in input
eps: a value added to the denominator for numerical stability. Default: 1e-5
affine: a boolean value that when set to ``True``, this module
has learnable per-channel affine parameters initialized to ones (for weights)
and zeros (for biases). Default: ``True``.
Shape:
- Input: :math:`(N, C, *)` where :math:`C=\\text{num\\_channels}`
- Output: :math:`(N, C, *)` (same shape as input)
Examples::
>>> input = torch.randn(20, 6, 10, 10)
>>> # Separate 6 channels into 3 groups
>>> m = NaiveGroupNorm(3, 6)
>>> # Separate 6 channels into 6 groups (equivalent with InstanceNorm)
>>> m = NaiveGroupNorm(6, 6)
>>> # Put all 6 channels into a single group (equivalent with LayerNorm)
>>> m = NaiveGroupNorm(1, 6)
>>> # Activating the module
>>> output = m(input)
.. _`Group Normalization`: https://arxiv.org/abs/1803.08494
"""
__constants__ = ['num_groups', 'num_channels', 'eps', 'affine',
'weight', 'bias']
def __init__(self, num_groups, num_channels, eps=1e-05, affine=True):
super(NaiveGroupNorm, self).__init__()
self.num_groups = num_groups
self.num_channels = num_channels
self.eps = eps
self.affine = affine
if self.affine:
self.weight = Parameter(torch.Tensor(num_channels))
self.bias = Parameter(torch.Tensor(num_channels))
else:
self.register_parameter('weight', None)
self.register_parameter('bias', None)
self.reset_parameters()
def reset_parameters(self):
if self.affine:
init.ones_(self.weight)
init.zeros_(self.bias)
def forward(self, input):
N, C, H, W = input.size()
assert C % self.num_groups == 0
input = input.reshape(N, self.num_groups, -1)
mean = input.mean(dim=-1, keepdim=True)
var = (input ** 2).mean(dim=-1, keepdim=True) - mean ** 2
std = torch.sqrt(var + self.eps)
input = (input - mean) / std
input = input.reshape(N, C, H, W)
if self.affine:
input = input * self.weight.reshape(1, C, 1, 1
) + self.bias.reshape(1, C, 1, 1)
return input
def extra_repr(self):
return ('{num_groups}, {num_channels}, eps={eps}, affine={affine}'.
format(**self.__dict__))
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'num_groups': 1, 'num_channels': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
from torch.nn import Module
from torch.nn import Parameter
from torch.nn import init
import torch.nn.parallel
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_per_fused_add_mean_mul_pow_sqrt_sub_0(in_out_ptr0, in_out_ptr1,
in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 4
RBLOCK: tl.constexpr = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
r3 = rindex // 16
tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0)
tmp20 = tl.load(in_ptr1 + r3, None, eviction_policy='evict_last')
tmp22 = tl.load(in_ptr2 + r3, None, eviction_policy='evict_last')
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(xmask, tmp1, 0)
tmp4 = tl.sum(tmp3, 1)[:, None]
tmp5 = tmp0 * tmp0
tmp6 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK])
tmp8 = tl.where(xmask, tmp6, 0)
tmp9 = tl.sum(tmp8, 1)[:, None]
tmp10 = 64.0
tmp11 = tmp4 / tmp10
tmp12 = tmp9 / tmp10
tmp13 = tmp11 * tmp11
tmp14 = tmp12 - tmp13
tmp15 = 1e-05
tmp16 = tmp14 + tmp15
tmp17 = libdevice.sqrt(tmp16)
tmp18 = tmp0 - tmp11
tmp19 = tmp18 / tmp17
tmp21 = tmp19 * tmp20
tmp23 = tmp21 + tmp22
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp11, xmask)
tl.debug_barrier()
tl.store(in_out_ptr1 + x0, tmp17, xmask)
tl.store(out_ptr0 + (r1 + 64 * x0), tmp23, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 1, 1), (1, 4, 4), torch.float32)
buf2 = empty_strided_cuda((4, 1, 1), (1, 4, 4), torch.float32)
buf1 = reinterpret_tensor(buf0, (4, 1, 1), (1, 1, 1), 0)
del buf0
buf3 = reinterpret_tensor(buf2, (4, 1, 1), (1, 1, 1), 0)
del buf2
buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_per_fused_add_mean_mul_pow_sqrt_sub_0[grid(4)](buf1, buf3,
primals_1, primals_2, primals_3, buf4, 4, 64, XBLOCK=1,
num_warps=2, num_stages=1)
del primals_2
del primals_3
return buf4, primals_1, buf1, buf3
class NaiveGroupNormNew(Module):
"""NaiveGroupNorm implements Group Normalization with the high-level matrix operations in PyTorch.
It is a temporary solution to export GN by ONNX before the official GN can be exported by ONNX.
The usage of NaiveGroupNorm is exactly the same as the official :class:`torch.nn.GroupNorm`.
Args:
num_groups (int): number of groups to separate the channels into
num_channels (int): number of channels expected in input
eps: a value added to the denominator for numerical stability. Default: 1e-5
affine: a boolean value that when set to ``True``, this module
has learnable per-channel affine parameters initialized to ones (for weights)
and zeros (for biases). Default: ``True``.
Shape:
- Input: :math:`(N, C, *)` where :math:`C=\\text{num\\_channels}`
- Output: :math:`(N, C, *)` (same shape as input)
Examples::
>>> input = torch.randn(20, 6, 10, 10)
>>> # Separate 6 channels into 3 groups
>>> m = NaiveGroupNorm(3, 6)
>>> # Separate 6 channels into 6 groups (equivalent with InstanceNorm)
>>> m = NaiveGroupNorm(6, 6)
>>> # Put all 6 channels into a single group (equivalent with LayerNorm)
>>> m = NaiveGroupNorm(1, 6)
>>> # Activating the module
>>> output = m(input)
.. _`Group Normalization`: https://arxiv.org/abs/1803.08494
"""
__constants__ = ['num_groups', 'num_channels', 'eps', 'affine',
'weight', 'bias']
def __init__(self, num_groups, num_channels, eps=1e-05, affine=True):
super(NaiveGroupNormNew, self).__init__()
self.num_groups = num_groups
self.num_channels = num_channels
self.eps = eps
self.affine = affine
if self.affine:
self.weight = Parameter(torch.Tensor(num_channels))
self.bias = Parameter(torch.Tensor(num_channels))
else:
self.register_parameter('weight', None)
self.register_parameter('bias', None)
self.reset_parameters()
def reset_parameters(self):
if self.affine:
init.ones_(self.weight)
init.zeros_(self.bias)
def extra_repr(self):
return ('{num_groups}, {num_channels}, eps={eps}, affine={affine}'.
format(**self.__dict__))
def forward(self, input_0):
primals_2 = self.weight
primals_3 = self.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
Tanveer81/BoxVOS
|
NaiveGroupNorm
| false
| 17,982
|
[
"BSD-2-Clause"
] | 4
|
c30aa319f18f3fbee2a25e0ed25cb006a4598300
|
https://github.com/Tanveer81/BoxVOS/tree/c30aa319f18f3fbee2a25e0ed25cb006a4598300
|
eSEModule
|
import torch
from torch import nn
import torch.nn.functional as F
import torch.nn.parallel
class Hsigmoid(nn.Module):
def __init__(self, inplace=True):
super(Hsigmoid, self).__init__()
self.inplace = inplace
def forward(self, x):
return F.relu6(x + 3.0, inplace=self.inplace) / 6.0
class eSEModule(nn.Module):
def __init__(self, channel, reduction=4):
super(eSEModule, self).__init__()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.fc = nn.Conv2d(channel, channel, kernel_size=1, padding=0)
self.hsigmoid = Hsigmoid()
def forward(self, x):
input = x
x = self.avg_pool(x)
x = self.fc(x)
x = self.hsigmoid(x)
return input * x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'channel': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch import nn
import torch.nn.functional as F
import torch.nn.parallel
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_per_fused_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK:
tl.constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(xmask, tmp1, 0)
tmp4 = tl.sum(tmp3, 1)[:, None]
tmp5 = 16.0
tmp6 = tmp4 / tmp5
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp6, xmask)
@triton.jit
def triton_poi_fused_add_convolution_div_hardtanh_mul_1(in_ptr0, in_ptr1,
in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x4 = xindex // 16
x1 = xindex // 16 % 4
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + x4, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp4 = 3.0
tmp5 = tmp3 + tmp4
tmp6 = 0.0
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = 6.0
tmp9 = triton_helpers.minimum(tmp7, tmp8)
tmp10 = 0.16666666666666666
tmp11 = tmp9 * tmp10
tmp12 = tmp0 * tmp11
tl.store(out_ptr0 + x3, tmp12, xmask)
@triton.jit
def triton_poi_fused_add_convolution_hardtanh_backward_2(in_ptr0, in_ptr1,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
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 = 3.0
tmp4 = tmp2 + tmp3
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tmp7 = 6.0
tmp8 = tmp4 >= tmp7
tmp9 = tmp6 | tmp8
tl.store(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, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_3, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32)
buf1 = reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0)
del buf0
get_raw_stream(0)
triton_per_fused_mean_0[grid(16)](buf1, primals_1, 16, 16, XBLOCK=8,
num_warps=2, num_stages=1)
buf2 = extern_kernels.convolution(buf1, primals_2, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 4, 1, 1), (4, 1, 1, 1))
buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_add_convolution_div_hardtanh_mul_1[grid(256)](
primals_1, buf2, primals_3, buf3, 256, XBLOCK=128, num_warps=4,
num_stages=1)
buf4 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.bool)
triton_poi_fused_add_convolution_hardtanh_backward_2[grid(16)](buf2,
primals_3, buf4, 16, XBLOCK=16, num_warps=1, num_stages=1)
del buf2
del primals_3
return buf3, primals_1, primals_2, buf1, buf4
class Hsigmoid(nn.Module):
def __init__(self, inplace=True):
super(Hsigmoid, self).__init__()
self.inplace = inplace
def forward(self, x):
return F.relu6(x + 3.0, inplace=self.inplace) / 6.0
class eSEModuleNew(nn.Module):
def __init__(self, channel, reduction=4):
super(eSEModuleNew, self).__init__()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.fc = nn.Conv2d(channel, channel, kernel_size=1, padding=0)
self.hsigmoid = Hsigmoid()
def forward(self, input_0):
primals_2 = self.fc.weight
primals_3 = self.fc.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
Tanveer81/BoxVOS
|
eSEModule
| false
| 17,983
|
[
"BSD-2-Clause"
] | 4
|
c30aa319f18f3fbee2a25e0ed25cb006a4598300
|
https://github.com/Tanveer81/BoxVOS/tree/c30aa319f18f3fbee2a25e0ed25cb006a4598300
|
GCN
|
import torch
from torch import nn
import torch.nn.functional as F
import torch.nn.parallel
class Conv2D(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size, padding=
'same', stride=1, dilation=1, groups=1):
super(Conv2D, self).__init__()
assert type(kernel_size) in [int, tuple
], 'Allowed kernel type [int or tuple], not {}'.format(type(
kernel_size))
assert padding == 'same', 'Allowed padding type {}, not {}'.format(
'same', padding)
self.kernel_size = kernel_size
if isinstance(kernel_size, tuple):
self.h_kernel = kernel_size[0]
self.w_kernel = kernel_size[1]
else:
self.h_kernel = kernel_size
self.w_kernel = kernel_size
self.padding = padding
self.stride = stride
self.dilation = dilation
self.groups = groups
self.conv = nn.Conv2d(in_channels=in_channels, out_channels=
out_channels, kernel_size=kernel_size, stride=self.stride,
dilation=self.dilation, groups=self.groups)
def forward(self, x):
if self.padding == 'same':
height, width = x.shape[2:]
h_pad_need = max(0, (height - 1) * self.stride + self.h_kernel -
height)
w_pad_need = max(0, (width - 1) * self.stride + self.w_kernel -
width)
pad_left = w_pad_need // 2
pad_right = w_pad_need - pad_left
pad_top = h_pad_need // 2
pad_bottom = h_pad_need - pad_top
padding = pad_left, pad_right, pad_top, pad_bottom
x = F.pad(x, padding, 'constant', 0)
x = self.conv(x)
return x
class GCN(nn.Module):
"""
Large Kernel Matters -- https://arxiv.org/abs/1703.02719
"""
def __init__(self, in_channels, out_channels, k=3):
super(GCN, self).__init__()
self.conv_l1 = Conv2D(in_channels=in_channels, out_channels=
out_channels, kernel_size=(k, 1), padding='same')
self.conv_l2 = Conv2D(in_channels=out_channels, out_channels=
out_channels, kernel_size=(1, k), padding='same')
self.conv_r1 = Conv2D(in_channels=in_channels, out_channels=
out_channels, kernel_size=(1, k), padding='same')
self.conv_r2 = Conv2D(in_channels=out_channels, out_channels=
out_channels, kernel_size=(k, 1), padding='same')
def forward(self, x):
x1 = self.conv_l1(x)
x1 = self.conv_l2(x1)
x2 = self.conv_r1(x)
x2 = self.conv_r2(x2)
out = x1 + x2
return out
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'out_channels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch import nn
import torch.nn.functional as F
import torch.nn.parallel
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 384
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 4 % 6
x2 = xindex // 24
x3 = xindex % 24
x4 = xindex
tmp0 = -1 + x1
tmp1 = tl.full([1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tmp2 & tmp4
tmp6 = tl.load(in_ptr0 + (-4 + x3 + 16 * x2), tmp5 & xmask, other=0.0)
tl.store(out_ptr0 + x4, tmp6, xmask)
@triton.jit
def triton_poi_fused_constant_pad_nd_convolution_1(in_ptr0, in_ptr1,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 384
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 6
x4 = xindex // 6
x2 = xindex // 24 % 4
x5 = xindex
tmp0 = -1 + x0
tmp1 = tl.full([1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tmp2 & tmp4
tmp6 = tl.load(in_ptr0 + (-1 + x0 + 4 * x4), tmp5 & xmask, other=0.0)
tmp7 = tl.load(in_ptr1 + x2, tmp5 & xmask, eviction_policy='evict_last',
other=0.0)
tmp8 = tmp6 + tmp7
tmp9 = tl.full(tmp8.shape, 0.0, tmp8.dtype)
tmp10 = tl.where(tmp5, tmp8, tmp9)
tl.store(out_ptr0 + x5, tmp10, xmask)
@triton.jit
def triton_poi_fused_constant_pad_nd_2(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 384
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 6
x1 = xindex // 6
x2 = xindex
tmp0 = -1 + x0
tmp1 = tl.full([1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tmp2 & tmp4
tmp6 = tl.load(in_ptr0 + (-1 + x0 + 4 * x1), tmp5 & xmask, other=0.0)
tl.store(out_ptr0 + x2, tmp6, xmask)
@triton.jit
def triton_poi_fused_constant_pad_nd_convolution_3(in_ptr0, in_ptr1,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 384
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 4 % 6
x4 = xindex // 24
x5 = xindex % 24
x2 = xindex // 24 % 4
x6 = xindex
tmp0 = -1 + x1
tmp1 = tl.full([1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tmp2 & tmp4
tmp6 = tl.load(in_ptr0 + (-4 + x5 + 16 * x4), tmp5 & xmask, other=0.0)
tmp7 = tl.load(in_ptr1 + x2, tmp5 & xmask, eviction_policy='evict_last',
other=0.0)
tmp8 = tmp6 + tmp7
tmp9 = tl.full(tmp8.shape, 0.0, tmp8.dtype)
tmp10 = tl.where(tmp5, tmp8, tmp9)
tl.store(out_ptr0 + x6, tmp10, xmask)
@triton.jit
def triton_poi_fused_add_convolution_4(in_out_ptr0, in_ptr0, in_ptr1,
in_ptr2, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x3, xmask)
tmp4 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp5 = tmp3 + tmp4
tmp6 = tmp2 + tmp5
tl.store(in_out_ptr0 + x3, tmp6, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4, 3, 1), (12, 3, 1, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4, 1, 3), (12, 3, 3, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (4, 4, 1, 3), (12, 3, 3, 1))
assert_size_stride(primals_7, (4,), (1,))
assert_size_stride(primals_8, (4, 4, 3, 1), (12, 3, 1, 1))
assert_size_stride(primals_9, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 6, 4), (96, 24, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_constant_pad_nd_0[grid(384)](primals_1, buf0, 384,
XBLOCK=128, num_warps=4, num_stages=1)
buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1))
buf2 = empty_strided_cuda((4, 4, 4, 6), (96, 24, 6, 1), torch.float32)
triton_poi_fused_constant_pad_nd_convolution_1[grid(384)](buf1,
primals_3, buf2, 384, XBLOCK=128, num_warps=4, num_stages=1)
del buf1
del primals_3
buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf3, (4, 4, 4, 4), (64, 16, 4, 1))
buf4 = empty_strided_cuda((4, 4, 4, 6), (96, 24, 6, 1), torch.float32)
triton_poi_fused_constant_pad_nd_2[grid(384)](primals_1, buf4, 384,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_1
buf5 = extern_kernels.convolution(buf4, primals_6, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf5, (4, 4, 4, 4), (64, 16, 4, 1))
buf6 = empty_strided_cuda((4, 4, 6, 4), (96, 24, 4, 1), torch.float32)
triton_poi_fused_constant_pad_nd_convolution_3[grid(384)](buf5,
primals_7, buf6, 384, XBLOCK=128, num_warps=4, num_stages=1)
del buf5
del primals_7
buf7 = extern_kernels.convolution(buf6, primals_8, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf7, (4, 4, 4, 4), (64, 16, 4, 1))
buf8 = buf3
del buf3
triton_poi_fused_add_convolution_4[grid(256)](buf8, primals_5, buf7,
primals_9, 256, XBLOCK=128, num_warps=4, num_stages=1)
del buf7
del primals_5
del primals_9
return (buf8, primals_2, primals_4, primals_6, primals_8, buf0, buf2,
buf4, buf6)
class Conv2D(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size, padding=
'same', stride=1, dilation=1, groups=1):
super(Conv2D, self).__init__()
assert type(kernel_size) in [int, tuple
], 'Allowed kernel type [int or tuple], not {}'.format(type(
kernel_size))
assert padding == 'same', 'Allowed padding type {}, not {}'.format(
'same', padding)
self.kernel_size = kernel_size
if isinstance(kernel_size, tuple):
self.h_kernel = kernel_size[0]
self.w_kernel = kernel_size[1]
else:
self.h_kernel = kernel_size
self.w_kernel = kernel_size
self.padding = padding
self.stride = stride
self.dilation = dilation
self.groups = groups
self.conv = nn.Conv2d(in_channels=in_channels, out_channels=
out_channels, kernel_size=kernel_size, stride=self.stride,
dilation=self.dilation, groups=self.groups)
def forward(self, x):
if self.padding == 'same':
height, width = x.shape[2:]
h_pad_need = max(0, (height - 1) * self.stride + self.h_kernel -
height)
w_pad_need = max(0, (width - 1) * self.stride + self.w_kernel -
width)
pad_left = w_pad_need // 2
pad_right = w_pad_need - pad_left
pad_top = h_pad_need // 2
pad_bottom = h_pad_need - pad_top
padding = pad_left, pad_right, pad_top, pad_bottom
x = F.pad(x, padding, 'constant', 0)
x = self.conv(x)
return x
class GCNNew(nn.Module):
"""
Large Kernel Matters -- https://arxiv.org/abs/1703.02719
"""
def __init__(self, in_channels, out_channels, k=3):
super(GCNNew, self).__init__()
self.conv_l1 = Conv2D(in_channels=in_channels, out_channels=
out_channels, kernel_size=(k, 1), padding='same')
self.conv_l2 = Conv2D(in_channels=out_channels, out_channels=
out_channels, kernel_size=(1, k), padding='same')
self.conv_r1 = Conv2D(in_channels=in_channels, out_channels=
out_channels, kernel_size=(1, k), padding='same')
self.conv_r2 = Conv2D(in_channels=out_channels, out_channels=
out_channels, kernel_size=(k, 1), padding='same')
def forward(self, input_0):
primals_2 = self.conv_l1.conv.weight
primals_3 = self.conv_l1.conv.bias
primals_4 = self.conv_l2.conv.weight
primals_5 = self.conv_l2.conv.bias
primals_6 = self.conv_r1.conv.weight
primals_7 = self.conv_r1.conv.bias
primals_8 = self.conv_r2.conv.weight
primals_9 = self.conv_r2.conv.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9])
return output[0]
|
Tanveer81/BoxVOS
|
GCN
| false
| 17,984
|
[
"BSD-2-Clause"
] | 4
|
c30aa319f18f3fbee2a25e0ed25cb006a4598300
|
https://github.com/Tanveer81/BoxVOS/tree/c30aa319f18f3fbee2a25e0ed25cb006a4598300
|
AnchorBoxTransform
|
import torch
from torch import Tensor
from typing import Optional
import torch.nn as nn
class AnchorBoxTransform(nn.Module):
def __init__(self, mean: 'Optional[Tensor]'=None, std:
'Optional[Tensor]'=None, log_length: 'bool'=False):
super(AnchorBoxTransform, self).__init__()
self.mean = mean
self.std = std
self.log_length = log_length
def forward(self, boxes: 'Tensor', deltas: 'Tensor') ->Tensor:
widths = boxes[:, :, 2] - boxes[:, :, 0]
heights = boxes[:, :, 3] - boxes[:, :, 1]
center_x = boxes[:, :, 0] + 0.5 * widths
center_y = boxes[:, :, 1] + 0.5 * heights
if self.std is not None:
deltas = deltas.mul(self.std)
if self.mean is not None:
deltas = deltas.add(self.mean)
dx, dy, dw, dh = [deltas[:, :, i] for i in range(4)]
if self.log_length:
dw, dh = [torch.exp(x) for x in (dw, dh)]
pred_center_x = center_x + dx * widths
pred_center_y = center_y + dy * heights
pred_w = dw * widths
pred_h = dh * heights
pred_boxes_x1 = pred_center_x - 0.5 * pred_w
pred_boxes_y1 = pred_center_y - 0.5 * pred_h
pred_boxes_x2 = pred_center_x + 0.5 * pred_w
pred_boxes_y2 = pred_center_y + 0.5 * pred_h
pred_boxes = torch.stack([pred_boxes_x1, pred_boxes_y1,
pred_boxes_x2, pred_boxes_y2], dim=-1)
return pred_boxes
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch import Tensor
from typing import Optional
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_stack_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4 % 4
x2 = xindex // 16
x3 = 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 + 16 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tl.load(in_ptr0 + (8 + x1 + 16 * x2), tmp4 & xmask,
eviction_policy='evict_last', other=0.0)
tmp7 = tmp6 - tmp5
tmp8 = 0.5
tmp9 = tmp7 * tmp8
tmp10 = tmp5 + tmp9
tmp11 = tl.load(in_ptr1 + (x1 + 16 * x2), tmp4 & xmask, eviction_policy
='evict_last', other=0.0)
tmp12 = tmp11 * tmp7
tmp13 = tmp10 + tmp12
tmp14 = tl.load(in_ptr1 + (8 + x1 + 16 * x2), tmp4 & xmask,
eviction_policy='evict_last', other=0.0)
tmp15 = tmp14 * tmp7
tmp16 = tmp15 * tmp8
tmp17 = tmp13 - tmp16
tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype)
tmp19 = tl.where(tmp4, tmp17, tmp18)
tmp20 = tmp0 >= tmp3
tmp21 = tl.full([1], 2, tl.int64)
tmp22 = tmp0 < tmp21
tmp23 = tmp20 & tmp22
tmp24 = tl.load(in_ptr0 + (4 + x1 + 16 * x2), tmp23 & xmask,
eviction_policy='evict_last', other=0.0)
tmp25 = tl.load(in_ptr0 + (12 + x1 + 16 * x2), tmp23 & xmask,
eviction_policy='evict_last', other=0.0)
tmp26 = tmp25 - tmp24
tmp27 = tmp26 * tmp8
tmp28 = tmp24 + tmp27
tmp29 = tl.load(in_ptr1 + (4 + x1 + 16 * x2), tmp23 & xmask,
eviction_policy='evict_last', other=0.0)
tmp30 = tmp29 * tmp26
tmp31 = tmp28 + tmp30
tmp32 = tl.load(in_ptr1 + (12 + x1 + 16 * x2), tmp23 & xmask,
eviction_policy='evict_last', other=0.0)
tmp33 = tmp32 * tmp26
tmp34 = tmp33 * tmp8
tmp35 = tmp31 - tmp34
tmp36 = tl.full(tmp35.shape, 0.0, tmp35.dtype)
tmp37 = tl.where(tmp23, tmp35, tmp36)
tmp38 = tmp0 >= tmp21
tmp39 = tl.full([1], 3, tl.int64)
tmp40 = tmp0 < tmp39
tmp41 = tmp38 & tmp40
tmp42 = tl.load(in_ptr0 + (x1 + 16 * x2), tmp41 & xmask,
eviction_policy='evict_last', other=0.0)
tmp43 = tl.load(in_ptr0 + (8 + x1 + 16 * x2), tmp41 & xmask,
eviction_policy='evict_last', other=0.0)
tmp44 = tmp43 - tmp42
tmp45 = tmp44 * tmp8
tmp46 = tmp42 + tmp45
tmp47 = tl.load(in_ptr1 + (x1 + 16 * x2), tmp41 & xmask,
eviction_policy='evict_last', other=0.0)
tmp48 = tmp47 * tmp44
tmp49 = tmp46 + tmp48
tmp50 = tl.load(in_ptr1 + (8 + x1 + 16 * x2), tmp41 & xmask,
eviction_policy='evict_last', other=0.0)
tmp51 = tmp50 * tmp44
tmp52 = tmp51 * tmp8
tmp53 = tmp49 + tmp52
tmp54 = tl.full(tmp53.shape, 0.0, tmp53.dtype)
tmp55 = tl.where(tmp41, tmp53, tmp54)
tmp56 = tmp0 >= tmp39
tl.full([1], 4, tl.int64)
tmp59 = tl.load(in_ptr0 + (4 + x1 + 16 * x2), tmp56 & xmask,
eviction_policy='evict_last', other=0.0)
tmp60 = tl.load(in_ptr0 + (12 + x1 + 16 * x2), tmp56 & xmask,
eviction_policy='evict_last', other=0.0)
tmp61 = tmp60 - tmp59
tmp62 = tmp61 * tmp8
tmp63 = tmp59 + tmp62
tmp64 = tl.load(in_ptr1 + (4 + x1 + 16 * x2), tmp56 & xmask,
eviction_policy='evict_last', other=0.0)
tmp65 = tmp64 * tmp61
tmp66 = tmp63 + tmp65
tmp67 = tl.load(in_ptr1 + (12 + x1 + 16 * x2), tmp56 & xmask,
eviction_policy='evict_last', other=0.0)
tmp68 = tmp67 * tmp61
tmp69 = tmp68 * tmp8
tmp70 = tmp66 + tmp69
tmp71 = tl.full(tmp70.shape, 0.0, tmp70.dtype)
tmp72 = tl.where(tmp56, tmp70, tmp71)
tmp73 = tl.where(tmp41, tmp55, tmp72)
tmp74 = tl.where(tmp23, tmp37, tmp73)
tmp75 = tl.where(tmp4, tmp19, tmp74)
tl.store(out_ptr0 + x3, tmp75, 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_stack_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 AnchorBoxTransformNew(nn.Module):
def __init__(self, mean: 'Optional[Tensor]'=None, std:
'Optional[Tensor]'=None, log_length: 'bool'=False):
super(AnchorBoxTransformNew, self).__init__()
self.mean = mean
self.std = std
self.log_length = log_length
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
TidalPaladin/combustion
|
AnchorBoxTransform
| false
| 17,985
|
[
"Apache-2.0"
] | 3
|
69b9a2b9baf90b81ed9098b4f0391f5c15efaee7
|
https://github.com/TidalPaladin/combustion/tree/69b9a2b9baf90b81ed9098b4f0391f5c15efaee7
|
TransposedConvModel
|
import torch
import torch.nn
import torch.utils.data
import torch.utils.tensorboard._pytorch_graph
import torch.onnx.symbolic_caffe2
class TransposedConvModel(torch.nn.Module):
def __init__(self):
super(TransposedConvModel, self).__init__()
self.conv1 = torch.nn.ConvTranspose2d(10, 10, 3)
self.relu1 = torch.nn.ReLU()
self.conv2 = torch.nn.ConvTranspose2d(10, 10, 3)
def forward(self, x):
x = self.conv1(x)
x = self.relu1(x)
x = self.conv2(x)
return x
def get_inputs():
return [torch.rand([4, 10, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn
import torch.utils.data
import torch.utils.tensorboard._pytorch_graph
import torch.onnx.symbolic_caffe2
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 = 1440
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 36 % 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_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 2560
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 64 % 10
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, (10, 10, 3, 3), (90, 9, 3, 1))
assert_size_stride(primals_2, (10,), (1,))
assert_size_stride(primals_3, (4, 10, 4, 4), (160, 16, 4, 1))
assert_size_stride(primals_4, (10, 10, 3, 3), (90, 9, 3, 1))
assert_size_stride(primals_5, (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=True,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 10, 6, 6), (360, 36, 6, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_relu_0[grid(1440)](buf1, primals_2,
1440, XBLOCK=128, num_warps=4, num_stages=1)
del primals_2
buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=True,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 10, 8, 8), (640, 64, 8, 1))
buf3 = buf2
del buf2
triton_poi_fused_convolution_1[grid(2560)](buf3, primals_5, 2560,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_5
return buf3, primals_1, primals_3, primals_4, buf1
class TransposedConvModelNew(torch.nn.Module):
def __init__(self):
super(TransposedConvModelNew, self).__init__()
self.conv1 = torch.nn.ConvTranspose2d(10, 10, 3)
self.relu1 = torch.nn.ReLU()
self.conv2 = torch.nn.ConvTranspose2d(10, 10, 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]
|
Rohan-Chaudhury/aimet
|
TransposedConvModel
| false
| 17,986
|
[
"BSD-3-Clause"
] | 3
|
1c38cac8cc0fd32dca40ce5e39940805d29f7a4a
|
https://github.com/Rohan-Chaudhury/aimet/tree/1c38cac8cc0fd32dca40ce5e39940805d29f7a4a
|
Downsampling
|
import torch
import torch.nn as M
def DepthwiseConv(in_channels, kernel_size, stride, padding):
return M.Conv2d(in_channels=in_channels, out_channels=in_channels,
kernel_size=kernel_size, stride=stride, padding=padding, groups=
in_channels, bias=False)
def PointwiseConv(in_channels, out_channels):
return M.Conv2d(in_channels=in_channels, out_channels=out_channels,
kernel_size=1, padding=0, bias=True)
class CovSepBlock(M.Module):
def __init__(self, in_channels, out_channels, kernel_size=5, stride=1,
padding=2):
super().__init__()
self.dc = DepthwiseConv(in_channels, kernel_size, stride=stride,
padding=padding)
self.pc = PointwiseConv(in_channels, out_channels)
def forward(self, x):
x = self.dc(x)
x = self.pc(x)
return x
class Downsampling(M.Module):
def __init__(self, in_channels, out_channels):
super().__init__()
self.sepconv = CovSepBlock(in_channels=in_channels, out_channels=
out_channels // 4, stride=2, padding=2)
self.activate = M.ReLU(inplace=True)
self.sepconv2 = CovSepBlock(in_channels=out_channels // 4,
out_channels=out_channels, padding=2)
self.branchconv = CovSepBlock(in_channels, out_channels,
kernel_size=3, stride=2, padding=1)
self.activate2 = M.ReLU(inplace=True)
def forward(self, x):
branch = x
x = self.sepconv(x)
x = self.activate(x)
x = self.sepconv2(x)
branch = self.branchconv(branch)
x += branch
return self.activate2(x)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'out_channels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as M
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 = 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.load(in_ptr0 + 0)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
tmp3 = tmp0 + tmp2
tmp4 = tl.full([1], 0, tl.int32)
tmp5 = triton_helpers.maximum(tmp4, tmp3)
tl.store(in_out_ptr0 + x0, tmp5, xmask)
@triton.jit
def triton_poi_fused_add_convolution_relu_threshold_backward_1(in_out_ptr0,
in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 4 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x3, xmask)
tmp4 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp5 = tmp3 + tmp4
tmp6 = tmp2 + tmp5
tmp7 = tl.full([1], 0, tl.int32)
tmp8 = triton_helpers.maximum(tmp7, tmp6)
tmp9 = 0.0
tmp10 = tmp8 <= tmp9
tl.store(in_out_ptr0 + x3, tmp8, xmask)
tl.store(out_ptr0 + x3, tmp10, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 1, 5, 5), (25, 25, 5, 1))
assert_size_stride(primals_3, (1, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_4, (1,), (1,))
assert_size_stride(primals_5, (1, 1, 5, 5), (25, 25, 5, 1))
assert_size_stride(primals_6, (4, 1, 1, 1), (1, 1, 1, 1))
assert_size_stride(primals_7, (4,), (1,))
assert_size_stride(primals_8, (4, 1, 3, 3), (9, 9, 3, 1))
assert_size_stride(primals_9, (4, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_10, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(2,
2), padding=(2, 2), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=4, bias=None)
assert_size_stride(buf0, (4, 4, 2, 2), (16, 4, 2, 1))
buf1 = extern_kernels.convolution(buf0, primals_3, 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))
buf2 = buf1
del buf1
get_raw_stream(0)
triton_poi_fused_convolution_relu_0[grid(16)](buf2, primals_4, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del primals_4
buf3 = extern_kernels.convolution(buf2, primals_5, stride=(1, 1),
padding=(2, 2), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf3, (4, 1, 2, 2), (4, 4, 2, 1))
buf4 = extern_kernels.convolution(buf3, primals_6, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 4, 2, 2), (16, 4, 2, 1))
buf5 = extern_kernels.convolution(primals_1, primals_8, stride=(2,
2), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=4, bias=None)
assert_size_stride(buf5, (4, 4, 2, 2), (16, 4, 2, 1))
buf6 = extern_kernels.convolution(buf5, primals_9, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf6, (4, 4, 2, 2), (16, 4, 2, 1))
buf7 = buf4
del buf4
buf8 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.bool)
triton_poi_fused_add_convolution_relu_threshold_backward_1[grid(64)](
buf7, primals_7, buf6, primals_10, buf8, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del buf6
del primals_10
del primals_7
return (buf7, primals_1, primals_2, primals_3, primals_5, primals_6,
primals_8, primals_9, buf0, buf2, buf3, buf5, buf8)
def DepthwiseConv(in_channels, kernel_size, stride, padding):
return M.Conv2d(in_channels=in_channels, out_channels=in_channels,
kernel_size=kernel_size, stride=stride, padding=padding, groups=
in_channels, bias=False)
def PointwiseConv(in_channels, out_channels):
return M.Conv2d(in_channels=in_channels, out_channels=out_channels,
kernel_size=1, padding=0, bias=True)
class CovSepBlock(M.Module):
def __init__(self, in_channels, out_channels, kernel_size=5, stride=1,
padding=2):
super().__init__()
self.dc = DepthwiseConv(in_channels, kernel_size, stride=stride,
padding=padding)
self.pc = PointwiseConv(in_channels, out_channels)
def forward(self, x):
x = self.dc(x)
x = self.pc(x)
return x
class DownsamplingNew(M.Module):
def __init__(self, in_channels, out_channels):
super().__init__()
self.sepconv = CovSepBlock(in_channels=in_channels, out_channels=
out_channels // 4, stride=2, padding=2)
self.activate = M.ReLU(inplace=True)
self.sepconv2 = CovSepBlock(in_channels=out_channels // 4,
out_channels=out_channels, padding=2)
self.branchconv = CovSepBlock(in_channels, out_channels,
kernel_size=3, stride=2, padding=1)
self.activate2 = M.ReLU(inplace=True)
def forward(self, input_0):
primals_2 = self.sepconv.dc.weight
primals_3 = self.sepconv.pc.weight
primals_4 = self.sepconv.pc.bias
primals_5 = self.sepconv2.dc.weight
primals_6 = self.sepconv2.pc.weight
primals_7 = self.sepconv2.pc.bias
primals_8 = self.branchconv.dc.weight
primals_9 = self.branchconv.pc.weight
primals_10 = self.branchconv.pc.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9, primals_10])
return output[0]
|
SuperbTUM/RAW-image-denoising
|
Downsampling
| false
| 17,987
|
[
"MIT"
] | 4
|
9f81be8da6a576f641022707d98b8c37f5c599ab
|
https://github.com/SuperbTUM/RAW-image-denoising/tree/9f81be8da6a576f641022707d98b8c37f5c599ab
|
SoftCrossEntropyLoss
|
import torch
import torch.nn as nn
class SoftCrossEntropyLoss(nn.Module):
"""Cross entropy loss with soft label as target
"""
def __init__(self, num_classes, epsilon=0.1, use_gpu=True, label_smooth
=False, batch_average=True):
super(SoftCrossEntropyLoss, self).__init__()
self.num_classes = num_classes
self.epsilon = epsilon
self.use_gpu = use_gpu
self.logsoftmax = nn.LogSoftmax(dim=1)
self.label_smooth = label_smooth
self.batch_average = batch_average
def forward(self, inputs, targets):
"""
Args:
inputs: prediction matrix (before softmax) with shape (batch_size, num_classes)
targets: ground truth labels with shape (batch_size, num_classes)
"""
log_probs = self.logsoftmax(inputs)
if self.use_gpu:
targets = targets
if self.label_smooth:
targets = (1 - self.epsilon
) * targets + self.epsilon / self.num_classes
loss = (-targets * log_probs).sum(1)
if self.batch_average:
loss = loss.mean()
return loss
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'num_classes': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused__log_softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tl.store(out_ptr0 + x3, tmp8, xmask)
@triton.jit
def triton_per_fused__log_softmax_mean_mul_neg_sum_1(in_out_ptr0, in_ptr0,
in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr):
RBLOCK: tl.constexpr = 64
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r0 = rindex % 16
r1 = rindex // 16
tmp0 = tl.load(in_ptr0 + (r0 + 64 * r1), None)
tmp2 = tl.load(in_ptr1 + (r0 + 64 * r1), None)
tmp4 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None)
tmp7 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None)
tmp10 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None)
tmp16 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None)
tmp21 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None)
tmp26 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None)
tmp1 = -tmp0
tmp3 = tl_math.exp(tmp2)
tmp5 = tl_math.exp(tmp4)
tmp6 = tmp3 + tmp5
tmp8 = tl_math.exp(tmp7)
tmp9 = tmp6 + tmp8
tmp11 = tl_math.exp(tmp10)
tmp12 = tmp9 + tmp11
tmp13 = tl_math.log(tmp12)
tmp14 = tmp2 - tmp13
tmp15 = tmp1 * tmp14
tmp17 = -tmp16
tmp18 = tmp4 - tmp13
tmp19 = tmp17 * tmp18
tmp20 = tmp15 + tmp19
tmp22 = -tmp21
tmp23 = tmp7 - tmp13
tmp24 = tmp22 * tmp23
tmp25 = tmp20 + tmp24
tmp27 = -tmp26
tmp28 = tmp10 - tmp13
tmp29 = tmp27 * tmp28
tmp30 = tmp25 + tmp29
tmp31 = tl.broadcast_to(tmp30, [XBLOCK, RBLOCK])
tmp33 = tl.sum(tmp31, 1)[:, None]
tmp34 = 64.0
tmp35 = tmp33 / tmp34
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp35, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__log_softmax_0[grid(256)](arg0_1, buf0, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del arg0_1
buf2 = empty_strided_cuda((), (), torch.float32)
buf3 = buf2
del buf2
triton_per_fused__log_softmax_mean_mul_neg_sum_1[grid(1)](buf3,
arg1_1, buf0, 1, 64, XBLOCK=1, num_warps=2, num_stages=1)
del arg1_1
del buf0
return buf3,
class SoftCrossEntropyLossNew(nn.Module):
"""Cross entropy loss with soft label as target
"""
def __init__(self, num_classes, epsilon=0.1, use_gpu=True, label_smooth
=False, batch_average=True):
super(SoftCrossEntropyLossNew, self).__init__()
self.num_classes = num_classes
self.epsilon = epsilon
self.use_gpu = use_gpu
self.logsoftmax = nn.LogSoftmax(dim=1)
self.label_smooth = label_smooth
self.batch_average = batch_average
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
Terminator8758/Precise-ICS-master
|
SoftCrossEntropyLoss
| false
| 17,988
|
[
"MIT"
] | 4
|
9f4591fee6ab64d9dd91f551355d29562bf663cb
|
https://github.com/Terminator8758/Precise-ICS-master/tree/9f4591fee6ab64d9dd91f551355d29562bf663cb
|
Normalize
|
import torch
from torch import nn
class Normalize(nn.Module):
""" Ln normalization copied from
https://github.com/salesforce/CoMatch
"""
def __init__(self, power=2):
super(Normalize, self).__init__()
self.power = power
def forward(self, x):
norm = x.pow(self.power).sum(1, keepdim=True).pow(1.0 / self.power)
out = x.div(norm)
return out
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_div_pow_sum_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = tmp0 / tmp12
tl.store(out_ptr0 + x3, tmp13, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_div_pow_sum_0[grid(256)](arg0_1, buf0, 256, XBLOCK
=128, num_warps=4, num_stages=1)
del arg0_1
return buf0,
class NormalizeNew(nn.Module):
""" Ln normalization copied from
https://github.com/salesforce/CoMatch
"""
def __init__(self, power=2):
super(NormalizeNew, self).__init__()
self.power = power
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
TencentYoutuResearch/Classification-SemiCLS
|
Normalize
| false
| 17,989
|
[
"Apache-2.0"
] | 4
|
ceb5546f8d8ba08e18de3b5d9426e6cda177e55e
|
https://github.com/TencentYoutuResearch/Classification-SemiCLS/tree/ceb5546f8d8ba08e18de3b5d9426e6cda177e55e
|
SoftmaxAttention
|
import torch
import torch.nn as nn
def masked_softmax(tensor, mask):
"""
Apply a masked softmax on the last dimension of a tensor.
The input tensor and mask should be of size (batch, *, sequence_length).
Args:
tensor: The tensor on which the softmax function must be applied along
the last dimension.
mask: A mask of the same size as the tensor with 0s in the positions of
the values that must be masked and 1s everywhere else.
Returns:
A tensor of the same size as the inputs containing the result of the
softmax.
"""
tensor_shape = tensor.size()
reshaped_tensor = tensor.view(-1, tensor_shape[-1])
while mask.dim() < tensor.dim():
mask = mask.unsqueeze(1)
mask = mask.expand_as(tensor).contiguous().float()
reshaped_mask = mask.view(-1, mask.size()[-1])
result = nn.functional.softmax(reshaped_tensor * reshaped_mask, dim=-1)
result = result * reshaped_mask
result = result / (result.sum(dim=-1, keepdim=True) + 1e-13)
return result.view(*tensor_shape)
def weighted_sum(tensor, weights, mask):
"""
Apply a weighted sum on the vectors along the last dimension of 'tensor',
and mask the vectors in the result with 'mask'.
Args:
tensor: A tensor of vectors on which a weighted sum must be applied.
weights: The weights to use in the weighted sum.
mask: A mask to apply on the result of the weighted sum.
Returns:
A new tensor containing the result of the weighted sum after the mask
has been applied on it.
"""
weighted_sum = weights.bmm(tensor)
while mask.dim() < weighted_sum.dim():
mask = mask.unsqueeze(1)
mask = mask.transpose(-1, -2)
mask = mask.expand_as(weighted_sum).contiguous().float()
return weighted_sum * mask
class SoftmaxAttention(nn.Module):
"""
Attention layer taking premises and hypotheses encoded by an RNN as input
and computing the soft attention between their elements.
The dot product of the encoded vectors in the premises and hypotheses is
first computed. The softmax of the result is then used in a weighted sum
of the vectors of the premises for each element of the hypotheses, and
conversely for the elements of the premises.
"""
def forward(self, premise_batch, premise_mask, hypothesis_batch,
hypothesis_mask):
"""
Args:
premise_batch: A batch of sequences of vectors representing the
premises in some NLI task. The batch is assumed to have the
size (batch, sequences, vector_dim).
premise_mask: A mask for the sequences in the premise batch, to
ignore padding data in the sequences during the computation of
the attention.
hypothesis_batch: A batch of sequences of vectors representing the
hypotheses in some NLI task. The batch is assumed to have the
size (batch, sequences, vector_dim).
hypothesis_mask: A mask for the sequences in the hypotheses batch,
to ignore padding data in the sequences during the computation
of the attention.
Returns:
attended_premises: The sequences of attention vectors for the
premises in the input batch.
attended_hypotheses: The sequences of attention vectors for the
hypotheses in the input batch.
"""
similarity_matrix = premise_batch.bmm(hypothesis_batch.transpose(2,
1).contiguous())
prem_hyp_attn = masked_softmax(similarity_matrix, hypothesis_mask)
hyp_prem_attn = masked_softmax(similarity_matrix.transpose(1, 2).
contiguous(), premise_mask)
attended_premises = weighted_sum(hypothesis_batch, prem_hyp_attn,
premise_mask)
attended_hypotheses = weighted_sum(premise_batch, hyp_prem_attn,
hypothesis_mask)
return attended_premises, attended_hypotheses
def get_inputs():
return [torch.rand([4, 4, 4]), torch.rand([4, 4]), torch.rand([4, 4, 4]
), torch.rand([4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
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
tmp0 = tl.load(in_ptr0 + x0, xmask)
tl.store(out_ptr0 + x0, tmp0, xmask)
@triton.jit
def triton_poi_fused__softmax_mul_sum_1(in_ptr0, in_ptr1, 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 + 4 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + 4 * (x0 // 4), 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 // 4)), 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 // 4)), 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 // 4)), xmask, eviction_policy=
'evict_last')
tmp2 = tmp0 * tmp1
tmp5 = tmp3 * tmp4
tmp6 = triton_helpers.maximum(tmp2, tmp5)
tmp9 = tmp7 * tmp8
tmp10 = triton_helpers.maximum(tmp6, tmp9)
tmp13 = tmp11 * tmp12
tmp14 = triton_helpers.maximum(tmp10, tmp13)
tmp15 = tmp2 - tmp14
tmp16 = tl_math.exp(tmp15)
tmp17 = tmp5 - tmp14
tmp18 = tl_math.exp(tmp17)
tmp19 = tmp16 + tmp18
tmp20 = tmp9 - tmp14
tmp21 = tl_math.exp(tmp20)
tmp22 = tmp19 + tmp21
tmp23 = tmp13 - tmp14
tmp24 = tl_math.exp(tmp23)
tmp25 = tmp22 + tmp24
tmp26 = tmp16 / tmp25
tmp27 = tmp26 * tmp1
tmp28 = tmp18 / tmp25
tmp29 = tmp28 * tmp4
tmp30 = tmp27 + tmp29
tmp31 = tmp21 / tmp25
tmp32 = tmp31 * tmp8
tmp33 = tmp30 + tmp32
tmp34 = tmp24 / tmp25
tmp35 = tmp34 * tmp12
tmp36 = tmp33 + tmp35
tl.store(out_ptr0 + x0, tmp14, xmask)
tl.store(out_ptr1 + x0, tmp25, xmask)
tl.store(out_ptr2 + x0, tmp36, xmask)
@triton.jit
def triton_poi_fused__softmax_add_div_mul_2(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + (x0 + 4 * (x1 // 4)), xmask)
tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 * tmp1
tmp4 = tmp2 - tmp3
tmp5 = tl_math.exp(tmp4)
tmp7 = tmp5 / tmp6
tmp8 = tmp7 * tmp1
tmp10 = 1e-13
tmp11 = tmp9 + tmp10
tmp12 = tmp8 / tmp11
tl.store(out_ptr0 + x2, tmp12, xmask)
@triton.jit
def triton_poi_fused_clone_mul_3(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
x1 = xindex // 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 * tmp1
tl.store(in_out_ptr0 + x2, tmp2, xmask)
@triton.jit
def triton_poi_fused__softmax_mul_sum_4(in_ptr0, in_ptr1, 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 + (16 * (x0 // 4) + x0 % 4), xmask)
tmp1 = tl.load(in_ptr1 + 4 * (x0 // 4), xmask, eviction_policy='evict_last'
)
tmp3 = tl.load(in_ptr0 + (4 + 16 * (x0 // 4) + x0 % 4), xmask)
tmp4 = tl.load(in_ptr1 + (1 + 4 * (x0 // 4)), xmask, eviction_policy=
'evict_last')
tmp7 = tl.load(in_ptr0 + (8 + 16 * (x0 // 4) + x0 % 4), xmask)
tmp8 = tl.load(in_ptr1 + (2 + 4 * (x0 // 4)), xmask, eviction_policy=
'evict_last')
tmp11 = tl.load(in_ptr0 + (12 + 16 * (x0 // 4) + x0 % 4), xmask)
tmp12 = tl.load(in_ptr1 + (3 + 4 * (x0 // 4)), xmask, eviction_policy=
'evict_last')
tmp2 = tmp0 * tmp1
tmp5 = tmp3 * tmp4
tmp6 = triton_helpers.maximum(tmp2, tmp5)
tmp9 = tmp7 * tmp8
tmp10 = triton_helpers.maximum(tmp6, tmp9)
tmp13 = tmp11 * tmp12
tmp14 = triton_helpers.maximum(tmp10, tmp13)
tmp15 = tmp2 - tmp14
tmp16 = tl_math.exp(tmp15)
tmp17 = tmp5 - tmp14
tmp18 = tl_math.exp(tmp17)
tmp19 = tmp16 + tmp18
tmp20 = tmp9 - tmp14
tmp21 = tl_math.exp(tmp20)
tmp22 = tmp19 + tmp21
tmp23 = tmp13 - tmp14
tmp24 = tl_math.exp(tmp23)
tmp25 = tmp22 + tmp24
tmp26 = tmp16 / tmp25
tmp27 = tmp26 * tmp1
tmp28 = tmp18 / tmp25
tmp29 = tmp28 * tmp4
tmp30 = tmp27 + tmp29
tmp31 = tmp21 / tmp25
tmp32 = tmp31 * tmp8
tmp33 = tmp30 + tmp32
tmp34 = tmp24 / tmp25
tmp35 = tmp34 * tmp12
tmp36 = tmp33 + tmp35
tl.store(out_ptr0 + x0, tmp14, xmask)
tl.store(out_ptr1 + x0, tmp25, xmask)
tl.store(out_ptr2 + x0, tmp36, xmask)
@triton.jit
def triton_poi_fused__softmax_add_div_mul_5(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, in_ptr4, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr,
XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x1 = xindex
y0 = yindex
tmp0 = tl.load(in_ptr0 + (4 * x1 + 16 * (y0 // 4) + y0 % 4), xmask &
ymask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + (x1 + 4 * (y0 // 4)), xmask & ymask,
eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + y0, ymask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr3 + y0, ymask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr4 + y0, ymask, eviction_policy='evict_last')
tmp2 = tmp0 * tmp1
tmp4 = tmp2 - tmp3
tmp5 = tl_math.exp(tmp4)
tmp7 = tmp5 / tmp6
tmp8 = tmp7 * tmp1
tmp10 = 1e-13
tmp11 = tmp9 + tmp10
tmp12 = tmp8 / tmp11
tl.store(out_ptr0 + (x1 + 4 * y0), tmp12, xmask & ymask)
def call(args):
arg0_1, arg1_1, arg2_1, arg3_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(arg2_1, (4, 4), (4, 1))
assert_size_stride(arg3_1, (4, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4), (16, 1, 4), torch.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(64)](arg1_1, buf0, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(arg0_1, buf0, out=buf1)
buf2 = empty_strided_cuda((16, 1), (1, 16), torch.float32)
buf3 = empty_strided_cuda((16, 1), (1, 16), torch.float32)
buf4 = empty_strided_cuda((16, 1), (1, 16), torch.float32)
triton_poi_fused__softmax_mul_sum_1[grid(16)](buf1, arg2_1, buf2,
buf3, buf4, 16, XBLOCK=16, num_warps=1, num_stages=1)
buf5 = reinterpret_tensor(buf0, (16, 4), (4, 1), 0)
del buf0
triton_poi_fused__softmax_add_div_mul_2[grid(64)](buf1, arg2_1,
buf2, buf3, buf4, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf6 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf5, (4, 4, 4), (16, 4, 1),
0), arg1_1, out=buf6)
del arg1_1
buf7 = buf6
del buf6
triton_poi_fused_clone_mul_3[grid(64)](buf7, arg3_1, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf8 = buf4
del buf4
buf9 = buf3
del buf3
buf10 = buf2
del buf2
triton_poi_fused__softmax_mul_sum_4[grid(16)](buf1, arg3_1, buf8,
buf9, buf10, 16, XBLOCK=16, num_warps=1, num_stages=1)
buf11 = buf5
del buf5
triton_poi_fused__softmax_add_div_mul_5[grid(16, 4)](buf1, arg3_1,
buf8, buf9, buf10, buf11, 16, 4, XBLOCK=2, YBLOCK=16, num_warps
=1, num_stages=1)
del arg3_1
del buf10
del buf8
del buf9
buf12 = buf1
del buf1
extern_kernels.bmm(reinterpret_tensor(buf11, (4, 4, 4), (16, 4, 1),
0), arg0_1, out=buf12)
del arg0_1
del buf11
buf13 = buf12
del buf12
triton_poi_fused_clone_mul_3[grid(64)](buf13, arg2_1, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del arg2_1
return buf7, buf13
def masked_softmax(tensor, mask):
"""
Apply a masked softmax on the last dimension of a tensor.
The input tensor and mask should be of size (batch, *, sequence_length).
Args:
tensor: The tensor on which the softmax function must be applied along
the last dimension.
mask: A mask of the same size as the tensor with 0s in the positions of
the values that must be masked and 1s everywhere else.
Returns:
A tensor of the same size as the inputs containing the result of the
softmax.
"""
tensor_shape = tensor.size()
reshaped_tensor = tensor.view(-1, tensor_shape[-1])
while mask.dim() < tensor.dim():
mask = mask.unsqueeze(1)
mask = mask.expand_as(tensor).contiguous().float()
reshaped_mask = mask.view(-1, mask.size()[-1])
result = nn.functional.softmax(reshaped_tensor * reshaped_mask, dim=-1)
result = result * reshaped_mask
result = result / (result.sum(dim=-1, keepdim=True) + 1e-13)
return result.view(*tensor_shape)
def weighted_sum(tensor, weights, mask):
"""
Apply a weighted sum on the vectors along the last dimension of 'tensor',
and mask the vectors in the result with 'mask'.
Args:
tensor: A tensor of vectors on which a weighted sum must be applied.
weights: The weights to use in the weighted sum.
mask: A mask to apply on the result of the weighted sum.
Returns:
A new tensor containing the result of the weighted sum after the mask
has been applied on it.
"""
weighted_sum = weights.bmm(tensor)
while mask.dim() < weighted_sum.dim():
mask = mask.unsqueeze(1)
mask = mask.transpose(-1, -2)
mask = mask.expand_as(weighted_sum).contiguous().float()
return weighted_sum * mask
class SoftmaxAttentionNew(nn.Module):
"""
Attention layer taking premises and hypotheses encoded by an RNN as input
and computing the soft attention between their elements.
The dot product of the encoded vectors in the premises and hypotheses is
first computed. The softmax of the result is then used in a weighted sum
of the vectors of the premises for each element of the hypotheses, and
conversely for the elements of the premises.
"""
def forward(self, input_0, input_1, input_2, input_3):
arg0_1 = input_0
arg2_1 = input_1
arg1_1 = input_2
arg3_1 = input_3
output = call([arg0_1, arg1_1, arg2_1, arg3_1])
return output[0], output[1]
|
Taoooo9/Cail_Text_similarity_esimtribert
|
SoftmaxAttention
| false
| 17,990
|
[
"Apache-2.0"
] | 5
|
10b0314fdc3fcc60e39737ac563e8538b96ceb19
|
https://github.com/Taoooo9/Cail_Text_similarity_esimtribert/tree/10b0314fdc3fcc60e39737ac563e8538b96ceb19
|
Edg_Capture
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class Edg_Capture(nn.Module):
def __init__(self):
super(Edg_Capture, self).__init__()
kernel = [[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]]
kernel = torch.FloatTensor(kernel).unsqueeze(0).unsqueeze(0)
self.weight = nn.Parameter(data=kernel, requires_grad=False)
def forward(self, x):
x1 = x[:, 0]
x2 = x[:, 1]
x3 = x[:, 2]
x1 = F.conv2d(x1.unsqueeze(1), self.weight, padding=1)
x2 = F.conv2d(x2.unsqueeze(1), self.weight, padding=1)
x3 = F.conv2d(x3.unsqueeze(1), self.weight, padding=1)
x = torch.cat([x1, x2, x3], 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
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_cat_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 192
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16 % 3
x0 = xindex % 16
x2 = xindex // 48
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 1, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 16 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tmp0 >= tmp3
tmp7 = tl.full([1], 2, tl.int64)
tmp8 = tmp0 < tmp7
tmp9 = tmp6 & tmp8
tmp10 = tl.load(in_ptr1 + (x0 + 16 * x2), tmp9 & xmask, eviction_policy
='evict_last', other=0.0)
tmp11 = tmp0 >= tmp7
tl.full([1], 3, tl.int64)
tmp14 = tl.load(in_ptr2 + (x0 + 16 * x2), tmp11 & xmask,
eviction_policy='evict_last', other=0.0)
tmp15 = tl.where(tmp9, tmp10, tmp14)
tmp16 = tl.where(tmp4, tmp5, tmp15)
tl.store(out_ptr0 + x3, tmp16, 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, (1, 1, 3, 3), (9, 9, 3, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(reinterpret_tensor(arg0_1, (4, 1,
4, 4), (64, 0, 4, 1), 0), arg1_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, 1, 4, 4), (16, 16, 4, 1))
buf1 = extern_kernels.convolution(reinterpret_tensor(arg0_1, (4, 1,
4, 4), (64, 0, 4, 1), 16), arg1_1, stride=(1, 1), padding=(1, 1
), 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 = extern_kernels.convolution(reinterpret_tensor(arg0_1, (4, 1,
4, 4), (64, 0, 4, 1), 32), arg1_1, stride=(1, 1), padding=(1, 1
), dilation=(1, 1), transposed=False, output_padding=(0, 0),
groups=1, bias=None)
assert_size_stride(buf2, (4, 1, 4, 4), (16, 16, 4, 1))
del arg0_1
del arg1_1
buf3 = empty_strided_cuda((4, 3, 4, 4), (48, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(192)](buf0, buf1, buf2, buf3, 192,
XBLOCK=256, num_warps=4, num_stages=1)
del buf0
del buf1
del buf2
return buf3,
class Edg_CaptureNew(nn.Module):
def __init__(self):
super(Edg_CaptureNew, self).__init__()
kernel = [[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]]
kernel = torch.FloatTensor(kernel).unsqueeze(0).unsqueeze(0)
self.weight = nn.Parameter(data=kernel, requires_grad=False)
def forward(self, input_0):
arg1_1 = self.weight
arg0_1 = input_0
output = call([arg0_1, arg1_1])
return output[0]
|
TaoWangzj/PCFAN
|
Edg_Capture
| false
| 17,991
|
[
"MIT"
] | 7
|
f6ddc8fd2e72a45431891acf0b25135499c84485
|
https://github.com/TaoWangzj/PCFAN/tree/f6ddc8fd2e72a45431891acf0b25135499c84485
|
Encoder
|
import torch
import torch.nn
import torch.nn as nn
import torch.nn.functional as F
class Encoder(nn.Module):
"""Estimation of the nonnegative mixture weight by a 1-D conv layer.
"""
def __init__(self, L, N):
super(Encoder, self).__init__()
self.L, self.N = L, N
self.conv1d_U = nn.Conv1d(1, N, kernel_size=L, stride=L // 2, bias=
False)
def forward(self, mixture):
"""
Args:
mixture: [M, T], M is batch size, T is #samples
Returns:
mixture_w: [M, N, K], where K = (T-L)/(L/2)+1 = 2T/L-1
"""
mixture = torch.unsqueeze(mixture, 1)
mixture_w = F.relu(self.conv1d_U(mixture))
return mixture_w
def get_inputs():
return [torch.rand([4, 4])]
def get_init_inputs():
return [[], {'L': 4, 'N': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn
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, 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)
tmp3 = 0.0
tmp4 = tmp2 <= tmp3
tl.store(in_out_ptr0 + x0, tmp2, xmask)
tl.store(out_ptr0 + x0, tmp4, xmask)
def call(args):
primals_1, primals_2 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4, 1, 4), (4, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(reinterpret_tensor(primals_1, (4,
1, 4), (4, 4, 1), 0), primals_2, stride=(2,), padding=(0,),
dilation=(1,), transposed=False, output_padding=(0,), groups=1,
bias=None)
assert_size_stride(buf0, (4, 4, 1), (4, 1, 1))
buf1 = buf0
del buf0
buf2 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.bool)
get_raw_stream(0)
triton_poi_fused_relu_threshold_backward_0[grid(16)](buf1, buf2, 16,
XBLOCK=16, num_warps=1, num_stages=1)
return buf1, primals_2, reinterpret_tensor(primals_1, (4, 1, 4), (4, 4,
1), 0), buf2
class EncoderNew(nn.Module):
"""Estimation of the nonnegative mixture weight by a 1-D conv layer.
"""
def __init__(self, L, N):
super(EncoderNew, self).__init__()
self.L, self.N = L, N
self.conv1d_U = nn.Conv1d(1, N, kernel_size=L, stride=L // 2, bias=
False)
def forward(self, input_0):
primals_2 = self.conv1d_U.weight
primals_1 = input_0
output = call([primals_1, primals_2])
return output[0]
|
ThomasRigoni7/Audio-emotion-recognition-RAVDESS
|
Encoder
| false
| 17,992
|
[
"MIT"
] | 5
|
ae44256edfcb320a32696444cd301264e1800866
|
https://github.com/ThomasRigoni7/Audio-emotion-recognition-RAVDESS/tree/ae44256edfcb320a32696444cd301264e1800866
|
GAT
|
import torch
import torch.nn.functional as F
import torch.autograd
import torch.nn as nn
class GraphAttConv(nn.Module):
def __init__(self, in_features, out_features, dropout, alpha, concat=True):
super(GraphAttConv, self).__init__()
self.dropout = dropout
self.in_features = in_features
self.out_features = out_features
self.alpha = alpha
self.concat = concat
self.W = nn.Parameter(torch.empty(size=(in_features, out_features)))
nn.init.xavier_uniform_(self.W.data, gain=1.414)
self.attention_w = nn.Parameter(torch.empty(size=(2 * out_features, 1))
)
nn.init.xavier_uniform_(self.attention_w.data, gain=1.414)
self.leakyrelu = nn.LeakyReLU(self.alpha)
def forward(self, h, adj):
hidden = torch.mm(h, self.W)
attention_input = self._prepare_attentional_mechanism_input(hidden)
e = self.leakyrelu(torch.matmul(attention_input, self.attention_w).
squeeze(2))
zero_vec = -9000000000000000.0 * torch.ones_like(e)
attention = torch.where(adj > 0, e * adj, zero_vec)
attention = F.softmax(attention, dim=1)
attention = F.dropout(attention, self.dropout, training=self.training)
h_prime = torch.matmul(attention, hidden)
if self.concat:
return F.elu(h_prime)
else:
return h_prime
def _prepare_attentional_mechanism_input(self, Wh):
N = Wh.size(0)
Wh_repeated_in_chunks = Wh.repeat_interleave(N, dim=0)
Wh_repeated_alternating = Wh.repeat(N, 1)
all_combinations_matrix = torch.cat([Wh_repeated_in_chunks,
Wh_repeated_alternating], dim=1)
return all_combinations_matrix.view(N, N, 2 * self.out_features)
class GAT(nn.Module):
def __init__(self, nfeat, nhid, nclass, dropout, alpha, nheads):
"""Dense version of GAT."""
super(GAT, self).__init__()
self.dropout = dropout
self.attentions = [GraphAttConv(nfeat, nhid, dropout=dropout, alpha
=alpha, concat=True) for _ in range(nheads)]
for i, attention in enumerate(self.attentions):
self.add_module('attention_{}'.format(i), attention)
self.out_att = GraphAttConv(nhid * nheads, nclass, dropout=dropout,
alpha=alpha, concat=False)
def forward(self, x, adj):
x = F.dropout(x, self.dropout, training=self.training)
x = torch.cat([att(x, adj) for att in self.attentions], dim=1)
x = F.dropout(x, self.dropout, training=self.training)
x = F.elu(self.out_att(x, adj))
return F.log_softmax(x, dim=1), x
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4])]
def get_init_inputs():
return [[], {'nfeat': 4, 'nhid': 4, 'nclass': 4, 'dropout': 0.5,
'alpha': 4, 'nheads': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
import torch.nn.functional as F
import torch.autograd
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_cat_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 8
x1 = xindex // 8
x2 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (4 * (x1 // 4) + x0), tmp4 & xmask,
eviction_policy='evict_last', other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 8, tl.int64)
tmp9 = tl.load(in_ptr0 + (4 * (x1 % 4) + (-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_leaky_relu_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 0.0
tmp2 = tmp0 > tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused__softmax_gt_leaky_relu_mul_where_2(in_ptr0, in_ptr1,
in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8, out_ptr0,
out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5, out_ptr6, out_ptr7,
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')
tmp3 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last').to(tl
.int1)
tmp4 = tl.load(in_ptr2 + 4 * x0, xmask, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp13 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
).to(tl.int1)
tmp14 = tl.load(in_ptr2 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp20 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp22 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
).to(tl.int1)
tmp23 = tl.load(in_ptr2 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp29 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp31 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
).to(tl.int1)
tmp32 = tl.load(in_ptr2 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp49 = tl.load(in_ptr3 + 4 * x0, xmask, eviction_policy='evict_last').to(
tl.int1)
tmp50 = tl.load(in_ptr4 + 4 * x0, xmask, eviction_policy='evict_last')
tmp55 = tl.load(in_ptr3 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
).to(tl.int1)
tmp56 = tl.load(in_ptr4 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp62 = tl.load(in_ptr3 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
).to(tl.int1)
tmp63 = tl.load(in_ptr4 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp69 = tl.load(in_ptr3 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
).to(tl.int1)
tmp70 = tl.load(in_ptr4 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp87 = tl.load(in_ptr5 + 4 * x0, xmask, eviction_policy='evict_last').to(
tl.int1)
tmp88 = tl.load(in_ptr6 + 4 * x0, xmask, eviction_policy='evict_last')
tmp93 = tl.load(in_ptr5 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
).to(tl.int1)
tmp94 = tl.load(in_ptr6 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp100 = tl.load(in_ptr5 + (2 + 4 * x0), xmask, eviction_policy=
'evict_last').to(tl.int1)
tmp101 = tl.load(in_ptr6 + (2 + 4 * x0), xmask, eviction_policy=
'evict_last')
tmp107 = tl.load(in_ptr5 + (3 + 4 * x0), xmask, eviction_policy=
'evict_last').to(tl.int1)
tmp108 = tl.load(in_ptr6 + (3 + 4 * x0), xmask, eviction_policy=
'evict_last')
tmp125 = tl.load(in_ptr7 + 4 * x0, xmask, eviction_policy='evict_last').to(
tl.int1)
tmp126 = tl.load(in_ptr8 + 4 * x0, xmask, eviction_policy='evict_last')
tmp131 = tl.load(in_ptr7 + (1 + 4 * x0), xmask, eviction_policy=
'evict_last').to(tl.int1)
tmp132 = tl.load(in_ptr8 + (1 + 4 * x0), xmask, eviction_policy=
'evict_last')
tmp138 = tl.load(in_ptr7 + (2 + 4 * x0), xmask, eviction_policy=
'evict_last').to(tl.int1)
tmp139 = tl.load(in_ptr8 + (2 + 4 * x0), xmask, eviction_policy=
'evict_last')
tmp145 = tl.load(in_ptr7 + (3 + 4 * x0), xmask, eviction_policy=
'evict_last').to(tl.int1)
tmp146 = tl.load(in_ptr8 + (3 + 4 * x0), xmask, eviction_policy=
'evict_last')
tmp1 = 0.0
tmp2 = tmp0 > tmp1
tmp5 = 4.0
tmp6 = tmp4 * tmp5
tmp7 = tl.where(tmp3, tmp4, tmp6)
tmp8 = tmp7 * tmp0
tmp9 = -8999999815811072.0
tmp10 = tl.where(tmp2, tmp8, tmp9)
tmp12 = tmp11 > tmp1
tmp15 = tmp14 * tmp5
tmp16 = tl.where(tmp13, tmp14, tmp15)
tmp17 = tmp16 * tmp11
tmp18 = tl.where(tmp12, tmp17, tmp9)
tmp19 = triton_helpers.maximum(tmp10, tmp18)
tmp21 = tmp20 > tmp1
tmp24 = tmp23 * tmp5
tmp25 = tl.where(tmp22, tmp23, tmp24)
tmp26 = tmp25 * tmp20
tmp27 = tl.where(tmp21, tmp26, tmp9)
tmp28 = triton_helpers.maximum(tmp19, tmp27)
tmp30 = tmp29 > tmp1
tmp33 = tmp32 * tmp5
tmp34 = tl.where(tmp31, tmp32, tmp33)
tmp35 = tmp34 * tmp29
tmp36 = tl.where(tmp30, tmp35, tmp9)
tmp37 = triton_helpers.maximum(tmp28, tmp36)
tmp38 = tmp10 - tmp37
tmp39 = tl_math.exp(tmp38)
tmp40 = tmp18 - tmp37
tmp41 = tl_math.exp(tmp40)
tmp42 = tmp39 + tmp41
tmp43 = tmp27 - tmp37
tmp44 = tl_math.exp(tmp43)
tmp45 = tmp42 + tmp44
tmp46 = tmp36 - tmp37
tmp47 = tl_math.exp(tmp46)
tmp48 = tmp45 + tmp47
tmp51 = tmp50 * tmp5
tmp52 = tl.where(tmp49, tmp50, tmp51)
tmp53 = tmp52 * tmp0
tmp54 = tl.where(tmp2, tmp53, tmp9)
tmp57 = tmp56 * tmp5
tmp58 = tl.where(tmp55, tmp56, tmp57)
tmp59 = tmp58 * tmp11
tmp60 = tl.where(tmp12, tmp59, tmp9)
tmp61 = triton_helpers.maximum(tmp54, tmp60)
tmp64 = tmp63 * tmp5
tmp65 = tl.where(tmp62, tmp63, tmp64)
tmp66 = tmp65 * tmp20
tmp67 = tl.where(tmp21, tmp66, tmp9)
tmp68 = triton_helpers.maximum(tmp61, tmp67)
tmp71 = tmp70 * tmp5
tmp72 = tl.where(tmp69, tmp70, tmp71)
tmp73 = tmp72 * tmp29
tmp74 = tl.where(tmp30, tmp73, tmp9)
tmp75 = triton_helpers.maximum(tmp68, tmp74)
tmp76 = tmp54 - tmp75
tmp77 = tl_math.exp(tmp76)
tmp78 = tmp60 - tmp75
tmp79 = tl_math.exp(tmp78)
tmp80 = tmp77 + tmp79
tmp81 = tmp67 - tmp75
tmp82 = tl_math.exp(tmp81)
tmp83 = tmp80 + tmp82
tmp84 = tmp74 - tmp75
tmp85 = tl_math.exp(tmp84)
tmp86 = tmp83 + tmp85
tmp89 = tmp88 * tmp5
tmp90 = tl.where(tmp87, tmp88, tmp89)
tmp91 = tmp90 * tmp0
tmp92 = tl.where(tmp2, tmp91, tmp9)
tmp95 = tmp94 * tmp5
tmp96 = tl.where(tmp93, tmp94, tmp95)
tmp97 = tmp96 * tmp11
tmp98 = tl.where(tmp12, tmp97, tmp9)
tmp99 = triton_helpers.maximum(tmp92, tmp98)
tmp102 = tmp101 * tmp5
tmp103 = tl.where(tmp100, tmp101, tmp102)
tmp104 = tmp103 * tmp20
tmp105 = tl.where(tmp21, tmp104, tmp9)
tmp106 = triton_helpers.maximum(tmp99, tmp105)
tmp109 = tmp108 * tmp5
tmp110 = tl.where(tmp107, tmp108, tmp109)
tmp111 = tmp110 * tmp29
tmp112 = tl.where(tmp30, tmp111, tmp9)
tmp113 = triton_helpers.maximum(tmp106, tmp112)
tmp114 = tmp92 - tmp113
tmp115 = tl_math.exp(tmp114)
tmp116 = tmp98 - tmp113
tmp117 = tl_math.exp(tmp116)
tmp118 = tmp115 + tmp117
tmp119 = tmp105 - tmp113
tmp120 = tl_math.exp(tmp119)
tmp121 = tmp118 + tmp120
tmp122 = tmp112 - tmp113
tmp123 = tl_math.exp(tmp122)
tmp124 = tmp121 + tmp123
tmp127 = tmp126 * tmp5
tmp128 = tl.where(tmp125, tmp126, tmp127)
tmp129 = tmp128 * tmp0
tmp130 = tl.where(tmp2, tmp129, tmp9)
tmp133 = tmp132 * tmp5
tmp134 = tl.where(tmp131, tmp132, tmp133)
tmp135 = tmp134 * tmp11
tmp136 = tl.where(tmp12, tmp135, tmp9)
tmp137 = triton_helpers.maximum(tmp130, tmp136)
tmp140 = tmp139 * tmp5
tmp141 = tl.where(tmp138, tmp139, tmp140)
tmp142 = tmp141 * tmp20
tmp143 = tl.where(tmp21, tmp142, tmp9)
tmp144 = triton_helpers.maximum(tmp137, tmp143)
tmp147 = tmp146 * tmp5
tmp148 = tl.where(tmp145, tmp146, tmp147)
tmp149 = tmp148 * tmp29
tmp150 = tl.where(tmp30, tmp149, tmp9)
tmp151 = triton_helpers.maximum(tmp144, tmp150)
tmp152 = tmp130 - tmp151
tmp153 = tl_math.exp(tmp152)
tmp154 = tmp136 - tmp151
tmp155 = tl_math.exp(tmp154)
tmp156 = tmp153 + tmp155
tmp157 = tmp143 - tmp151
tmp158 = tl_math.exp(tmp157)
tmp159 = tmp156 + tmp158
tmp160 = tmp150 - tmp151
tmp161 = tl_math.exp(tmp160)
tmp162 = tmp159 + tmp161
tl.store(out_ptr0 + x0, tmp37, xmask)
tl.store(out_ptr1 + x0, tmp48, xmask)
tl.store(out_ptr2 + x0, tmp75, xmask)
tl.store(out_ptr3 + x0, tmp86, xmask)
tl.store(out_ptr4 + x0, tmp113, xmask)
tl.store(out_ptr5 + x0, tmp124, xmask)
tl.store(out_ptr6 + x0, tmp151, xmask)
tl.store(out_ptr7 + x0, tmp162, xmask)
@triton.jit
def triton_poi_fused__softmax_gt_leaky_relu_mul_where_3(in_out_ptr0,
in_out_ptr1, in_out_ptr2, in_out_ptr3, in_ptr0, in_ptr1, in_ptr2,
in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8, in_ptr9, in_ptr10,
in_ptr11, in_ptr12, 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)
tmp3 = tl.load(in_ptr1 + x2, xmask).to(tl.int1)
tmp4 = tl.load(in_out_ptr0 + x2, xmask)
tmp11 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp14 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
tmp16 = tl.load(in_ptr4 + x2, xmask).to(tl.int1)
tmp17 = tl.load(in_out_ptr1 + x2, xmask)
tmp22 = tl.load(in_ptr5 + x1, xmask, eviction_policy='evict_last')
tmp25 = tl.load(in_ptr6 + x1, xmask, eviction_policy='evict_last')
tmp27 = tl.load(in_ptr7 + x2, xmask).to(tl.int1)
tmp28 = tl.load(in_out_ptr2 + x2, xmask)
tmp33 = tl.load(in_ptr8 + x1, xmask, eviction_policy='evict_last')
tmp36 = tl.load(in_ptr9 + x1, xmask, eviction_policy='evict_last')
tmp38 = tl.load(in_ptr10 + x2, xmask).to(tl.int1)
tmp39 = tl.load(in_out_ptr3 + x2, xmask)
tmp44 = tl.load(in_ptr11 + x1, xmask, eviction_policy='evict_last')
tmp47 = tl.load(in_ptr12 + x1, xmask, eviction_policy='evict_last')
tmp1 = 0.0
tmp2 = tmp0 > tmp1
tmp5 = 4.0
tmp6 = tmp4 * tmp5
tmp7 = tl.where(tmp3, tmp4, tmp6)
tmp8 = tmp7 * tmp0
tmp9 = -8999999815811072.0
tmp10 = tl.where(tmp2, tmp8, tmp9)
tmp12 = tmp10 - tmp11
tmp13 = tl_math.exp(tmp12)
tmp15 = tmp13 / tmp14
tmp18 = tmp17 * tmp5
tmp19 = tl.where(tmp16, tmp17, tmp18)
tmp20 = tmp19 * tmp0
tmp21 = tl.where(tmp2, tmp20, tmp9)
tmp23 = tmp21 - tmp22
tmp24 = tl_math.exp(tmp23)
tmp26 = tmp24 / tmp25
tmp29 = tmp28 * tmp5
tmp30 = tl.where(tmp27, tmp28, tmp29)
tmp31 = tmp30 * tmp0
tmp32 = tl.where(tmp2, tmp31, tmp9)
tmp34 = tmp32 - tmp33
tmp35 = tl_math.exp(tmp34)
tmp37 = tmp35 / tmp36
tmp40 = tmp39 * tmp5
tmp41 = tl.where(tmp38, tmp39, tmp40)
tmp42 = tmp41 * tmp0
tmp43 = tl.where(tmp2, tmp42, tmp9)
tmp45 = tmp43 - tmp44
tmp46 = tl_math.exp(tmp45)
tmp48 = tmp46 / tmp47
tl.store(in_out_ptr0 + x2, tmp15, xmask)
tl.store(in_out_ptr1 + x2, tmp26, xmask)
tl.store(in_out_ptr2 + x2, tmp37, xmask)
tl.store(in_out_ptr3 + x2, tmp48, xmask)
@triton.jit
def triton_poi_fused_cat_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 16
x1 = xindex // 16
x2 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = 0.0
tmp7 = tmp5 > tmp6
tmp8 = 1.0
tmp9 = tmp5 * tmp8
tmp10 = libdevice.expm1(tmp9)
tmp11 = tmp10 * tmp8
tmp12 = tl.where(tmp7, tmp9, tmp11)
tmp13 = tl.full(tmp12.shape, 0.0, tmp12.dtype)
tmp14 = tl.where(tmp4, tmp12, tmp13)
tmp15 = tmp0 >= tmp3
tmp16 = tl.full([1], 8, tl.int64)
tmp17 = tmp0 < tmp16
tmp18 = tmp15 & tmp17
tmp19 = tl.load(in_ptr1 + (4 * x1 + (-4 + x0)), tmp18 & xmask,
eviction_policy='evict_last', other=0.0)
tmp20 = tmp19 > tmp6
tmp21 = tmp19 * tmp8
tmp22 = libdevice.expm1(tmp21)
tmp23 = tmp22 * tmp8
tmp24 = tl.where(tmp20, tmp21, tmp23)
tmp25 = tl.full(tmp24.shape, 0.0, tmp24.dtype)
tmp26 = tl.where(tmp18, tmp24, tmp25)
tmp27 = tmp0 >= tmp16
tmp28 = tl.full([1], 12, tl.int64)
tmp29 = tmp0 < tmp28
tmp30 = tmp27 & tmp29
tmp31 = tl.load(in_ptr2 + (4 * x1 + (-8 + x0)), tmp30 & xmask,
eviction_policy='evict_last', other=0.0)
tmp32 = tmp31 > tmp6
tmp33 = tmp31 * tmp8
tmp34 = libdevice.expm1(tmp33)
tmp35 = tmp34 * tmp8
tmp36 = tl.where(tmp32, tmp33, tmp35)
tmp37 = tl.full(tmp36.shape, 0.0, tmp36.dtype)
tmp38 = tl.where(tmp30, tmp36, tmp37)
tmp39 = tmp0 >= tmp28
tl.full([1], 16, tl.int64)
tmp42 = tl.load(in_ptr3 + (4 * x1 + (-12 + x0)), tmp39 & xmask,
eviction_policy='evict_last', other=0.0)
tmp43 = tmp42 > tmp6
tmp44 = tmp42 * tmp8
tmp45 = libdevice.expm1(tmp44)
tmp46 = tmp45 * tmp8
tmp47 = tl.where(tmp43, tmp44, tmp46)
tmp48 = tl.full(tmp47.shape, 0.0, tmp47.dtype)
tmp49 = tl.where(tmp39, tmp47, tmp48)
tmp50 = tl.where(tmp30, tmp38, tmp49)
tmp51 = tl.where(tmp18, tmp26, tmp50)
tmp52 = tl.where(tmp4, tmp14, tmp51)
tl.store(out_ptr0 + x2, tmp52, xmask)
@triton.jit
def triton_poi_fused__softmax_gt_leaky_relu_mul_where_5(in_ptr0, in_ptr1,
in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last').to(tl
.int1)
tmp4 = tl.load(in_ptr2 + 4 * x0, xmask, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp13 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
).to(tl.int1)
tmp14 = tl.load(in_ptr2 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp20 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp22 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
).to(tl.int1)
tmp23 = tl.load(in_ptr2 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp29 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp31 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
).to(tl.int1)
tmp32 = tl.load(in_ptr2 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp1 = 0.0
tmp2 = tmp0 > tmp1
tmp5 = 4.0
tmp6 = tmp4 * tmp5
tmp7 = tl.where(tmp3, tmp4, tmp6)
tmp8 = tmp7 * tmp0
tmp9 = -8999999815811072.0
tmp10 = tl.where(tmp2, tmp8, tmp9)
tmp12 = tmp11 > tmp1
tmp15 = tmp14 * tmp5
tmp16 = tl.where(tmp13, tmp14, tmp15)
tmp17 = tmp16 * tmp11
tmp18 = tl.where(tmp12, tmp17, tmp9)
tmp19 = triton_helpers.maximum(tmp10, tmp18)
tmp21 = tmp20 > tmp1
tmp24 = tmp23 * tmp5
tmp25 = tl.where(tmp22, tmp23, tmp24)
tmp26 = tmp25 * tmp20
tmp27 = tl.where(tmp21, tmp26, tmp9)
tmp28 = triton_helpers.maximum(tmp19, tmp27)
tmp30 = tmp29 > tmp1
tmp33 = tmp32 * tmp5
tmp34 = tl.where(tmp31, tmp32, tmp33)
tmp35 = tmp34 * tmp29
tmp36 = tl.where(tmp30, tmp35, tmp9)
tmp37 = triton_helpers.maximum(tmp28, tmp36)
tmp38 = tmp10 - tmp37
tmp39 = tl_math.exp(tmp38)
tmp40 = tmp18 - tmp37
tmp41 = tl_math.exp(tmp40)
tmp42 = tmp39 + tmp41
tmp43 = tmp27 - tmp37
tmp44 = tl_math.exp(tmp43)
tmp45 = tmp42 + tmp44
tmp46 = tmp36 - tmp37
tmp47 = tl_math.exp(tmp46)
tmp48 = tmp45 + tmp47
tl.store(out_ptr0 + x0, tmp37, xmask)
tl.store(out_ptr1 + x0, tmp48, xmask)
@triton.jit
def triton_poi_fused__softmax_gt_leaky_relu_mul_where_6(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
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp3 = tl.load(in_ptr1 + x2, xmask).to(tl.int1)
tmp4 = tl.load(in_out_ptr0 + x2, xmask)
tmp11 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp14 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
tmp1 = 0.0
tmp2 = tmp0 > tmp1
tmp5 = 4.0
tmp6 = tmp4 * tmp5
tmp7 = tl.where(tmp3, tmp4, tmp6)
tmp8 = tmp7 * tmp0
tmp9 = -8999999815811072.0
tmp10 = tl.where(tmp2, tmp8, tmp9)
tmp12 = tmp10 - tmp11
tmp13 = tl_math.exp(tmp12)
tmp15 = tmp13 / tmp14
tl.store(in_out_ptr0 + x2, tmp15, xmask)
@triton.jit
def triton_poi_fused_elu_7(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 0.0
tmp2 = tmp0 > tmp1
tmp3 = 1.0
tmp4 = tmp0 * tmp3
tmp5 = libdevice.expm1(tmp4)
tmp6 = tmp5 * tmp3
tmp7 = tl.where(tmp2, tmp4, tmp6)
tl.store(out_ptr0 + x0, tmp7, xmask)
@triton.jit
def triton_poi_fused__log_softmax_8(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
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_9(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp2 = tl_math.exp(tmp1)
tmp4 = tl_math.exp(tmp3)
tmp5 = tmp2 + tmp4
tmp7 = tl_math.exp(tmp6)
tmp8 = tmp5 + tmp7
tmp10 = tl_math.exp(tmp9)
tmp11 = tmp8 + tmp10
tmp12 = tl_math.log(tmp11)
tmp13 = tmp0 - tmp12
tl.store(out_ptr0 + x2, tmp13, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11, primals_12
) = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (8, 1), (1, 1))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (4, 4), (4, 1))
assert_size_stride(primals_6, (8, 1), (1, 1))
assert_size_stride(primals_7, (4, 4), (4, 1))
assert_size_stride(primals_8, (8, 1), (1, 1))
assert_size_stride(primals_9, (4, 4), (4, 1))
assert_size_stride(primals_10, (8, 1), (1, 1))
assert_size_stride(primals_11, (16, 4), (4, 1))
assert_size_stride(primals_12, (8, 1), (1, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_1, primals_2, out=buf0)
del primals_2
buf1 = empty_strided_cuda((16, 8), (8, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(128)](buf0, buf1, 128, XBLOCK=128,
num_warps=4, num_stages=1)
buf2 = empty_strided_cuda((16, 1), (1, 1), torch.float32)
extern_kernels.mm(buf1, primals_3, out=buf2)
buf3 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
triton_poi_fused_leaky_relu_1[grid(16)](buf2, buf3, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf8 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_1, primals_5, out=buf8)
del primals_5
buf9 = empty_strided_cuda((16, 8), (8, 1), torch.float32)
triton_poi_fused_cat_0[grid(128)](buf8, buf9, 128, XBLOCK=128,
num_warps=4, num_stages=1)
buf10 = empty_strided_cuda((16, 1), (1, 1), torch.float32)
extern_kernels.mm(buf9, primals_6, out=buf10)
buf11 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
triton_poi_fused_leaky_relu_1[grid(16)](buf10, buf11, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf16 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_1, primals_7, out=buf16)
del primals_7
buf17 = empty_strided_cuda((16, 8), (8, 1), torch.float32)
triton_poi_fused_cat_0[grid(128)](buf16, buf17, 128, XBLOCK=128,
num_warps=4, num_stages=1)
buf18 = empty_strided_cuda((16, 1), (1, 1), torch.float32)
extern_kernels.mm(buf17, primals_8, out=buf18)
buf19 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
triton_poi_fused_leaky_relu_1[grid(16)](buf18, buf19, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf24 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_1, primals_9, out=buf24)
del primals_9
buf25 = empty_strided_cuda((16, 8), (8, 1), torch.float32)
triton_poi_fused_cat_0[grid(128)](buf24, buf25, 128, XBLOCK=128,
num_warps=4, num_stages=1)
buf26 = empty_strided_cuda((16, 1), (1, 1), torch.float32)
extern_kernels.mm(buf25, primals_10, out=buf26)
buf27 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
triton_poi_fused_leaky_relu_1[grid(16)](buf26, buf27, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf4 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
buf5 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
buf12 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
buf13 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
buf20 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
buf21 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
buf28 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
buf29 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
triton_poi_fused__softmax_gt_leaky_relu_mul_where_2[grid(4)](primals_4,
buf3, buf2, buf11, buf10, buf19, buf18, buf27, buf26, buf4,
buf5, buf12, buf13, buf20, buf21, buf28, buf29, 4, XBLOCK=4,
num_warps=1, num_stages=1)
buf6 = reinterpret_tensor(buf2, (4, 4), (4, 1), 0)
del buf2
buf14 = reinterpret_tensor(buf10, (4, 4), (4, 1), 0)
del buf10
buf22 = reinterpret_tensor(buf18, (4, 4), (4, 1), 0)
del buf18
buf30 = reinterpret_tensor(buf26, (4, 4), (4, 1), 0)
del buf26
triton_poi_fused__softmax_gt_leaky_relu_mul_where_3[grid(16)](buf6,
buf14, buf22, buf30, primals_4, buf3, buf4, buf5, buf11, buf12,
buf13, buf19, buf20, buf21, buf27, buf28, buf29, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del buf12
del buf13
del buf20
del buf21
del buf28
del buf29
buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf6, buf0, out=buf7)
buf15 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf14, buf8, out=buf15)
buf23 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf22, buf16, out=buf23)
buf31 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf30, buf24, out=buf31)
buf32 = empty_strided_cuda((4, 16), (16, 1), torch.float32)
triton_poi_fused_cat_4[grid(64)](buf7, buf15, buf23, buf31, buf32,
64, XBLOCK=64, num_warps=1, num_stages=1)
buf33 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf32, primals_11, out=buf33)
buf34 = empty_strided_cuda((16, 8), (8, 1), torch.float32)
triton_poi_fused_cat_0[grid(128)](buf33, buf34, 128, XBLOCK=128,
num_warps=4, num_stages=1)
buf35 = empty_strided_cuda((16, 1), (1, 1), torch.float32)
extern_kernels.mm(buf34, primals_12, out=buf35)
buf36 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
triton_poi_fused_leaky_relu_1[grid(16)](buf35, buf36, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf37 = buf5
del buf5
buf38 = buf4
del buf4
triton_poi_fused__softmax_gt_leaky_relu_mul_where_5[grid(4)](primals_4,
buf36, buf35, buf37, buf38, 4, XBLOCK=4, num_warps=1, num_stages=1)
buf39 = reinterpret_tensor(buf35, (4, 4), (4, 1), 0)
del buf35
triton_poi_fused__softmax_gt_leaky_relu_mul_where_6[grid(16)](buf39,
primals_4, buf36, buf37, buf38, 16, XBLOCK=16, num_warps=1,
num_stages=1)
del buf37
del buf38
buf40 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf39, buf33, out=buf40)
buf41 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused_elu_7[grid(16)](buf40, buf41, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf42 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused__log_softmax_8[grid(16)](buf41, buf42, 16, XBLOCK=
16, num_warps=1, num_stages=1)
buf43 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused__log_softmax_9[grid(16)](buf42, buf43, 16, XBLOCK=
16, num_warps=1, num_stages=1)
del buf42
return (buf43, buf41, primals_4, buf3, buf6, buf7, buf11, buf14, buf15,
buf19, buf22, buf23, buf27, buf30, buf31, buf36, buf39, buf40,
buf43, reinterpret_tensor(buf33, (4, 4), (1, 4), 0),
reinterpret_tensor(buf34, (8, 16), (1, 8), 0), reinterpret_tensor(
primals_12, (1, 8), (1, 1), 0), reinterpret_tensor(buf32, (16, 4),
(1, 16), 0), reinterpret_tensor(primals_11, (4, 16), (1, 4), 0),
reinterpret_tensor(buf24, (4, 4), (1, 4), 0), reinterpret_tensor(
buf25, (8, 16), (1, 8), 0), reinterpret_tensor(primals_10, (1, 8),
(1, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0),
reinterpret_tensor(buf16, (4, 4), (1, 4), 0), reinterpret_tensor(
buf17, (8, 16), (1, 8), 0), reinterpret_tensor(primals_8, (1, 8), (
1, 1), 0), reinterpret_tensor(buf8, (4, 4), (1, 4), 0),
reinterpret_tensor(buf9, (8, 16), (1, 8), 0), reinterpret_tensor(
primals_6, (1, 8), (1, 1), 0), reinterpret_tensor(buf0, (4, 4), (1,
4), 0), reinterpret_tensor(buf1, (8, 16), (1, 8), 0),
reinterpret_tensor(primals_3, (1, 8), (1, 1), 0))
class GraphAttConv(nn.Module):
def __init__(self, in_features, out_features, dropout, alpha, concat=True):
super(GraphAttConv, self).__init__()
self.dropout = dropout
self.in_features = in_features
self.out_features = out_features
self.alpha = alpha
self.concat = concat
self.W = nn.Parameter(torch.empty(size=(in_features, out_features)))
nn.init.xavier_uniform_(self.W.data, gain=1.414)
self.attention_w = nn.Parameter(torch.empty(size=(2 * out_features, 1))
)
nn.init.xavier_uniform_(self.attention_w.data, gain=1.414)
self.leakyrelu = nn.LeakyReLU(self.alpha)
def forward(self, h, adj):
hidden = torch.mm(h, self.W)
attention_input = self._prepare_attentional_mechanism_input(hidden)
e = self.leakyrelu(torch.matmul(attention_input, self.attention_w).
squeeze(2))
zero_vec = -9000000000000000.0 * torch.ones_like(e)
attention = torch.where(adj > 0, e * adj, zero_vec)
attention = F.softmax(attention, dim=1)
attention = F.dropout(attention, self.dropout, training=self.training)
h_prime = torch.matmul(attention, hidden)
if self.concat:
return F.elu(h_prime)
else:
return h_prime
def _prepare_attentional_mechanism_input(self, Wh):
N = Wh.size(0)
Wh_repeated_in_chunks = Wh.repeat_interleave(N, dim=0)
Wh_repeated_alternating = Wh.repeat(N, 1)
all_combinations_matrix = torch.cat([Wh_repeated_in_chunks,
Wh_repeated_alternating], dim=1)
return all_combinations_matrix.view(N, N, 2 * self.out_features)
class GATNew(nn.Module):
def __init__(self, nfeat, nhid, nclass, dropout, alpha, nheads):
"""Dense version of GAT."""
super(GATNew, self).__init__()
self.dropout = dropout
self.attentions = [GraphAttConv(nfeat, nhid, dropout=dropout, alpha
=alpha, concat=True) for _ in range(nheads)]
for i, attention in enumerate(self.attentions):
self.add_module('attention_{}'.format(i), attention)
self.out_att = GraphAttConv(nhid * nheads, nclass, dropout=dropout,
alpha=alpha, concat=False)
def forward(self, input_0, input_1):
primals_1 = self.attention_0.W
primals_3 = self.attention_0.attention_w
primals_2 = self.attention_1.W
primals_6 = self.attention_1.attention_w
primals_4 = self.attention_2.W
primals_8 = self.attention_2.attention_w
primals_5 = self.attention_3.W
primals_10 = self.attention_3.attention_w
primals_11 = self.out_att.W
primals_12 = self.out_att.attention_w
primals_7 = input_0
primals_9 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11, primals_12])
return output[0], output[1]
|
SsGood/MMGL
|
GAT
| false
| 17,993
|
[
"MIT"
] | 6
|
ea769e46fffb42559e764e2912c5b1dc17c10af2
|
https://github.com/SsGood/MMGL/tree/ea769e46fffb42559e764e2912c5b1dc17c10af2
|
SCANLoss
|
import torch
from torch import nn
import torch.nn.functional as F
def entropy(x, input_as_probabilities):
"""
Helper function to compute the entropy over the batch
input: batch w/ shape [b, num_classes]
output: entropy value [is ideally -log(num_classes)]
"""
if input_as_probabilities:
x_ = torch.clamp(x, min=1e-08)
b = x_ * torch.log(x_)
else:
b = F.softmax(x, dim=1) * F.log_softmax(x, dim=1)
if len(b.size()) == 2:
return -b.sum(dim=1).mean()
elif len(b.size()) == 1:
return -b.sum()
else:
raise ValueError('Input tensor is %d-Dimensional' % len(b.size()))
class SCANLoss(nn.Module):
def __init__(self, entropy_weight=2.0):
super(SCANLoss, self).__init__()
self.softmax = nn.Softmax(dim=1)
self.bce = nn.BCELoss()
self.entropy_weight = entropy_weight
def forward(self, anchors, neighbors):
"""
input:
- anchors: logits for anchor images w/ shape [b, num_classes]
- neighbors: logits for neighbor images w/ shape [b, num_classes]
output:
- Loss
"""
b, n = anchors.size()
anchors_prob = self.softmax(anchors)
positives_prob = self.softmax(neighbors)
similarity = torch.bmm(anchors_prob.view(b, 1, n), positives_prob.
view(b, n, 1)).squeeze()
ones = torch.ones_like(similarity)
consistency_loss = self.bce(similarity, ones)
entropy_loss = entropy(torch.mean(anchors_prob, 0),
input_as_probabilities=True)
total_loss = consistency_loss - self.entropy_weight * entropy_loss
return total_loss, consistency_loss, entropy_loss
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4, 1])]
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, math as tl_math
from torch import nn
import torch.nn.functional as F
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
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 = 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)
@triton.jit
def triton_per_fused_binary_cross_entropy_clamp_log_mean_mul_neg_sub_sum_2(
in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel,
XBLOCK: tl.constexpr):
RBLOCK: tl.constexpr = 4
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp1 = tl.load(in_ptr0 + (4 + r0), None)
tmp3 = tl.load(in_ptr0 + (8 + r0), None)
tmp5 = tl.load(in_ptr0 + (12 + r0), None)
tmp16 = tl.load(in_ptr1 + r0, None)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp7 = 4.0
tmp8 = tmp6 / tmp7
tmp9 = 1e-08
tmp10 = triton_helpers.maximum(tmp8, tmp9)
tmp11 = tl_math.log(tmp10)
tmp12 = tmp10 * tmp11
tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK])
tmp15 = tl.sum(tmp13, 1)[:, None]
tmp17 = -tmp16
tmp18 = libdevice.log1p(tmp17)
tmp19 = -100.0
tmp20 = triton_helpers.maximum(tmp18, tmp19)
tmp21 = 0.0
tmp22 = tmp21 * tmp20
tmp23 = tl_math.log(tmp16)
tmp24 = triton_helpers.maximum(tmp23, tmp19)
tmp25 = tmp22 - tmp24
tmp26 = tl.broadcast_to(tmp25, [XBLOCK, RBLOCK])
tmp28 = tl.sum(tmp26, 1)[:, None]
tmp29 = tmp28 / tmp7
tmp30 = -tmp15
tmp31 = 2.0
tmp32 = tmp30 * tmp31
tmp33 = tmp29 - tmp32
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp29, None)
tl.debug_barrier()
tl.store(in_out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp30, None)
tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp33, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4), (4, 1))
assert_size_stride(arg1_1, (4, 4, 1), (4, 1, 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__softmax_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)
triton_poi_fused__softmax_1[grid(16)](buf0, buf1, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf2 = reinterpret_tensor(buf0, (4, 4, 1), (4, 1, 16), 0)
del buf0
triton_poi_fused__softmax_0[grid(16)](arg1_1, buf2, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del arg1_1
buf3 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
triton_poi_fused__softmax_1[grid(16)](buf2, buf3, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del buf2
buf4 = empty_strided_cuda((4, 1, 1), (1, 1, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf1, (4, 1, 4), (4, 4, 1), 0
), buf3, out=buf4)
del buf3
buf7 = empty_strided_cuda((), (), torch.float32)
buf5 = empty_strided_cuda((), (), torch.float32)
buf6 = buf5
del buf5
buf8 = buf7
del buf7
buf9 = empty_strided_cuda((), (), torch.float32)
triton_per_fused_binary_cross_entropy_clamp_log_mean_mul_neg_sub_sum_2[
grid(1)](buf6, buf8, buf1, buf4, buf9, 1, 4, XBLOCK=1,
num_warps=2, num_stages=1)
del buf1
del buf4
return buf9, buf6, buf8
def entropy(x, input_as_probabilities):
"""
Helper function to compute the entropy over the batch
input: batch w/ shape [b, num_classes]
output: entropy value [is ideally -log(num_classes)]
"""
if input_as_probabilities:
x_ = torch.clamp(x, min=1e-08)
b = x_ * torch.log(x_)
else:
b = F.softmax(x, dim=1) * F.log_softmax(x, dim=1)
if len(b.size()) == 2:
return -b.sum(dim=1).mean()
elif len(b.size()) == 1:
return -b.sum()
else:
raise ValueError('Input tensor is %d-Dimensional' % len(b.size()))
class SCANLossNew(nn.Module):
def __init__(self, entropy_weight=2.0):
super(SCANLossNew, self).__init__()
self.softmax = nn.Softmax(dim=1)
self.bce = nn.BCELoss()
self.entropy_weight = entropy_weight
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0], output[1], output[2]
|
TencentYoutuResearch/ActiveLearning-SDM
|
SCANLoss
| false
| 17,994
|
[
"Apache-2.0"
] | 4
|
0ee700e59451131536b7509ff3d4b266835ac01b
|
https://github.com/TencentYoutuResearch/ActiveLearning-SDM/tree/0ee700e59451131536b7509ff3d4b266835ac01b
|
Concat
|
import torch
import torch.nn
import torch.utils.data
import torch.utils.tensorboard._pytorch_graph
import torch.onnx.symbolic_caffe2
class Concat(torch.nn.Module):
""" Concat module for a functional concat"""
def __init__(self, axis: 'int'=0):
super(Concat, self).__init__()
self.axis = axis
def forward(self, x, y):
"""
Forward-pass routine for divide op
"""
return torch.cat((x, y), self.axis)
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn
import torch.utils.data
import torch.utils.tensorboard._pytorch_graph
import torch.onnx.symbolic_caffe2
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 512
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 64
x0 = xindex % 64
x2 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 64 * x1), tmp4 & xmask, other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 8, tl.int64)
tmp9 = tl.load(in_ptr1 + (x0 + 64 * (-4 + x1)), tmp6 & xmask, other=0.0)
tmp10 = tl.where(tmp4, tmp5, tmp9)
tl.store(out_ptr0 + x2, tmp10, xmask)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((8, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(512)](arg0_1, arg1_1, buf0, 512, XBLOCK
=128, num_warps=4, num_stages=1)
del arg0_1
del arg1_1
return buf0,
class ConcatNew(torch.nn.Module):
""" Concat module for a functional concat"""
def __init__(self, axis: 'int'=0):
super(ConcatNew, self).__init__()
self.axis = axis
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
Rohan-Chaudhury/aimet
|
Concat
| false
| 17,995
|
[
"BSD-3-Clause"
] | 3
|
1c38cac8cc0fd32dca40ce5e39940805d29f7a4a
|
https://github.com/Rohan-Chaudhury/aimet/tree/1c38cac8cc0fd32dca40ce5e39940805d29f7a4a
|
BasicBlock
|
import torch
import torch.nn.functional as F
from torch import nn
class BasicBlock(nn.Module):
def __init__(self, input_dim, width, block_depth):
super(BasicBlock, self).__init__()
self.block_depth = block_depth
self.conv1 = nn.Conv2d(input_dim, width, kernel_size=3, padding=1)
if block_depth > 1:
self.conv2 = nn.Conv2d(width, width, kernel_size=3, padding=1)
if block_depth > 2:
self.conv3 = nn.Conv2d(width, width, kernel_size=3, padding=1)
if block_depth > 3:
self.conv4 = nn.Conv2d(width, width, kernel_size=3, padding=1)
if block_depth > 4:
raise BaseException('block_depth > 4 is not implemented.')
def forward(self, x):
out = F.relu(self.conv1(x))
out1 = out
if self.block_depth > 1:
out = F.relu(self.conv2(out))
if self.block_depth > 2:
out = F.relu(self.conv3(out))
if self.block_depth > 3:
out = F.relu(self.conv4(out))
return out + out1
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'input_dim': 4, 'width': 4, 'block_depth': 1}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_add_convolution_relu_threshold_backward_0(in_ptr0,
in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = tmp4 + tmp4
tmp6 = 0.0
tmp7 = tmp4 <= tmp6
tl.store(out_ptr0 + x3, tmp5, xmask)
tl.store(out_ptr1 + x3, tmp7, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1))
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
get_raw_stream(0)
triton_poi_fused_add_convolution_relu_threshold_backward_0[grid(256)](
buf0, primals_2, buf1, buf2, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del buf0
del primals_2
return buf1, primals_1, primals_3, buf2
class BasicBlockNew(nn.Module):
def __init__(self, input_dim, width, block_depth):
super(BasicBlockNew, self).__init__()
self.block_depth = block_depth
self.conv1 = nn.Conv2d(input_dim, width, kernel_size=3, padding=1)
if block_depth > 1:
self.conv2 = nn.Conv2d(width, width, kernel_size=3, padding=1)
if block_depth > 2:
self.conv3 = nn.Conv2d(width, width, kernel_size=3, padding=1)
if block_depth > 3:
self.conv4 = nn.Conv2d(width, width, kernel_size=3, padding=1)
if block_depth > 4:
raise BaseException('block_depth > 4 is not implemented.')
def forward(self, input_0):
primals_1 = self.conv1.weight
primals_2 = self.conv1.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
TomHeaven/Pixel-wise-Estimation-of-Signal-Dependent-Image-Noise-using-Deep-Residual-Learning
|
BasicBlock
| false
| 17,996
|
[
"MIT"
] | 10
|
7f2a57312f7cec76e5d7016825f75ee9bbd170f5
|
https://github.com/TomHeaven/Pixel-wise-Estimation-of-Signal-Dependent-Image-Noise-using-Deep-Residual-Learning/tree/7f2a57312f7cec76e5d7016825f75ee9bbd170f5
|
KLDivLoss
|
import torch
class KLDivLoss(torch.nn.KLDivLoss):
def __init__(self, reduction='none'):
super().__init__(reduction=reduction)
def forward(self, preds, targets):
"""
Applies ``log_softmax`` to ``pred`` and ``softmax`` to ``targets``
prior to computing KL-Divergence loss. These operations are performed
due to the requirements of the PyTorch API for KLDivLoss.
"""
preds_ = torch.nn.functional.log_softmax(preds, dim=1)
targets_ = torch.nn.functional.softmax(targets, dim=1)
return super(KLDivLoss, self).forward(preds_, targets_)
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
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 = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x3, tmp9, xmask)
@triton.jit
def triton_poi_fused__log_softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tl.store(out_ptr0 + x3, tmp8, xmask)
@triton.jit
def triton_poi_fused__log_softmax__softmax_mul_sub_xlogy_2(in_out_ptr0,
in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp17 = tl.load(in_ptr1 + x3, xmask)
tmp18 = tl.load(in_ptr1 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp20 = tl.load(in_ptr1 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp23 = tl.load(in_ptr1 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp26 = tl.load(in_ptr1 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tmp9 = libdevice.isnan(tmp8).to(tl.int1)
tmp10 = 0.0
tmp11 = tmp8 == tmp10
tmp12 = tl_math.log(tmp8)
tmp13 = tmp8 * tmp12
tmp14 = tl.where(tmp11, tmp10, tmp13)
tmp15 = float('nan')
tmp16 = tl.where(tmp9, tmp15, tmp14)
tmp19 = tl_math.exp(tmp18)
tmp21 = tl_math.exp(tmp20)
tmp22 = tmp19 + tmp21
tmp24 = tl_math.exp(tmp23)
tmp25 = tmp22 + tmp24
tmp27 = tl_math.exp(tmp26)
tmp28 = tmp25 + tmp27
tmp29 = tl_math.log(tmp28)
tmp30 = tmp17 - tmp29
tmp31 = tmp8 * tmp30
tmp32 = tmp16 - tmp31
tl.store(in_out_ptr0 + x3, tmp32, 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__softmax_0[grid(256)](arg1_1, buf0, 256, XBLOCK=
128, num_warps=4, num_stages=1)
del arg1_1
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__log_softmax_1[grid(256)](arg0_1, buf2, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del arg0_1
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf3 = buf1
del buf1
triton_poi_fused__log_softmax__softmax_mul_sub_xlogy_2[grid(256)](buf3,
buf0, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1)
del buf0
del buf2
return buf3,
class KLDivLossNew(torch.nn.KLDivLoss):
def __init__(self, reduction='none'):
super().__init__(reduction=reduction)
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
Thesys-lab/learned-coded-computation
|
KLDivLoss
| false
| 17,997
|
[
"Apache-2.0"
] | 8
|
c5c32bcfb7cc4a9f52079f648373e6972c19eff9
|
https://github.com/Thesys-lab/learned-coded-computation/tree/c5c32bcfb7cc4a9f52079f648373e6972c19eff9
|
CharbonnierLoss
|
import torch
import torch.utils.data
import torch.nn as nn
class CharbonnierLoss(nn.Module):
"""Charbonnier Loss (L1)"""
def __init__(self, eps=1e-06):
super(CharbonnierLoss, self).__init__()
self.eps = eps
def forward(self, x, y):
diff = x - y
loss = torch.sum(torch.sqrt(diff * diff + self.eps))
return loss
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
import torch.utils.data
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_add_mul_sqrt_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 = tmp2 * tmp2
tmp4 = 1e-06
tmp5 = tmp3 + tmp4
tmp6 = libdevice.sqrt(tmp5)
tmp7 = tl.broadcast_to(tmp6, [RBLOCK])
tmp9 = triton_helpers.promote_to_tensor(tl.sum(tmp7, 0))
tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp9, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((), (), torch.float32)
get_raw_stream(0)
triton_per_fused_add_mul_sqrt_sub_sum_0[grid(1)](arg0_1, arg1_1,
buf0, 1, 256, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
return buf0,
class CharbonnierLossNew(nn.Module):
"""Charbonnier Loss (L1)"""
def __init__(self, eps=1e-06):
super(CharbonnierLossNew, self).__init__()
self.eps = eps
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
TevenLeScao/BasicSR
|
CharbonnierLoss
| false
| 17,998
|
[
"Apache-2.0"
] | 4
|
1a7bd8754de00f3a9c9f2031acfc447350459ea0
|
https://github.com/TevenLeScao/BasicSR/tree/1a7bd8754de00f3a9c9f2031acfc447350459ea0
|
ResNetV2
|
import torch
import torch.nn.functional as F
from collections import OrderedDict
import torch.nn as nn
def conv1x1(cin, cout, stride=1, bias=False):
return StdConv2d(cin, cout, kernel_size=1, stride=stride, padding=0,
bias=bias)
def conv3x3(cin, cout, stride=1, groups=1, bias=False):
return StdConv2d(cin, cout, kernel_size=3, stride=stride, padding=1,
bias=bias, groups=groups)
def np2th(weights, conv=False):
"""Possibly convert HWIO to OIHW."""
if conv:
weights = weights.transpose([3, 2, 0, 1])
return torch.from_numpy(weights)
class StdConv2d(nn.Conv2d):
def forward(self, x):
w = self.weight
v, m = torch.var_mean(w, dim=[1, 2, 3], keepdim=True, unbiased=False)
w = (w - m) / torch.sqrt(v + 1e-05)
return F.conv2d(x, w, self.bias, self.stride, self.padding, self.
dilation, self.groups)
class PreActBottleneck(nn.Module):
"""Pre-activation (v2) bottleneck block.
"""
def __init__(self, cin, cout=None, cmid=None, stride=1):
super().__init__()
cout = cout or cin
cmid = cmid or cout // 4
self.gn1 = nn.GroupNorm(32, cmid, eps=1e-06)
self.conv1 = conv1x1(cin, cmid, bias=False)
self.gn2 = nn.GroupNorm(32, cmid, eps=1e-06)
self.conv2 = conv3x3(cmid, cmid, stride, bias=False)
self.gn3 = nn.GroupNorm(32, cout, eps=1e-06)
self.conv3 = conv1x1(cmid, cout, bias=False)
self.relu = nn.ReLU(inplace=True)
if stride != 1 or cin != cout:
self.downsample = conv1x1(cin, cout, stride, bias=False)
self.gn_proj = nn.GroupNorm(cout, cout)
def forward(self, x):
residual = x
if hasattr(self, 'downsample'):
residual = self.downsample(x)
residual = self.gn_proj(residual)
y = self.relu(self.gn1(self.conv1(x)))
y = self.relu(self.gn2(self.conv2(y)))
y = self.gn3(self.conv3(y))
y = self.relu(residual + y)
return y
def load_from(self, weights, n_block, n_unit):
conv1_weight = np2th(weights[n_block + '/' + n_unit + '/' +
'conv1/kernel'], conv=True)
conv2_weight = np2th(weights[n_block + '/' + n_unit + '/' +
'conv2/kernel'], conv=True)
conv3_weight = np2th(weights[n_block + '/' + n_unit + '/' +
'conv3/kernel'], conv=True)
gn1_weight = np2th(weights[n_block + '/' + n_unit + '/' + 'gn1/scale'])
gn1_bias = np2th(weights[n_block + '/' + n_unit + '/' + 'gn1/bias'])
gn2_weight = np2th(weights[n_block + '/' + n_unit + '/' + 'gn2/scale'])
gn2_bias = np2th(weights[n_block + '/' + n_unit + '/' + 'gn2/bias'])
gn3_weight = np2th(weights[n_block + '/' + n_unit + '/' + 'gn3/scale'])
gn3_bias = np2th(weights[n_block + '/' + n_unit + '/' + 'gn3/bias'])
self.conv1.weight.copy_(conv1_weight)
self.conv2.weight.copy_(conv2_weight)
self.conv3.weight.copy_(conv3_weight)
self.gn1.weight.copy_(gn1_weight.view(-1))
self.gn1.bias.copy_(gn1_bias.view(-1))
self.gn2.weight.copy_(gn2_weight.view(-1))
self.gn2.bias.copy_(gn2_bias.view(-1))
self.gn3.weight.copy_(gn3_weight.view(-1))
self.gn3.bias.copy_(gn3_bias.view(-1))
if hasattr(self, 'downsample'):
proj_conv_weight = np2th(weights[n_block + '/' + n_unit + '/' +
'conv_proj/kernel'], conv=True)
proj_gn_weight = np2th(weights[n_block + '/' + n_unit + '/' +
'gn_proj/scale'])
proj_gn_bias = np2th(weights[n_block + '/' + n_unit + '/' +
'gn_proj/bias'])
self.downsample.weight.copy_(proj_conv_weight)
self.gn_proj.weight.copy_(proj_gn_weight.view(-1))
self.gn_proj.bias.copy_(proj_gn_bias.view(-1))
class ResNetV2(nn.Module):
"""Implementation of Pre-activation (v2) ResNet mode."""
def __init__(self, block_units, width_factor):
super().__init__()
width = int(64 * width_factor)
self.width = width
self.root = nn.Sequential(OrderedDict([('conv', StdConv2d(3, width,
kernel_size=7, stride=2, bias=False, padding=3)), ('gn', nn.
GroupNorm(32, width, eps=1e-06)), ('relu', nn.ReLU(inplace=True
)), ('pool', nn.MaxPool2d(kernel_size=3, stride=2, padding=0))]))
self.body = nn.Sequential(OrderedDict([('block1', nn.Sequential(
OrderedDict([('unit1', PreActBottleneck(cin=width, cout=width *
4, cmid=width))] + [(f'unit{i:d}', PreActBottleneck(cin=width *
4, cout=width * 4, cmid=width)) for i in range(2, block_units[0
] + 1)]))), ('block2', nn.Sequential(OrderedDict([('unit1',
PreActBottleneck(cin=width * 4, cout=width * 8, cmid=width * 2,
stride=2))] + [(f'unit{i:d}', PreActBottleneck(cin=width * 8,
cout=width * 8, cmid=width * 2)) for i in range(2, block_units[
1] + 1)]))), ('block3', nn.Sequential(OrderedDict([('unit1',
PreActBottleneck(cin=width * 8, cout=width * 16, cmid=width * 4,
stride=2))] + [(f'unit{i:d}', PreActBottleneck(cin=width * 16,
cout=width * 16, cmid=width * 4)) for i in range(2, block_units
[2] + 1)])))]))
def forward(self, x):
x = self.root(x)
x = self.body(x)
return x
def get_inputs():
return [torch.rand([4, 3, 64, 64])]
def get_init_inputs():
return [[], {'block_units': [4, 4, 4], 'width_factor': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn.functional as F
from collections import OrderedDict
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 768
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
y3 = yindex
y0 = yindex % 3
y1 = yindex // 3
tmp0 = tl.load(in_ptr0 + (x2 + 49 * y3), xmask & ymask, eviction_policy
='evict_last')
tl.store(out_ptr0 + (y0 + 3 * x2 + 147 * y1), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 12
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
x2 = xindex
y3 = yindex
y0 = yindex % 3
y1 = yindex // 3
tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (y0 + 3 * x2 + 12288 * y1), tmp0, ymask)
@triton.jit
def triton_poi_fused_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
xnumel = 9
yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1)
) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 256
y1 = yindex // 256
tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last'
)
tl.store(out_ptr0 + (y0 + 256 * x2 + 2304 * y1), tmp0, xmask)
@triton.jit
def triton_poi_fused_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
xnumel = 9
yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1)
) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 512
y1 = yindex // 512
tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last'
)
tl.store(out_ptr0 + (y0 + 512 * x2 + 4608 * y1), tmp0, xmask)
@triton.jit
def triton_poi_fused_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
xnumel = 9
yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1)
) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 1024
y1 = yindex // 1024
tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last'
)
tl.store(out_ptr0 + (y0 + 1024 * x2 + 9216 * y1), tmp0, xmask)
@triton.jit
def triton_per_fused_add_div_sqrt_sub_var_mean_5(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 256
rnumel = 147
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
rmask = rindex < rnumel
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 147 * x0), rmask & xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tl.where(rmask & xmask, tmp1, 0)
tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp6 = tl.where(rmask & xmask, tmp4, 0)
tmp7 = tl.sum(tmp6, 1)[:, None]
tmp8 = tl.full([XBLOCK, 1], 147, tl.int32)
tmp9 = tmp8.to(tl.float32)
tmp10 = tmp7 / tmp9
tmp11 = tmp1 - tmp10
tmp12 = tmp11 * tmp11
tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK])
tmp15 = tl.where(rmask & xmask, tmp13, 0)
tmp16 = tl.sum(tmp15, 1)[:, None]
tmp17 = 147.0
tmp18 = tmp16 / tmp17
tmp19 = 1e-05
tmp20 = tmp18 + tmp19
tmp21 = libdevice.sqrt(tmp20)
tmp22 = tmp0 - tmp10
tmp23 = tmp22 / tmp21
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp21, xmask)
tl.store(out_ptr1 + (r1 + 147 * x0), tmp23, rmask & xmask)
@triton.jit
def triton_red_fused_native_group_norm_6(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 128
rnumel = 8192
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex % 32
x1 = xindex // 32
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
x4 = xindex
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex % 8
r3 = rindex // 8
tmp0 = tl.load(in_ptr0 + (r2 + 8 * x0 + 256 * r3 + 262144 * x1),
rmask & xmask, eviction_policy='evict_first', other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers.
welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0)
)
tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean)
tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2)
tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight)
tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean,
tmp2_m2, tmp2_weight, 1)
tmp2 = tmp2_tmp[:, None]
tmp3 = tmp3_tmp[:, None]
tmp4_tmp[:, None]
tl.store(out_ptr0 + x4, tmp2, xmask)
tl.store(out_ptr1 + x4, tmp3, xmask)
tmp5 = 8192.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-06
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_native_group_norm_relu_7(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x0 = xindex % 256
x2 = xindex // 262144
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 8), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 8), None, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 8192.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-06
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp14 = tl.full([1], 0, tl.int32)
tmp15 = triton_helpers.maximum(tmp14, tmp13)
tl.store(out_ptr0 + x3, tmp15, None)
@triton.jit
def triton_poi_fused_max_pool2d_with_indices_8(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 230400
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 256
x1 = xindex // 256 % 15
x2 = xindex // 3840 % 15
x3 = xindex // 57600
x4 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 512 * x1 + 16384 * x2 + 262144 * x3), xmask)
tmp1 = tl.load(in_ptr0 + (256 + x0 + 512 * x1 + 16384 * x2 + 262144 *
x3), xmask)
tmp3 = tl.load(in_ptr0 + (512 + x0 + 512 * x1 + 16384 * x2 + 262144 *
x3), xmask)
tmp5 = tl.load(in_ptr0 + (8192 + x0 + 512 * x1 + 16384 * x2 + 262144 *
x3), xmask)
tmp7 = tl.load(in_ptr0 + (8448 + x0 + 512 * x1 + 16384 * x2 + 262144 *
x3), xmask)
tmp9 = tl.load(in_ptr0 + (8704 + x0 + 512 * x1 + 16384 * x2 + 262144 *
x3), xmask)
tmp11 = tl.load(in_ptr0 + (16384 + x0 + 512 * x1 + 16384 * x2 + 262144 *
x3), xmask)
tmp13 = tl.load(in_ptr0 + (16640 + x0 + 512 * x1 + 16384 * x2 + 262144 *
x3), xmask)
tmp15 = tl.load(in_ptr0 + (16896 + x0 + 512 * x1 + 16384 * x2 + 262144 *
x3), xmask)
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = triton_helpers.maximum(tmp5, tmp4)
tmp8 = triton_helpers.maximum(tmp7, tmp6)
tmp10 = triton_helpers.maximum(tmp9, tmp8)
tmp12 = triton_helpers.maximum(tmp11, tmp10)
tmp14 = triton_helpers.maximum(tmp13, tmp12)
tmp16 = triton_helpers.maximum(tmp15, tmp14)
tmp17 = tmp1 > tmp0
tmp18 = tl.full([1], 1, tl.int8)
tmp19 = tl.full([1], 0, tl.int8)
tmp20 = tl.where(tmp17, tmp18, tmp19)
tmp21 = tmp3 > tmp2
tmp22 = tl.full([1], 2, tl.int8)
tmp23 = tl.where(tmp21, tmp22, tmp20)
tmp24 = tmp5 > tmp4
tmp25 = tl.full([1], 3, tl.int8)
tmp26 = tl.where(tmp24, tmp25, tmp23)
tmp27 = tmp7 > tmp6
tmp28 = tl.full([1], 4, tl.int8)
tmp29 = tl.where(tmp27, tmp28, tmp26)
tmp30 = tmp9 > tmp8
tmp31 = tl.full([1], 5, tl.int8)
tmp32 = tl.where(tmp30, tmp31, tmp29)
tmp33 = tmp11 > tmp10
tmp34 = tl.full([1], 6, tl.int8)
tmp35 = tl.where(tmp33, tmp34, tmp32)
tmp36 = tmp13 > tmp12
tmp37 = tl.full([1], 7, tl.int8)
tmp38 = tl.where(tmp36, tmp37, tmp35)
tmp39 = tmp15 > tmp14
tmp40 = tl.full([1], 8, tl.int8)
tmp41 = tl.where(tmp39, tmp40, tmp38)
tl.store(out_ptr0 + x4, tmp16, xmask)
tl.store(out_ptr1 + x4, tmp41, xmask)
@triton.jit
def triton_per_fused_add_div_sqrt_sub_var_mean_9(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 256 * x0), None)
tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
tmp3 = tl.broadcast_to(tmp1, [RBLOCK])
tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0))
tmp6 = tl.full([1], 256, tl.int32)
tmp7 = tmp6.to(tl.float32)
tmp8 = tmp5 / tmp7
tmp9 = tmp1 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tl.broadcast_to(tmp10, [RBLOCK])
tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0))
tmp14 = 256.0
tmp15 = tmp13 / tmp14
tmp16 = 1e-05
tmp17 = tmp15 + tmp16
tmp18 = libdevice.sqrt(tmp17)
tmp19 = tmp0 - tmp8
tmp20 = tmp19 / tmp18
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp18, None)
tl.store(out_ptr1 + (r1 + 256 * x0), tmp20, None)
@triton.jit
def triton_per_fused_native_group_norm_10(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr):
rnumel = 225
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
rmask = rindex < rnumel
r2 = rindex
x0 = xindex % 1024
x1 = xindex // 1024
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 1024 * r2 + 230400 * x1), rmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tl.where(rmask, tmp1, 0)
tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp6 = tl.where(rmask, tmp4, 0)
tmp7 = tl.sum(tmp6, 1)[:, None]
tmp8 = tl.full([XBLOCK, 1], 225, tl.int32)
tmp9 = tmp8.to(tl.float32)
tmp10 = tmp7 / tmp9
tmp11 = tmp1 - tmp10
tmp12 = tmp11 * tmp11
tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK])
tmp15 = tl.where(rmask, tmp13, 0)
tmp16 = tl.sum(tmp15, 1)[:, None]
tmp17 = 225.0
tmp18 = tmp16 / tmp17
tmp19 = 1e-05
tmp20 = tmp18 + tmp19
tmp21 = libdevice.rsqrt(tmp20)
tl.store(out_ptr2 + x3, tmp21, None)
tl.store(out_ptr0 + x3, tmp10, None)
tl.store(out_ptr1 + x3, tmp16, None)
@triton.jit
def triton_per_fused_add_div_sqrt_sub_var_mean_11(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 256 * x0), None)
tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
tmp3 = tl.broadcast_to(tmp1, [RBLOCK])
tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0))
tmp6 = tl.full([1], 256, tl.int32)
tmp7 = tmp6.to(tl.float32)
tmp8 = tmp5 / tmp7
tmp9 = tmp1 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tl.broadcast_to(tmp10, [RBLOCK])
tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0))
tmp14 = 256.0
tmp15 = tmp13 / tmp14
tmp16 = 1e-05
tmp17 = tmp15 + tmp16
tmp18 = libdevice.sqrt(tmp17)
tmp19 = tmp0 - tmp8
tmp20 = tmp19 / tmp18
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp18, None)
tl.store(out_ptr1 + (r1 + 256 * x0), tmp20, None)
@triton.jit
def triton_red_fused_native_group_norm_12(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 128
rnumel = 1800
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex % 32
x1 = xindex // 32
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
x4 = xindex
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex % 8
r3 = rindex // 8
tmp0 = tl.load(in_ptr0 + (r2 + 8 * x0 + 256 * r3 + 57600 * x1),
rmask & xmask, eviction_policy='evict_first', other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers.
welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0)
)
tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean)
tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2)
tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight)
tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean,
tmp2_m2, tmp2_weight, 1)
tmp2 = tmp2_tmp[:, None]
tmp3 = tmp3_tmp[:, None]
tmp4_tmp[:, None]
tl.store(out_ptr0 + x4, tmp2, xmask)
tl.store(out_ptr1 + x4, tmp3, xmask)
tmp5 = 1800.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-06
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_native_group_norm_relu_13(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 230400
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 256
x2 = xindex // 57600
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 8), xmask, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 8), xmask, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 1800.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-06
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp14 = tl.full([1], 0, tl.int32)
tmp15 = triton_helpers.maximum(tmp14, tmp13)
tl.store(out_ptr0 + x3, tmp15, xmask)
@triton.jit
def triton_red_fused_add_div_sqrt_sub_var_mean_14(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 256
rnumel = 2304
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp0 = tl.load(in_ptr0 + (r1 + 2304 * x0), rmask & xmask,
eviction_policy='evict_last', other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers.
welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0)
)
tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean)
tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2)
tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight)
tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean,
tmp2_m2, tmp2_weight, 1)
tmp2 = tmp2_tmp[:, None]
tmp3 = tmp3_tmp[:, None]
tmp4_tmp[:, None]
tmp5 = 2304.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-05
tmp8 = tmp6 + tmp7
tmp9 = libdevice.sqrt(tmp8)
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp9, xmask)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp10 = tl.load(in_ptr0 + (r1 + 2304 * x0), rmask & xmask,
eviction_policy='evict_first', other=0.0)
tmp11 = tmp10 - tmp2
tmp12 = tmp11 / tmp9
tl.store(out_ptr1 + (r1 + 2304 * x0), tmp12, rmask & xmask)
@triton.jit
def triton_red_fused_native_group_norm_15(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 128
rnumel = 7200
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex % 32
x1 = xindex // 32
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
x4 = xindex
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex % 32
r3 = rindex // 32
tmp0 = tl.load(in_ptr0 + (r2 + 32 * x0 + 1024 * r3 + 230400 * x1),
rmask & xmask, eviction_policy='evict_first', other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers.
welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0)
)
tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean)
tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2)
tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight)
tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean,
tmp2_m2, tmp2_weight, 1)
tmp2 = tmp2_tmp[:, None]
tmp3 = tmp3_tmp[:, None]
tmp4_tmp[:, None]
tl.store(out_ptr0 + x4, tmp2, xmask)
tl.store(out_ptr1 + x4, tmp3, xmask)
tmp5 = 7200.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-06
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_add_native_group_norm_relu_16(in_out_ptr0, in_ptr0,
in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8,
in_ptr9, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x0 = xindex % 1024
x2 = xindex // 230400
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (x0 + 1024 * x2), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (x0 + 1024 * x2), None, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp14 = tl.load(in_ptr5 + x3, None)
tmp15 = tl.load(in_ptr6 + (32 * x2 + x0 // 32), None, eviction_policy=
'evict_last')
tmp17 = tl.load(in_ptr7 + (32 * x2 + x0 // 32), None, eviction_policy=
'evict_last')
tmp24 = tl.load(in_ptr8 + x0, None, eviction_policy='evict_last')
tmp26 = tl.load(in_ptr9 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 225.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-05
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp16 = tmp14 - tmp15
tmp18 = 7200.0
tmp19 = tmp17 / tmp18
tmp20 = 1e-06
tmp21 = tmp19 + tmp20
tmp22 = libdevice.rsqrt(tmp21)
tmp23 = tmp16 * tmp22
tmp25 = tmp23 * tmp24
tmp27 = tmp25 + tmp26
tmp28 = tmp13 + tmp27
tmp29 = tl.full([1], 0, tl.int32)
tmp30 = triton_helpers.maximum(tmp29, tmp28)
tl.store(in_out_ptr0 + x3, tmp30, None)
@triton.jit
def triton_per_fused_add_div_sqrt_sub_var_mean_17(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 1024 * x0), None)
tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
tmp3 = tl.broadcast_to(tmp1, [RBLOCK])
tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0))
tmp6 = tl.full([1], 1024, tl.int32)
tmp7 = tmp6.to(tl.float32)
tmp8 = tmp5 / tmp7
tmp9 = tmp1 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tl.broadcast_to(tmp10, [RBLOCK])
tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0))
tmp14 = 1024.0
tmp15 = tmp13 / tmp14
tmp16 = 1e-05
tmp17 = tmp15 + tmp16
tmp18 = libdevice.sqrt(tmp17)
tmp19 = tmp0 - tmp8
tmp20 = tmp19 / tmp18
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp18, None)
tl.store(out_ptr1 + (r1 + 1024 * x0), tmp20, None)
@triton.jit
def triton_poi_fused_add_native_group_norm_relu_18(in_ptr0, in_ptr1,
in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x0 = xindex % 1024
x2 = xindex // 230400
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + x3, None)
tmp2 = tl.load(in_ptr2 + (32 * x2 + x0 // 32), None, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr3 + (32 * x2 + x0 // 32), None, eviction_policy=
'evict_last')
tmp11 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp13 = tl.load(in_ptr5 + x0, None, eviction_policy='evict_last')
tmp3 = tmp1 - tmp2
tmp5 = 7200.0
tmp6 = tmp4 / tmp5
tmp7 = 1e-06
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tmp10 = tmp3 * tmp9
tmp12 = tmp10 * tmp11
tmp14 = tmp12 + tmp13
tmp15 = tmp0 + tmp14
tmp16 = tl.full([1], 0, tl.int32)
tmp17 = triton_helpers.maximum(tmp16, tmp15)
tl.store(out_ptr0 + x3, tmp17, None)
@triton.jit
def triton_per_fused_add_div_sqrt_sub_var_mean_19(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 1024 * x0), None)
tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
tmp3 = tl.broadcast_to(tmp1, [RBLOCK])
tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0))
tmp6 = tl.full([1], 1024, tl.int32)
tmp7 = tmp6.to(tl.float32)
tmp8 = tmp5 / tmp7
tmp9 = tmp1 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tl.broadcast_to(tmp10, [RBLOCK])
tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0))
tmp14 = 1024.0
tmp15 = tmp13 / tmp14
tmp16 = 1e-05
tmp17 = tmp15 + tmp16
tmp18 = libdevice.sqrt(tmp17)
tmp19 = tmp0 - tmp8
tmp20 = tmp19 / tmp18
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp18, None)
tl.store(out_ptr1 + (r1 + 1024 * x0), tmp20, None)
@triton.jit
def triton_per_fused_native_group_norm_20(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr):
RBLOCK: tl.constexpr = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r2 = rindex
x0 = xindex % 2048
x1 = xindex // 2048
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 2048 * r2 + 131072 * x1), None)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp5 = tl.sum(tmp3, 1)[:, None]
tmp6 = tl.full([XBLOCK, 1], 64, tl.int32)
tmp7 = tmp6.to(tl.float32)
tmp8 = tmp5 / tmp7
tmp9 = tmp1 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK])
tmp13 = tl.sum(tmp11, 1)[:, None]
tmp14 = 64.0
tmp15 = tmp13 / tmp14
tmp16 = 1e-05
tmp17 = tmp15 + tmp16
tmp18 = libdevice.rsqrt(tmp17)
tl.store(out_ptr2 + x3, tmp18, None)
tl.store(out_ptr0 + x3, tmp8, None)
tl.store(out_ptr1 + x3, tmp13, None)
@triton.jit
def triton_per_fused_add_div_sqrt_sub_var_mean_21(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 1024 * x0), None)
tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
tmp3 = tl.broadcast_to(tmp1, [RBLOCK])
tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0))
tmp6 = tl.full([1], 1024, tl.int32)
tmp7 = tmp6.to(tl.float32)
tmp8 = tmp5 / tmp7
tmp9 = tmp1 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tl.broadcast_to(tmp10, [RBLOCK])
tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0))
tmp14 = 1024.0
tmp15 = tmp13 / tmp14
tmp16 = 1e-05
tmp17 = tmp15 + tmp16
tmp18 = libdevice.sqrt(tmp17)
tmp19 = tmp0 - tmp8
tmp20 = tmp19 / tmp18
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp18, None)
tl.store(out_ptr1 + (r1 + 1024 * x0), tmp20, None)
@triton.jit
def triton_red_fused_native_group_norm_22(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 128
rnumel = 3600
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex % 32
x1 = xindex // 32
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
x4 = xindex
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex % 16
r3 = rindex // 16
tmp0 = tl.load(in_ptr0 + (r2 + 16 * x0 + 512 * r3 + 115200 * x1),
rmask & xmask, eviction_policy='evict_first', other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers.
welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0)
)
tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean)
tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2)
tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight)
tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean,
tmp2_m2, tmp2_weight, 1)
tmp2 = tmp2_tmp[:, None]
tmp3 = tmp3_tmp[:, None]
tmp4_tmp[:, None]
tl.store(out_ptr0 + x4, tmp2, xmask)
tl.store(out_ptr1 + x4, tmp3, xmask)
tmp5 = 3600.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-06
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_native_group_norm_relu_23(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x0 = xindex % 512
x2 = xindex // 115200
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 16), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 16), None, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 3600.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-06
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp14 = tl.full([1], 0, tl.int32)
tmp15 = triton_helpers.maximum(tmp14, tmp13)
tl.store(out_ptr0 + x3, tmp15, None)
@triton.jit
def triton_red_fused_add_div_sqrt_sub_var_mean_24(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 512
rnumel = 4608
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp0 = tl.load(in_ptr0 + (r1 + 4608 * x0), rmask & xmask,
eviction_policy='evict_last', other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers.
welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0)
)
tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean)
tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2)
tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight)
tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean,
tmp2_m2, tmp2_weight, 1)
tmp2 = tmp2_tmp[:, None]
tmp3 = tmp3_tmp[:, None]
tmp4_tmp[:, None]
tmp5 = 4608.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-05
tmp8 = tmp6 + tmp7
tmp9 = libdevice.sqrt(tmp8)
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp9, xmask)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp10 = tl.load(in_ptr0 + (r1 + 4608 * x0), rmask & xmask,
eviction_policy='evict_first', other=0.0)
tmp11 = tmp10 - tmp2
tmp12 = tmp11 / tmp9
tl.store(out_ptr1 + (r1 + 4608 * x0), tmp12, rmask & xmask)
@triton.jit
def triton_per_fused_native_group_norm_25(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r2 = rindex % 16
r3 = rindex // 16
x0 = xindex % 32
x1 = xindex // 32
x4 = xindex
tmp0 = tl.load(in_ptr0 + (r2 + 16 * x0 + 512 * r3 + 32768 * x1), None)
tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
tmp3 = tl.broadcast_to(tmp1, [RBLOCK])
tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0))
tmp6 = tl.full([1], 1024, tl.int32)
tmp7 = tmp6.to(tl.float32)
tmp8 = tmp5 / tmp7
tmp9 = tmp1 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tl.broadcast_to(tmp10, [RBLOCK])
tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0))
tmp14 = 1024.0
tmp15 = tmp13 / tmp14
tmp16 = 1e-06
tmp17 = tmp15 + tmp16
tmp18 = libdevice.rsqrt(tmp17)
tl.store(out_ptr2 + x4, tmp18, None)
tl.store(out_ptr0 + x4, tmp8, None)
tl.store(out_ptr1 + x4, tmp13, None)
@triton.jit
def triton_poi_fused_native_group_norm_relu_26(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x0 = xindex % 512
x2 = xindex // 32768
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 16), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 16), None, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 1024.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-06
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp14 = tl.full([1], 0, tl.int32)
tmp15 = triton_helpers.maximum(tmp14, tmp13)
tl.store(out_ptr0 + x3, tmp15, None)
@triton.jit
def triton_per_fused_add_div_sqrt_sub_var_mean_27(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 512
xoffset = tl.program_id(0) * XBLOCK
xindex = tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 512 * x0), None)
tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
tmp3 = tl.broadcast_to(tmp1, [RBLOCK])
tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0))
tmp6 = tl.full([1], 512, tl.int32)
tmp7 = tmp6.to(tl.float32)
tmp8 = tmp5 / tmp7
tmp9 = tmp1 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tl.broadcast_to(tmp10, [RBLOCK])
tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0))
tmp14 = 512.0
tmp15 = tmp13 / tmp14
tmp16 = 1e-05
tmp17 = tmp15 + tmp16
tmp18 = libdevice.sqrt(tmp17)
tmp19 = tmp0 - tmp8
tmp20 = tmp19 / tmp18
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp18, None)
tl.store(out_ptr1 + (r1 + 512 * x0), tmp20, None)
@triton.jit
def triton_red_fused_native_group_norm_28(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 128
rnumel = 4096
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex % 32
x1 = xindex // 32
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
x4 = xindex
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex % 64
r3 = rindex // 64
tmp0 = tl.load(in_ptr0 + (r2 + 64 * x0 + 2048 * r3 + 131072 * x1),
rmask & xmask, eviction_policy='evict_first', other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers.
welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0)
)
tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean)
tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2)
tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight)
tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean,
tmp2_m2, tmp2_weight, 1)
tmp2 = tmp2_tmp[:, None]
tmp3 = tmp3_tmp[:, None]
tmp4_tmp[:, None]
tl.store(out_ptr0 + x4, tmp2, xmask)
tl.store(out_ptr1 + x4, tmp3, xmask)
tmp5 = 4096.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-06
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_add_native_group_norm_relu_29(in_out_ptr0, in_ptr0,
in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8,
in_ptr9, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x0 = xindex % 2048
x2 = xindex // 131072
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (x0 + 2048 * x2), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (x0 + 2048 * x2), None, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp14 = tl.load(in_ptr5 + x3, None)
tmp15 = tl.load(in_ptr6 + (32 * x2 + x0 // 64), None, eviction_policy=
'evict_last')
tmp17 = tl.load(in_ptr7 + (32 * x2 + x0 // 64), None, eviction_policy=
'evict_last')
tmp24 = tl.load(in_ptr8 + x0, None, eviction_policy='evict_last')
tmp26 = tl.load(in_ptr9 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 64.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-05
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp16 = tmp14 - tmp15
tmp18 = 4096.0
tmp19 = tmp17 / tmp18
tmp20 = 1e-06
tmp21 = tmp19 + tmp20
tmp22 = libdevice.rsqrt(tmp21)
tmp23 = tmp16 * tmp22
tmp25 = tmp23 * tmp24
tmp27 = tmp25 + tmp26
tmp28 = tmp13 + tmp27
tmp29 = tl.full([1], 0, tl.int32)
tmp30 = triton_helpers.maximum(tmp29, tmp28)
tl.store(in_out_ptr0 + x3, tmp30, None)
@triton.jit
def triton_red_fused_add_div_sqrt_sub_var_mean_30(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 512
rnumel = 2048
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp0 = tl.load(in_ptr0 + (r1 + 2048 * x0), rmask & xmask,
eviction_policy='evict_last', other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers.
welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0)
)
tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean)
tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2)
tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight)
tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean,
tmp2_m2, tmp2_weight, 1)
tmp2 = tmp2_tmp[:, None]
tmp3 = tmp3_tmp[:, None]
tmp4_tmp[:, None]
tmp5 = 2048.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-05
tmp8 = tmp6 + tmp7
tmp9 = libdevice.sqrt(tmp8)
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp9, xmask)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp10 = tl.load(in_ptr0 + (r1 + 2048 * x0), rmask & xmask,
eviction_policy='evict_first', other=0.0)
tmp11 = tmp10 - tmp2
tmp12 = tmp11 / tmp9
tl.store(out_ptr1 + (r1 + 2048 * x0), tmp12, rmask & xmask)
@triton.jit
def triton_poi_fused_add_native_group_norm_relu_31(in_ptr0, in_ptr1,
in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x0 = xindex % 2048
x2 = xindex // 131072
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + x3, None)
tmp2 = tl.load(in_ptr2 + (32 * x2 + x0 // 64), None, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr3 + (32 * x2 + x0 // 64), None, eviction_policy=
'evict_last')
tmp11 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp13 = tl.load(in_ptr5 + x0, None, eviction_policy='evict_last')
tmp3 = tmp1 - tmp2
tmp5 = 4096.0
tmp6 = tmp4 / tmp5
tmp7 = 1e-06
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tmp10 = tmp3 * tmp9
tmp12 = tmp10 * tmp11
tmp14 = tmp12 + tmp13
tmp15 = tmp0 + tmp14
tmp16 = tl.full([1], 0, tl.int32)
tmp17 = triton_helpers.maximum(tmp16, tmp15)
tl.store(out_ptr0 + x3, tmp17, None)
@triton.jit
def triton_red_fused_add_div_sqrt_sub_var_mean_32(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
rnumel = 2048
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp0 = tl.load(in_ptr0 + (r1 + 2048 * x0), rmask, eviction_policy=
'evict_last', other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers.
welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0)
)
tmp2_mean = tl.where(rmask, tmp2_mean_next, tmp2_mean)
tmp2_m2 = tl.where(rmask, tmp2_m2_next, tmp2_m2)
tmp2_weight = tl.where(rmask, tmp2_weight_next, tmp2_weight)
tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean,
tmp2_m2, tmp2_weight, 1)
tmp2 = tmp2_tmp[:, None]
tmp3 = tmp3_tmp[:, None]
tmp4_tmp[:, None]
tmp5 = 2048.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-05
tmp8 = tmp6 + tmp7
tmp9 = libdevice.sqrt(tmp8)
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp9, None)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp10 = tl.load(in_ptr0 + (r1 + 2048 * x0), rmask, eviction_policy=
'evict_first', other=0.0)
tmp11 = tmp10 - tmp2
tmp12 = tmp11 / tmp9
tl.store(out_ptr1 + (r1 + 2048 * x0), tmp12, rmask)
@triton.jit
def triton_per_fused_native_group_norm_33(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr):
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r2 = rindex
x0 = xindex % 4096
x1 = xindex // 4096
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4096 * r2 + 65536 * x1), None)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp5 = tl.sum(tmp3, 1)[:, None]
tmp6 = tl.full([XBLOCK, 1], 16, tl.int32)
tmp7 = tmp6.to(tl.float32)
tmp8 = tmp5 / tmp7
tmp9 = tmp1 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK])
tmp13 = tl.sum(tmp11, 1)[:, None]
tmp14 = 16.0
tmp15 = tmp13 / tmp14
tmp16 = 1e-05
tmp17 = tmp15 + tmp16
tmp18 = libdevice.rsqrt(tmp17)
tl.store(out_ptr2 + x3, tmp18, None)
tl.store(out_ptr0 + x3, tmp8, None)
tl.store(out_ptr1 + x3, tmp13, None)
@triton.jit
def triton_red_fused_add_div_sqrt_sub_var_mean_34(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 1024
rnumel = 2048
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp0 = tl.load(in_ptr0 + (r1 + 2048 * x0), rmask & xmask,
eviction_policy='evict_last', other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers.
welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0)
)
tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean)
tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2)
tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight)
tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean,
tmp2_m2, tmp2_weight, 1)
tmp2 = tmp2_tmp[:, None]
tmp3 = tmp3_tmp[:, None]
tmp4_tmp[:, None]
tmp5 = 2048.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-05
tmp8 = tmp6 + tmp7
tmp9 = libdevice.sqrt(tmp8)
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp9, xmask)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp10 = tl.load(in_ptr0 + (r1 + 2048 * x0), rmask & xmask,
eviction_policy='evict_first', other=0.0)
tmp11 = tmp10 - tmp2
tmp12 = tmp11 / tmp9
tl.store(out_ptr1 + (r1 + 2048 * x0), tmp12, rmask & xmask)
@triton.jit
def triton_red_fused_native_group_norm_35(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 128
rnumel = 2048
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex % 32
x1 = xindex // 32
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
x4 = xindex
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex % 32
r3 = rindex // 32
tmp0 = tl.load(in_ptr0 + (r2 + 32 * x0 + 1024 * r3 + 65536 * x1),
rmask & xmask, eviction_policy='evict_first', other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers.
welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0)
)
tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean)
tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2)
tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight)
tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean,
tmp2_m2, tmp2_weight, 1)
tmp2 = tmp2_tmp[:, None]
tmp3 = tmp3_tmp[:, None]
tmp4_tmp[:, None]
tl.store(out_ptr0 + x4, tmp2, xmask)
tl.store(out_ptr1 + x4, tmp3, xmask)
tmp5 = 2048.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-06
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_native_group_norm_relu_36(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x0 = xindex % 1024
x2 = xindex // 65536
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 32), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 32), None, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 2048.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-06
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp14 = tl.full([1], 0, tl.int32)
tmp15 = triton_helpers.maximum(tmp14, tmp13)
tl.store(out_ptr0 + x3, tmp15, None)
@triton.jit
def triton_red_fused_add_div_sqrt_sub_var_mean_37(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 1024
rnumel = 9216
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp0 = tl.load(in_ptr0 + (r1 + 9216 * x0), rmask & xmask,
eviction_policy='evict_last', other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers.
welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0)
)
tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean)
tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2)
tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight)
tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean,
tmp2_m2, tmp2_weight, 1)
tmp2 = tmp2_tmp[:, None]
tmp3 = tmp3_tmp[:, None]
tmp4_tmp[:, None]
tmp5 = 9216.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-05
tmp8 = tmp6 + tmp7
tmp9 = libdevice.sqrt(tmp8)
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp9, xmask)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp10 = tl.load(in_ptr0 + (r1 + 9216 * x0), rmask & xmask,
eviction_policy='evict_first', other=0.0)
tmp11 = tmp10 - tmp2
tmp12 = tmp11 / tmp9
tl.store(out_ptr1 + (r1 + 9216 * x0), tmp12, rmask & xmask)
@triton.jit
def triton_per_fused_native_group_norm_38(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 512
xoffset = tl.program_id(0) * XBLOCK
xindex = tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r2 = rindex % 32
r3 = rindex // 32
x0 = xindex % 32
x1 = xindex // 32
x4 = xindex
tmp0 = tl.load(in_ptr0 + (r2 + 32 * x0 + 1024 * r3 + 16384 * x1), None)
tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
tmp3 = tl.broadcast_to(tmp1, [RBLOCK])
tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0))
tmp6 = tl.full([1], 512, tl.int32)
tmp7 = tmp6.to(tl.float32)
tmp8 = tmp5 / tmp7
tmp9 = tmp1 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tl.broadcast_to(tmp10, [RBLOCK])
tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0))
tmp14 = 512.0
tmp15 = tmp13 / tmp14
tmp16 = 1e-06
tmp17 = tmp15 + tmp16
tmp18 = libdevice.rsqrt(tmp17)
tl.store(out_ptr2 + x4, tmp18, None)
tl.store(out_ptr0 + x4, tmp8, None)
tl.store(out_ptr1 + x4, tmp13, None)
@triton.jit
def triton_poi_fused_native_group_norm_relu_39(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x0 = xindex % 1024
x2 = xindex // 16384
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 32), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 32), None, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 512.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-06
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp14 = tl.full([1], 0, tl.int32)
tmp15 = triton_helpers.maximum(tmp14, tmp13)
tl.store(out_ptr0 + x3, tmp15, None)
@triton.jit
def triton_per_fused_add_div_sqrt_sub_var_mean_40(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 1024 * x0), None)
tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
tmp3 = tl.broadcast_to(tmp1, [RBLOCK])
tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0))
tmp6 = tl.full([1], 1024, tl.int32)
tmp7 = tmp6.to(tl.float32)
tmp8 = tmp5 / tmp7
tmp9 = tmp1 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tl.broadcast_to(tmp10, [RBLOCK])
tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0))
tmp14 = 1024.0
tmp15 = tmp13 / tmp14
tmp16 = 1e-05
tmp17 = tmp15 + tmp16
tmp18 = libdevice.sqrt(tmp17)
tmp19 = tmp0 - tmp8
tmp20 = tmp19 / tmp18
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp18, None)
tl.store(out_ptr1 + (r1 + 1024 * x0), tmp20, None)
@triton.jit
def triton_red_fused_native_group_norm_41(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 128
rnumel = 2048
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex % 32
x1 = xindex // 32
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
x4 = xindex
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex % 128
r3 = rindex // 128
tmp0 = tl.load(in_ptr0 + (r2 + 128 * x0 + 4096 * r3 + 65536 * x1),
rmask & xmask, eviction_policy='evict_first', other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers.
welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0)
)
tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean)
tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2)
tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight)
tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean,
tmp2_m2, tmp2_weight, 1)
tmp2 = tmp2_tmp[:, None]
tmp3 = tmp3_tmp[:, None]
tmp4_tmp[:, None]
tl.store(out_ptr0 + x4, tmp2, xmask)
tl.store(out_ptr1 + x4, tmp3, xmask)
tmp5 = 2048.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-06
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_add_native_group_norm_relu_42(in_out_ptr0, in_ptr0,
in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8,
in_ptr9, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x0 = xindex % 4096
x2 = xindex // 65536
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (x0 + 4096 * x2), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (x0 + 4096 * x2), None, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp14 = tl.load(in_ptr5 + x3, None)
tmp15 = tl.load(in_ptr6 + (32 * x2 + x0 // 128), None, eviction_policy=
'evict_last')
tmp17 = tl.load(in_ptr7 + (32 * x2 + x0 // 128), None, eviction_policy=
'evict_last')
tmp24 = tl.load(in_ptr8 + x0, None, eviction_policy='evict_last')
tmp26 = tl.load(in_ptr9 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 16.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-05
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp16 = tmp14 - tmp15
tmp18 = 2048.0
tmp19 = tmp17 / tmp18
tmp20 = 1e-06
tmp21 = tmp19 + tmp20
tmp22 = libdevice.rsqrt(tmp21)
tmp23 = tmp16 * tmp22
tmp25 = tmp23 * tmp24
tmp27 = tmp25 + tmp26
tmp28 = tmp13 + tmp27
tmp29 = tl.full([1], 0, tl.int32)
tmp30 = triton_helpers.maximum(tmp29, tmp28)
tl.store(in_out_ptr0 + x3, tmp30, None)
@triton.jit
def triton_red_fused_add_div_sqrt_sub_var_mean_43(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 1024
rnumel = 4096
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp0 = tl.load(in_ptr0 + (r1 + 4096 * x0), rmask & xmask,
eviction_policy='evict_last', other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers.
welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0)
)
tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean)
tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2)
tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight)
tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean,
tmp2_m2, tmp2_weight, 1)
tmp2 = tmp2_tmp[:, None]
tmp3 = tmp3_tmp[:, None]
tmp4_tmp[:, None]
tmp5 = 4096.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-05
tmp8 = tmp6 + tmp7
tmp9 = libdevice.sqrt(tmp8)
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp9, xmask)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp10 = tl.load(in_ptr0 + (r1 + 4096 * x0), rmask & xmask,
eviction_policy='evict_first', other=0.0)
tmp11 = tmp10 - tmp2
tmp12 = tmp11 / tmp9
tl.store(out_ptr1 + (r1 + 4096 * x0), tmp12, rmask & xmask)
@triton.jit
def triton_poi_fused_add_native_group_norm_relu_44(in_ptr0, in_ptr1,
in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x0 = xindex % 4096
x2 = xindex // 65536
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + x3, None)
tmp2 = tl.load(in_ptr2 + (32 * x2 + x0 // 128), None, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr3 + (32 * x2 + x0 // 128), None, eviction_policy=
'evict_last')
tmp11 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp13 = tl.load(in_ptr5 + x0, None, eviction_policy='evict_last')
tmp3 = tmp1 - tmp2
tmp5 = 2048.0
tmp6 = tmp4 / tmp5
tmp7 = 1e-06
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tmp10 = tmp3 * tmp9
tmp12 = tmp10 * tmp11
tmp14 = tmp12 + tmp13
tmp15 = tmp0 + tmp14
tmp16 = tl.full([1], 0, tl.int32)
tmp17 = triton_helpers.maximum(tmp16, tmp15)
tl.store(out_ptr0 + x3, tmp17, None)
@triton.jit
def triton_poi_fused_add_native_group_norm_relu_45(in_ptr0, in_ptr1,
in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, ynumel, xnumel, YBLOCK:
tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 64
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
x2 = xindex
y3 = yindex
y1 = yindex // 16
y0 = yindex % 16
tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy=
'evict_last')
tmp1 = tl.load(in_ptr1 + (x2 + 4096 * y3), ymask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr2 + (32 * y1 + x2 // 128), ymask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr3 + (32 * y1 + x2 // 128), ymask, eviction_policy=
'evict_last')
tmp11 = tl.load(in_ptr4 + x2, None, eviction_policy='evict_last')
tmp13 = tl.load(in_ptr5 + x2, None, eviction_policy='evict_last')
tmp3 = tmp1 - tmp2
tmp5 = 2048.0
tmp6 = tmp4 / tmp5
tmp7 = 1e-06
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tmp10 = tmp3 * tmp9
tmp12 = tmp10 * tmp11
tmp14 = tmp12 + tmp13
tmp15 = tmp0 + tmp14
tmp16 = tl.full([1, 1], 0, tl.int32)
tmp17 = triton_helpers.maximum(tmp16, tmp15)
tl.store(out_ptr0 + (y0 + 16 * x2 + 65536 * y1), tmp17, ymask)
@triton.jit
def triton_poi_fused_threshold_backward_46(in_ptr0, out_ptr0, ynumel,
xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
xnumel = 16
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 4096
y1 = yindex // 4096
tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask, eviction_policy=
'evict_last')
tmp1 = 0.0
tmp2 = tmp0 <= tmp1
tl.store(out_ptr0 + (y0 + 4096 * x2 + 65536 * y1), tmp2, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
primals_13, primals_14, primals_15, primals_16, primals_17,
primals_18, primals_19, primals_20, primals_21, primals_22,
primals_23, primals_24, primals_25, primals_26, primals_27,
primals_28, primals_29, primals_30, primals_31, primals_32,
primals_33, primals_34, primals_35, primals_36, primals_37,
primals_38, primals_39, primals_40, primals_41, primals_42,
primals_43, primals_44, primals_45, primals_46, primals_47,
primals_48, primals_49, primals_50, primals_51, primals_52,
primals_53, primals_54, primals_55, primals_56, primals_57,
primals_58, primals_59, primals_60, primals_61, primals_62,
primals_63, primals_64, primals_65, primals_66, primals_67,
primals_68, primals_69, primals_70, primals_71, primals_72,
primals_73, primals_74, primals_75, primals_76, primals_77,
primals_78, primals_79, primals_80, primals_81, primals_82,
primals_83, primals_84, primals_85, primals_86, primals_87,
primals_88, primals_89, primals_90, primals_91, primals_92,
primals_93, primals_94, primals_95, primals_96, primals_97,
primals_98, primals_99, primals_100, primals_101, primals_102,
primals_103, primals_104, primals_105, primals_106, primals_107,
primals_108, primals_109, primals_110, primals_111, primals_112,
primals_113, primals_114, primals_115, primals_116, primals_117,
primals_118, primals_119, primals_120, primals_121) = args
args.clear()
assert_size_stride(primals_1, (256, 3, 7, 7), (147, 49, 7, 1))
assert_size_stride(primals_2, (4, 3, 64, 64), (12288, 4096, 64, 1))
assert_size_stride(primals_3, (256,), (1,))
assert_size_stride(primals_4, (256,), (1,))
assert_size_stride(primals_5, (1024, 256, 1, 1), (256, 1, 1, 1))
assert_size_stride(primals_6, (1024,), (1,))
assert_size_stride(primals_7, (1024,), (1,))
assert_size_stride(primals_8, (256, 256, 1, 1), (256, 1, 1, 1))
assert_size_stride(primals_9, (256,), (1,))
assert_size_stride(primals_10, (256,), (1,))
assert_size_stride(primals_11, (256, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_12, (256,), (1,))
assert_size_stride(primals_13, (256,), (1,))
assert_size_stride(primals_14, (1024, 256, 1, 1), (256, 1, 1, 1))
assert_size_stride(primals_15, (1024,), (1,))
assert_size_stride(primals_16, (1024,), (1,))
assert_size_stride(primals_17, (256, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_18, (256,), (1,))
assert_size_stride(primals_19, (256,), (1,))
assert_size_stride(primals_20, (256, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_21, (256,), (1,))
assert_size_stride(primals_22, (256,), (1,))
assert_size_stride(primals_23, (1024, 256, 1, 1), (256, 1, 1, 1))
assert_size_stride(primals_24, (1024,), (1,))
assert_size_stride(primals_25, (1024,), (1,))
assert_size_stride(primals_26, (256, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_27, (256,), (1,))
assert_size_stride(primals_28, (256,), (1,))
assert_size_stride(primals_29, (256, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_30, (256,), (1,))
assert_size_stride(primals_31, (256,), (1,))
assert_size_stride(primals_32, (1024, 256, 1, 1), (256, 1, 1, 1))
assert_size_stride(primals_33, (1024,), (1,))
assert_size_stride(primals_34, (1024,), (1,))
assert_size_stride(primals_35, (256, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_36, (256,), (1,))
assert_size_stride(primals_37, (256,), (1,))
assert_size_stride(primals_38, (256, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_39, (256,), (1,))
assert_size_stride(primals_40, (256,), (1,))
assert_size_stride(primals_41, (1024, 256, 1, 1), (256, 1, 1, 1))
assert_size_stride(primals_42, (1024,), (1,))
assert_size_stride(primals_43, (1024,), (1,))
assert_size_stride(primals_44, (2048, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_45, (2048,), (1,))
assert_size_stride(primals_46, (2048,), (1,))
assert_size_stride(primals_47, (512, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_48, (512,), (1,))
assert_size_stride(primals_49, (512,), (1,))
assert_size_stride(primals_50, (512, 512, 3, 3), (4608, 9, 3, 1))
assert_size_stride(primals_51, (512,), (1,))
assert_size_stride(primals_52, (512,), (1,))
assert_size_stride(primals_53, (2048, 512, 1, 1), (512, 1, 1, 1))
assert_size_stride(primals_54, (2048,), (1,))
assert_size_stride(primals_55, (2048,), (1,))
assert_size_stride(primals_56, (512, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_57, (512,), (1,))
assert_size_stride(primals_58, (512,), (1,))
assert_size_stride(primals_59, (512, 512, 3, 3), (4608, 9, 3, 1))
assert_size_stride(primals_60, (512,), (1,))
assert_size_stride(primals_61, (512,), (1,))
assert_size_stride(primals_62, (2048, 512, 1, 1), (512, 1, 1, 1))
assert_size_stride(primals_63, (2048,), (1,))
assert_size_stride(primals_64, (2048,), (1,))
assert_size_stride(primals_65, (512, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_66, (512,), (1,))
assert_size_stride(primals_67, (512,), (1,))
assert_size_stride(primals_68, (512, 512, 3, 3), (4608, 9, 3, 1))
assert_size_stride(primals_69, (512,), (1,))
assert_size_stride(primals_70, (512,), (1,))
assert_size_stride(primals_71, (2048, 512, 1, 1), (512, 1, 1, 1))
assert_size_stride(primals_72, (2048,), (1,))
assert_size_stride(primals_73, (2048,), (1,))
assert_size_stride(primals_74, (512, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_75, (512,), (1,))
assert_size_stride(primals_76, (512,), (1,))
assert_size_stride(primals_77, (512, 512, 3, 3), (4608, 9, 3, 1))
assert_size_stride(primals_78, (512,), (1,))
assert_size_stride(primals_79, (512,), (1,))
assert_size_stride(primals_80, (2048, 512, 1, 1), (512, 1, 1, 1))
assert_size_stride(primals_81, (2048,), (1,))
assert_size_stride(primals_82, (2048,), (1,))
assert_size_stride(primals_83, (4096, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_84, (4096,), (1,))
assert_size_stride(primals_85, (4096,), (1,))
assert_size_stride(primals_86, (1024, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_87, (1024,), (1,))
assert_size_stride(primals_88, (1024,), (1,))
assert_size_stride(primals_89, (1024, 1024, 3, 3), (9216, 9, 3, 1))
assert_size_stride(primals_90, (1024,), (1,))
assert_size_stride(primals_91, (1024,), (1,))
assert_size_stride(primals_92, (4096, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_93, (4096,), (1,))
assert_size_stride(primals_94, (4096,), (1,))
assert_size_stride(primals_95, (1024, 4096, 1, 1), (4096, 1, 1, 1))
assert_size_stride(primals_96, (1024,), (1,))
assert_size_stride(primals_97, (1024,), (1,))
assert_size_stride(primals_98, (1024, 1024, 3, 3), (9216, 9, 3, 1))
assert_size_stride(primals_99, (1024,), (1,))
assert_size_stride(primals_100, (1024,), (1,))
assert_size_stride(primals_101, (4096, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_102, (4096,), (1,))
assert_size_stride(primals_103, (4096,), (1,))
assert_size_stride(primals_104, (1024, 4096, 1, 1), (4096, 1, 1, 1))
assert_size_stride(primals_105, (1024,), (1,))
assert_size_stride(primals_106, (1024,), (1,))
assert_size_stride(primals_107, (1024, 1024, 3, 3), (9216, 9, 3, 1))
assert_size_stride(primals_108, (1024,), (1,))
assert_size_stride(primals_109, (1024,), (1,))
assert_size_stride(primals_110, (4096, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_111, (4096,), (1,))
assert_size_stride(primals_112, (4096,), (1,))
assert_size_stride(primals_113, (1024, 4096, 1, 1), (4096, 1, 1, 1))
assert_size_stride(primals_114, (1024,), (1,))
assert_size_stride(primals_115, (1024,), (1,))
assert_size_stride(primals_116, (1024, 1024, 3, 3), (9216, 9, 3, 1))
assert_size_stride(primals_117, (1024,), (1,))
assert_size_stride(primals_118, (1024,), (1,))
assert_size_stride(primals_119, (4096, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_120, (4096,), (1,))
assert_size_stride(primals_121, (4096,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((256, 3, 7, 7), (147, 1, 21, 3), torch.
float32)
get_raw_stream(0)
triton_poi_fused_0[grid(768, 49)](primals_1, buf0, 768, 49, XBLOCK=
32, YBLOCK=32, num_warps=4, num_stages=1)
del primals_1
buf1 = empty_strided_cuda((4, 3, 64, 64), (12288, 1, 192, 3), torch
.float32)
triton_poi_fused_1[grid(12, 4096)](primals_2, buf1, 12, 4096,
XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1)
del primals_2
buf2 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_poi_fused_2[grid(65536, 9)](primals_11, buf2, 65536, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_11
buf3 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_poi_fused_2[grid(65536, 9)](primals_20, buf3, 65536, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_20
buf4 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_poi_fused_2[grid(65536, 9)](primals_29, buf4, 65536, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_29
buf5 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_poi_fused_2[grid(65536, 9)](primals_38, buf5, 65536, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_38
buf6 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512),
torch.float32)
triton_poi_fused_3[grid(262144, 9)](primals_50, buf6, 262144, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_50
buf7 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512),
torch.float32)
triton_poi_fused_3[grid(262144, 9)](primals_59, buf7, 262144, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_59
buf8 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512),
torch.float32)
triton_poi_fused_3[grid(262144, 9)](primals_68, buf8, 262144, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_68
buf9 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512),
torch.float32)
triton_poi_fused_3[grid(262144, 9)](primals_77, buf9, 262144, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_77
buf10 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072, 1024
), torch.float32)
triton_poi_fused_4[grid(1048576, 9)](primals_89, buf10, 1048576, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_89
buf11 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072, 1024
), torch.float32)
triton_poi_fused_4[grid(1048576, 9)](primals_98, buf11, 1048576, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_98
buf12 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072, 1024
), torch.float32)
triton_poi_fused_4[grid(1048576, 9)](primals_107, buf12, 1048576, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_107
buf13 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072, 1024
), torch.float32)
triton_poi_fused_4[grid(1048576, 9)](primals_116, buf13, 1048576, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_116
buf15 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256),
torch.float32)
buf17 = reinterpret_tensor(buf15, (256, 1, 1, 1), (1, 1, 1, 1), 0)
del buf15
buf18 = empty_strided_cuda((256, 3, 7, 7), (147, 1, 21, 3), torch.
float32)
triton_per_fused_add_div_sqrt_sub_var_mean_5[grid(256)](buf17, buf0,
buf18, 256, 147, XBLOCK=1, num_warps=2, num_stages=1)
buf19 = extern_kernels.convolution(buf1, buf18, stride=(2, 2),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf19, (4, 256, 32, 32), (262144, 1, 8192, 256))
buf20 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf21 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf23 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_6[grid(128)](buf19, buf20, buf21,
buf23, 128, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1
)
buf24 = empty_strided_cuda((4, 256, 32, 32), (262144, 1, 8192, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_7[grid(1048576)](buf19,
buf20, buf21, primals_3, primals_4, buf24, 1048576, XBLOCK=512,
num_warps=8, num_stages=1)
del primals_4
buf25 = empty_strided_cuda((4, 256, 15, 15), (57600, 1, 3840, 256),
torch.float32)
buf26 = empty_strided_cuda((4, 256, 15, 15), (57600, 1, 3840, 256),
torch.int8)
triton_poi_fused_max_pool2d_with_indices_8[grid(230400)](buf24,
buf25, buf26, 230400, XBLOCK=512, num_warps=8, num_stages=1)
buf28 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf30 = reinterpret_tensor(buf28, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf28
buf31 = empty_strided_cuda((1024, 256, 1, 1), (256, 1, 256, 256),
torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_9[grid(1024)](buf30,
primals_5, buf31, 1024, 256, num_warps=2, num_stages=1)
buf32 = extern_kernels.convolution(buf25, buf31, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf32, (4, 1024, 15, 15), (230400, 1, 15360, 1024))
buf33 = empty_strided_cuda((4, 1024, 1, 1), (1024, 1, 4096, 4096),
torch.float32)
buf34 = empty_strided_cuda((4, 1024, 1, 1), (1024, 1, 4096, 4096),
torch.float32)
buf36 = empty_strided_cuda((4, 1024, 1, 1), (1024, 1, 4096, 4096),
torch.float32)
triton_per_fused_native_group_norm_10[grid(4096)](buf32, buf33,
buf34, buf36, 4096, 225, XBLOCK=1, num_warps=2, num_stages=1)
buf38 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256),
torch.float32)
buf40 = reinterpret_tensor(buf38, (256, 1, 1, 1), (1, 1, 1, 1), 0)
del buf38
buf41 = empty_strided_cuda((256, 256, 1, 1), (256, 1, 256, 256),
torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_11[grid(256)](buf40,
primals_8, buf41, 256, 256, num_warps=2, num_stages=1)
buf42 = extern_kernels.convolution(buf25, buf41, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf42, (4, 256, 15, 15), (57600, 1, 3840, 256))
buf43 = buf21
del buf21
buf44 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf46 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_12[grid(128)](buf42, buf43,
buf44, buf46, 128, 1800, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf47 = empty_strided_cuda((4, 256, 15, 15), (57600, 1, 3840, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_13[grid(230400)](buf42,
buf43, buf44, primals_9, primals_10, buf47, 230400, XBLOCK=1024,
num_warps=4, num_stages=1)
del primals_10
buf49 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256),
torch.float32)
buf51 = reinterpret_tensor(buf49, (256, 1, 1, 1), (1, 1, 1, 1), 0)
del buf49
buf52 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_14[grid(256)](buf51,
buf2, buf52, 256, 2304, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf53 = extern_kernels.convolution(buf47, buf52, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf53, (4, 256, 15, 15), (57600, 1, 3840, 256))
buf54 = buf44
del buf44
buf55 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf57 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_12[grid(128)](buf53, buf54,
buf55, buf57, 128, 1800, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf58 = empty_strided_cuda((4, 256, 15, 15), (57600, 1, 3840, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_13[grid(230400)](buf53,
buf54, buf55, primals_12, primals_13, buf58, 230400, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_13
buf60 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf62 = reinterpret_tensor(buf60, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf60
buf63 = empty_strided_cuda((1024, 256, 1, 1), (256, 1, 256, 256),
torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_9[grid(1024)](buf62,
primals_14, buf63, 1024, 256, num_warps=2, num_stages=1)
buf64 = extern_kernels.convolution(buf58, buf63, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf64, (4, 1024, 15, 15), (230400, 1, 15360, 1024))
buf65 = buf55
del buf55
buf66 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf68 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_15[grid(128)](buf64, buf65,
buf66, buf68, 128, 7200, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf69 = empty_strided_cuda((4, 1024, 15, 15), (230400, 1, 15360,
1024), torch.float32)
buf70 = buf69
del buf69
triton_poi_fused_add_native_group_norm_relu_16[grid(921600)](buf70,
buf32, buf33, buf34, primals_6, primals_7, buf64, buf65, buf66,
primals_15, primals_16, 921600, XBLOCK=512, num_warps=8,
num_stages=1)
del primals_16
del primals_7
buf72 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256),
torch.float32)
buf74 = reinterpret_tensor(buf72, (256, 1, 1, 1), (1, 1, 1, 1), 0)
del buf72
buf75 = empty_strided_cuda((256, 1024, 1, 1), (1024, 1, 1024, 1024),
torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_17[grid(256)](buf74,
primals_17, buf75, 256, 1024, num_warps=8, num_stages=1)
buf76 = extern_kernels.convolution(buf70, buf75, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf76, (4, 256, 15, 15), (57600, 1, 3840, 256))
buf77 = buf66
del buf66
buf78 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf80 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_12[grid(128)](buf76, buf77,
buf78, buf80, 128, 1800, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf81 = empty_strided_cuda((4, 256, 15, 15), (57600, 1, 3840, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_13[grid(230400)](buf76,
buf77, buf78, primals_18, primals_19, buf81, 230400, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_19
buf83 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256),
torch.float32)
buf85 = reinterpret_tensor(buf83, (256, 1, 1, 1), (1, 1, 1, 1), 0)
del buf83
buf86 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_14[grid(256)](buf85,
buf3, buf86, 256, 2304, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf87 = extern_kernels.convolution(buf81, buf86, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf87, (4, 256, 15, 15), (57600, 1, 3840, 256))
buf88 = buf78
del buf78
buf89 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf91 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_12[grid(128)](buf87, buf88,
buf89, buf91, 128, 1800, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf92 = empty_strided_cuda((4, 256, 15, 15), (57600, 1, 3840, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_13[grid(230400)](buf87,
buf88, buf89, primals_21, primals_22, buf92, 230400, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_22
buf94 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf96 = reinterpret_tensor(buf94, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf94
buf97 = empty_strided_cuda((1024, 256, 1, 1), (256, 1, 256, 256),
torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_9[grid(1024)](buf96,
primals_23, buf97, 1024, 256, num_warps=2, num_stages=1)
buf98 = extern_kernels.convolution(buf92, buf97, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf98, (4, 1024, 15, 15), (230400, 1, 15360, 1024))
buf99 = buf89
del buf89
buf100 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf102 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_15[grid(128)](buf98, buf99,
buf100, buf102, 128, 7200, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf103 = empty_strided_cuda((4, 1024, 15, 15), (230400, 1, 15360,
1024), torch.float32)
triton_poi_fused_add_native_group_norm_relu_18[grid(921600)](buf70,
buf98, buf99, buf100, primals_24, primals_25, buf103, 921600,
XBLOCK=512, num_warps=8, num_stages=1)
del primals_25
buf105 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256),
torch.float32)
buf107 = reinterpret_tensor(buf105, (256, 1, 1, 1), (1, 1, 1, 1), 0)
del buf105
buf108 = empty_strided_cuda((256, 1024, 1, 1), (1024, 1, 1024, 1024
), torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_17[grid(256)](buf107,
primals_26, buf108, 256, 1024, num_warps=8, num_stages=1)
buf109 = extern_kernels.convolution(buf103, buf108, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf109, (4, 256, 15, 15), (57600, 1, 3840, 256))
buf110 = buf100
del buf100
buf111 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf113 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_12[grid(128)](buf109, buf110,
buf111, buf113, 128, 1800, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf114 = empty_strided_cuda((4, 256, 15, 15), (57600, 1, 3840, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_13[grid(230400)](buf109,
buf110, buf111, primals_27, primals_28, buf114, 230400, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_28
buf116 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256),
torch.float32)
buf118 = reinterpret_tensor(buf116, (256, 1, 1, 1), (1, 1, 1, 1), 0)
del buf116
buf119 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_14[grid(256)](buf118,
buf4, buf119, 256, 2304, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf120 = extern_kernels.convolution(buf114, buf119, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf120, (4, 256, 15, 15), (57600, 1, 3840, 256))
buf121 = buf111
del buf111
buf122 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf124 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_12[grid(128)](buf120, buf121,
buf122, buf124, 128, 1800, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf125 = empty_strided_cuda((4, 256, 15, 15), (57600, 1, 3840, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_13[grid(230400)](buf120,
buf121, buf122, primals_30, primals_31, buf125, 230400, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_31
buf127 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf129 = reinterpret_tensor(buf127, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf127
buf130 = empty_strided_cuda((1024, 256, 1, 1), (256, 1, 256, 256),
torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_9[grid(1024)](buf129,
primals_32, buf130, 1024, 256, num_warps=2, num_stages=1)
buf131 = extern_kernels.convolution(buf125, buf130, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf131, (4, 1024, 15, 15), (230400, 1, 15360, 1024))
buf132 = buf122
del buf122
buf133 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf135 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_15[grid(128)](buf131, buf132,
buf133, buf135, 128, 7200, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf136 = empty_strided_cuda((4, 1024, 15, 15), (230400, 1, 15360,
1024), torch.float32)
triton_poi_fused_add_native_group_norm_relu_18[grid(921600)](buf103,
buf131, buf132, buf133, primals_33, primals_34, buf136, 921600,
XBLOCK=512, num_warps=8, num_stages=1)
del primals_34
buf138 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256),
torch.float32)
buf140 = reinterpret_tensor(buf138, (256, 1, 1, 1), (1, 1, 1, 1), 0)
del buf138
buf141 = empty_strided_cuda((256, 1024, 1, 1), (1024, 1, 1024, 1024
), torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_17[grid(256)](buf140,
primals_35, buf141, 256, 1024, num_warps=8, num_stages=1)
buf142 = extern_kernels.convolution(buf136, buf141, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf142, (4, 256, 15, 15), (57600, 1, 3840, 256))
buf143 = buf133
del buf133
buf144 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf146 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_12[grid(128)](buf142, buf143,
buf144, buf146, 128, 1800, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf147 = empty_strided_cuda((4, 256, 15, 15), (57600, 1, 3840, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_13[grid(230400)](buf142,
buf143, buf144, primals_36, primals_37, buf147, 230400, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_37
buf149 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256),
torch.float32)
buf151 = reinterpret_tensor(buf149, (256, 1, 1, 1), (1, 1, 1, 1), 0)
del buf149
buf152 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_14[grid(256)](buf151,
buf5, buf152, 256, 2304, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf153 = extern_kernels.convolution(buf147, buf152, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf153, (4, 256, 15, 15), (57600, 1, 3840, 256))
buf154 = buf144
del buf144
buf155 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf157 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_12[grid(128)](buf153, buf154,
buf155, buf157, 128, 1800, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf158 = empty_strided_cuda((4, 256, 15, 15), (57600, 1, 3840, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_13[grid(230400)](buf153,
buf154, buf155, primals_39, primals_40, buf158, 230400, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_40
buf160 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf162 = reinterpret_tensor(buf160, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf160
buf163 = empty_strided_cuda((1024, 256, 1, 1), (256, 1, 256, 256),
torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_9[grid(1024)](buf162,
primals_41, buf163, 1024, 256, num_warps=2, num_stages=1)
buf164 = extern_kernels.convolution(buf158, buf163, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf164, (4, 1024, 15, 15), (230400, 1, 15360, 1024))
buf165 = buf155
del buf155
buf166 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf168 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_15[grid(128)](buf164, buf165,
buf166, buf168, 128, 7200, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf169 = empty_strided_cuda((4, 1024, 15, 15), (230400, 1, 15360,
1024), torch.float32)
triton_poi_fused_add_native_group_norm_relu_18[grid(921600)](buf136,
buf164, buf165, buf166, primals_42, primals_43, buf169, 921600,
XBLOCK=512, num_warps=8, num_stages=1)
del primals_43
buf171 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048),
torch.float32)
buf173 = reinterpret_tensor(buf171, (2048, 1, 1, 1), (1, 1, 1, 1), 0)
del buf171
buf174 = empty_strided_cuda((2048, 1024, 1, 1), (1024, 1, 1024,
1024), torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_19[grid(2048)](buf173,
primals_44, buf174, 2048, 1024, num_warps=8, num_stages=1)
buf175 = extern_kernels.convolution(buf169, buf174, stride=(2, 2),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf175, (4, 2048, 8, 8), (131072, 1, 16384, 2048))
buf176 = empty_strided_cuda((4, 2048, 1, 1), (2048, 1, 8192, 8192),
torch.float32)
buf177 = empty_strided_cuda((4, 2048, 1, 1), (2048, 1, 8192, 8192),
torch.float32)
buf179 = empty_strided_cuda((4, 2048, 1, 1), (2048, 1, 8192, 8192),
torch.float32)
triton_per_fused_native_group_norm_20[grid(8192)](buf175, buf176,
buf177, buf179, 8192, 64, XBLOCK=8, num_warps=4, num_stages=1)
buf181 = empty_strided_cuda((512, 1, 1, 1), (1, 512, 512, 512),
torch.float32)
buf183 = reinterpret_tensor(buf181, (512, 1, 1, 1), (1, 1, 1, 1), 0)
del buf181
buf184 = empty_strided_cuda((512, 1024, 1, 1), (1024, 1, 1024, 1024
), torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_21[grid(512)](buf183,
primals_47, buf184, 512, 1024, num_warps=8, num_stages=1)
buf185 = extern_kernels.convolution(buf169, buf184, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf185, (4, 512, 15, 15), (115200, 1, 7680, 512))
buf186 = buf166
del buf166
buf187 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf189 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_22[grid(128)](buf185, buf186,
buf187, buf189, 128, 3600, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf190 = empty_strided_cuda((4, 512, 15, 15), (115200, 1, 7680, 512
), torch.float32)
triton_poi_fused_native_group_norm_relu_23[grid(460800)](buf185,
buf186, buf187, primals_48, primals_49, buf190, 460800, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_49
buf192 = empty_strided_cuda((512, 1, 1, 1), (1, 512, 512, 512),
torch.float32)
buf194 = reinterpret_tensor(buf192, (512, 1, 1, 1), (1, 1, 1, 1), 0)
del buf192
buf195 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512),
torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_24[grid(512)](buf194,
buf6, buf195, 512, 4608, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf196 = extern_kernels.convolution(buf190, buf195, stride=(2, 2),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf196, (4, 512, 8, 8), (32768, 1, 4096, 512))
buf197 = buf187
del buf187
buf198 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf200 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_25[grid(128)](buf196, buf197,
buf198, buf200, 128, 1024, num_warps=8, num_stages=1)
buf201 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512),
torch.float32)
triton_poi_fused_native_group_norm_relu_26[grid(131072)](buf196,
buf197, buf198, primals_51, primals_52, buf201, 131072, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_52
buf203 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048),
torch.float32)
buf205 = reinterpret_tensor(buf203, (2048, 1, 1, 1), (1, 1, 1, 1), 0)
del buf203
buf206 = empty_strided_cuda((2048, 512, 1, 1), (512, 1, 512, 512),
torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_27[grid(2048)](buf205,
primals_53, buf206, 2048, 512, num_warps=4, num_stages=1)
buf207 = extern_kernels.convolution(buf201, buf206, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf207, (4, 2048, 8, 8), (131072, 1, 16384, 2048))
buf208 = buf198
del buf198
buf209 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf211 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_28[grid(128)](buf207, buf208,
buf209, buf211, 128, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf212 = empty_strided_cuda((4, 2048, 8, 8), (131072, 1, 16384,
2048), torch.float32)
buf213 = buf212
del buf212
triton_poi_fused_add_native_group_norm_relu_29[grid(524288)](buf213,
buf175, buf176, buf177, primals_45, primals_46, buf207, buf208,
buf209, primals_54, primals_55, 524288, XBLOCK=512, num_warps=8,
num_stages=1)
del buf177
del primals_46
del primals_55
buf215 = empty_strided_cuda((512, 1, 1, 1), (1, 512, 512, 512),
torch.float32)
buf217 = reinterpret_tensor(buf215, (512, 1, 1, 1), (1, 1, 1, 1), 0)
del buf215
buf218 = empty_strided_cuda((512, 2048, 1, 1), (2048, 1, 2048, 2048
), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_30[grid(512)](buf217,
primals_56, buf218, 512, 2048, XBLOCK=1, RBLOCK=2048, num_warps
=16, num_stages=1)
buf219 = extern_kernels.convolution(buf213, buf218, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf219, (4, 512, 8, 8), (32768, 1, 4096, 512))
buf220 = buf209
del buf209
buf221 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf223 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_25[grid(128)](buf219, buf220,
buf221, buf223, 128, 1024, num_warps=8, num_stages=1)
buf224 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512),
torch.float32)
triton_poi_fused_native_group_norm_relu_26[grid(131072)](buf219,
buf220, buf221, primals_57, primals_58, buf224, 131072, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_58
buf226 = empty_strided_cuda((512, 1, 1, 1), (1, 512, 512, 512),
torch.float32)
buf228 = reinterpret_tensor(buf226, (512, 1, 1, 1), (1, 1, 1, 1), 0)
del buf226
buf229 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512),
torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_24[grid(512)](buf228,
buf7, buf229, 512, 4608, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf230 = extern_kernels.convolution(buf224, buf229, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf230, (4, 512, 8, 8), (32768, 1, 4096, 512))
buf231 = buf221
del buf221
buf232 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf234 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_25[grid(128)](buf230, buf231,
buf232, buf234, 128, 1024, num_warps=8, num_stages=1)
buf235 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512),
torch.float32)
triton_poi_fused_native_group_norm_relu_26[grid(131072)](buf230,
buf231, buf232, primals_60, primals_61, buf235, 131072, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_61
buf237 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048),
torch.float32)
buf239 = reinterpret_tensor(buf237, (2048, 1, 1, 1), (1, 1, 1, 1), 0)
del buf237
buf240 = empty_strided_cuda((2048, 512, 1, 1), (512, 1, 512, 512),
torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_27[grid(2048)](buf239,
primals_62, buf240, 2048, 512, num_warps=4, num_stages=1)
buf241 = extern_kernels.convolution(buf235, buf240, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf241, (4, 2048, 8, 8), (131072, 1, 16384, 2048))
buf242 = buf232
del buf232
buf243 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf245 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_28[grid(128)](buf241, buf242,
buf243, buf245, 128, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf246 = empty_strided_cuda((4, 2048, 8, 8), (131072, 1, 16384,
2048), torch.float32)
triton_poi_fused_add_native_group_norm_relu_31[grid(524288)](buf213,
buf241, buf242, buf243, primals_63, primals_64, buf246, 524288,
XBLOCK=512, num_warps=8, num_stages=1)
del primals_64
buf248 = empty_strided_cuda((512, 1, 1, 1), (1, 512, 512, 512),
torch.float32)
buf250 = reinterpret_tensor(buf248, (512, 1, 1, 1), (1, 1, 1, 1), 0)
del buf248
buf251 = empty_strided_cuda((512, 2048, 1, 1), (2048, 1, 2048, 2048
), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_30[grid(512)](buf250,
primals_65, buf251, 512, 2048, XBLOCK=1, RBLOCK=2048, num_warps
=16, num_stages=1)
buf252 = extern_kernels.convolution(buf246, buf251, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf252, (4, 512, 8, 8), (32768, 1, 4096, 512))
buf253 = buf243
del buf243
buf254 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf256 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_25[grid(128)](buf252, buf253,
buf254, buf256, 128, 1024, num_warps=8, num_stages=1)
buf257 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512),
torch.float32)
triton_poi_fused_native_group_norm_relu_26[grid(131072)](buf252,
buf253, buf254, primals_66, primals_67, buf257, 131072, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_67
buf259 = empty_strided_cuda((512, 1, 1, 1), (1, 512, 512, 512),
torch.float32)
buf261 = reinterpret_tensor(buf259, (512, 1, 1, 1), (1, 1, 1, 1), 0)
del buf259
buf262 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512),
torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_24[grid(512)](buf261,
buf8, buf262, 512, 4608, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf263 = extern_kernels.convolution(buf257, buf262, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf263, (4, 512, 8, 8), (32768, 1, 4096, 512))
buf264 = buf254
del buf254
buf265 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf267 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_25[grid(128)](buf263, buf264,
buf265, buf267, 128, 1024, num_warps=8, num_stages=1)
buf268 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512),
torch.float32)
triton_poi_fused_native_group_norm_relu_26[grid(131072)](buf263,
buf264, buf265, primals_69, primals_70, buf268, 131072, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_70
buf270 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048),
torch.float32)
buf272 = reinterpret_tensor(buf270, (2048, 1, 1, 1), (1, 1, 1, 1), 0)
del buf270
buf273 = empty_strided_cuda((2048, 512, 1, 1), (512, 1, 512, 512),
torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_27[grid(2048)](buf272,
primals_71, buf273, 2048, 512, num_warps=4, num_stages=1)
buf274 = extern_kernels.convolution(buf268, buf273, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf274, (4, 2048, 8, 8), (131072, 1, 16384, 2048))
buf275 = buf265
del buf265
buf276 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf278 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_28[grid(128)](buf274, buf275,
buf276, buf278, 128, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf279 = empty_strided_cuda((4, 2048, 8, 8), (131072, 1, 16384,
2048), torch.float32)
triton_poi_fused_add_native_group_norm_relu_31[grid(524288)](buf246,
buf274, buf275, buf276, primals_72, primals_73, buf279, 524288,
XBLOCK=512, num_warps=8, num_stages=1)
del primals_73
buf281 = empty_strided_cuda((512, 1, 1, 1), (1, 512, 512, 512),
torch.float32)
buf283 = reinterpret_tensor(buf281, (512, 1, 1, 1), (1, 1, 1, 1), 0)
del buf281
buf284 = empty_strided_cuda((512, 2048, 1, 1), (2048, 1, 2048, 2048
), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_30[grid(512)](buf283,
primals_74, buf284, 512, 2048, XBLOCK=1, RBLOCK=2048, num_warps
=16, num_stages=1)
buf285 = extern_kernels.convolution(buf279, buf284, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf285, (4, 512, 8, 8), (32768, 1, 4096, 512))
buf286 = buf276
del buf276
buf287 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf289 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_25[grid(128)](buf285, buf286,
buf287, buf289, 128, 1024, num_warps=8, num_stages=1)
buf290 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512),
torch.float32)
triton_poi_fused_native_group_norm_relu_26[grid(131072)](buf285,
buf286, buf287, primals_75, primals_76, buf290, 131072, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_76
buf292 = empty_strided_cuda((512, 1, 1, 1), (1, 512, 512, 512),
torch.float32)
buf294 = reinterpret_tensor(buf292, (512, 1, 1, 1), (1, 1, 1, 1), 0)
del buf292
buf295 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512),
torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_24[grid(512)](buf294,
buf9, buf295, 512, 4608, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf296 = extern_kernels.convolution(buf290, buf295, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf296, (4, 512, 8, 8), (32768, 1, 4096, 512))
buf297 = buf287
del buf287
buf298 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf300 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_25[grid(128)](buf296, buf297,
buf298, buf300, 128, 1024, num_warps=8, num_stages=1)
buf301 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512),
torch.float32)
triton_poi_fused_native_group_norm_relu_26[grid(131072)](buf296,
buf297, buf298, primals_78, primals_79, buf301, 131072, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_79
buf303 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048),
torch.float32)
buf305 = reinterpret_tensor(buf303, (2048, 1, 1, 1), (1, 1, 1, 1), 0)
del buf303
buf306 = empty_strided_cuda((2048, 512, 1, 1), (512, 1, 512, 512),
torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_27[grid(2048)](buf305,
primals_80, buf306, 2048, 512, num_warps=4, num_stages=1)
buf307 = extern_kernels.convolution(buf301, buf306, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf307, (4, 2048, 8, 8), (131072, 1, 16384, 2048))
buf308 = buf298
del buf298
buf309 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf311 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_28[grid(128)](buf307, buf308,
buf309, buf311, 128, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf312 = empty_strided_cuda((4, 2048, 8, 8), (131072, 1, 16384,
2048), torch.float32)
triton_poi_fused_add_native_group_norm_relu_31[grid(524288)](buf279,
buf307, buf308, buf309, primals_81, primals_82, buf312, 524288,
XBLOCK=512, num_warps=8, num_stages=1)
del primals_82
buf314 = reinterpret_tensor(buf34, (4096, 1, 1, 1), (1, 4096, 4096,
4096), 0)
del buf34
buf316 = reinterpret_tensor(buf314, (4096, 1, 1, 1), (1, 1, 1, 1), 0)
del buf314
buf317 = empty_strided_cuda((4096, 2048, 1, 1), (2048, 1, 2048,
2048), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_32[grid(4096)](buf316,
primals_83, buf317, 4096, 2048, XBLOCK=1, RBLOCK=2048,
num_warps=16, num_stages=1)
buf318 = extern_kernels.convolution(buf312, buf317, stride=(2, 2),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf318, (4, 4096, 4, 4), (65536, 1, 16384, 4096))
buf319 = empty_strided_cuda((4, 4096, 1, 1), (4096, 1, 16384, 16384
), torch.float32)
buf320 = empty_strided_cuda((4, 4096, 1, 1), (4096, 1, 16384, 16384
), torch.float32)
buf322 = empty_strided_cuda((4, 4096, 1, 1), (4096, 1, 16384, 16384
), torch.float32)
triton_per_fused_native_group_norm_33[grid(16384)](buf318, buf319,
buf320, buf322, 16384, 16, XBLOCK=32, num_warps=4, num_stages=1)
buf324 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf326 = reinterpret_tensor(buf324, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf324
buf327 = empty_strided_cuda((1024, 2048, 1, 1), (2048, 1, 2048,
2048), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_34[grid(1024)](buf326,
primals_86, buf327, 1024, 2048, XBLOCK=1, RBLOCK=2048,
num_warps=16, num_stages=1)
buf328 = extern_kernels.convolution(buf312, buf327, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf328, (4, 1024, 8, 8), (65536, 1, 8192, 1024))
buf329 = buf309
del buf309
buf330 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf332 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_35[grid(128)](buf328, buf329,
buf330, buf332, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf333 = empty_strided_cuda((4, 1024, 8, 8), (65536, 1, 8192, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_36[grid(262144)](buf328,
buf329, buf330, primals_87, primals_88, buf333, 262144, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_88
buf335 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf337 = reinterpret_tensor(buf335, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf335
buf338 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072,
1024), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_37[grid(1024)](buf337,
buf10, buf338, 1024, 9216, XBLOCK=1, RBLOCK=1024, num_warps=16,
num_stages=1)
buf339 = extern_kernels.convolution(buf333, buf338, stride=(2, 2),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf339, (4, 1024, 4, 4), (16384, 1, 4096, 1024))
buf340 = buf330
del buf330
buf341 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf343 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_38[grid(128)](buf339, buf340,
buf341, buf343, 128, 512, num_warps=4, num_stages=1)
buf344 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_39[grid(65536)](buf339,
buf340, buf341, primals_90, primals_91, buf344, 65536, XBLOCK=
512, num_warps=4, num_stages=1)
del primals_91
buf346 = empty_strided_cuda((4096, 1, 1, 1), (1, 4096, 4096, 4096),
torch.float32)
buf348 = reinterpret_tensor(buf346, (4096, 1, 1, 1), (1, 1, 1, 1), 0)
del buf346
buf349 = empty_strided_cuda((4096, 1024, 1, 1), (1024, 1, 1024,
1024), torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_40[grid(4096)](buf348,
primals_92, buf349, 4096, 1024, num_warps=8, num_stages=1)
buf350 = extern_kernels.convolution(buf344, buf349, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf350, (4, 4096, 4, 4), (65536, 1, 16384, 4096))
buf351 = buf341
del buf341
buf352 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf354 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_41[grid(128)](buf350, buf351,
buf352, buf354, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf355 = empty_strided_cuda((4, 4096, 4, 4), (65536, 1, 16384, 4096
), torch.float32)
buf356 = buf355
del buf355
triton_poi_fused_add_native_group_norm_relu_42[grid(262144)](buf356,
buf318, buf319, buf320, primals_84, primals_85, buf350, buf351,
buf352, primals_93, primals_94, 262144, XBLOCK=512, num_warps=8,
num_stages=1)
del buf320
del primals_85
del primals_94
buf358 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf360 = reinterpret_tensor(buf358, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf358
buf361 = empty_strided_cuda((1024, 4096, 1, 1), (4096, 1, 4096,
4096), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_43[grid(1024)](buf360,
primals_95, buf361, 1024, 4096, XBLOCK=1, RBLOCK=2048,
num_warps=16, num_stages=1)
buf362 = extern_kernels.convolution(buf356, buf361, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf362, (4, 1024, 4, 4), (16384, 1, 4096, 1024))
buf363 = buf352
del buf352
buf364 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf366 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_38[grid(128)](buf362, buf363,
buf364, buf366, 128, 512, num_warps=4, num_stages=1)
buf367 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_39[grid(65536)](buf362,
buf363, buf364, primals_96, primals_97, buf367, 65536, XBLOCK=
512, num_warps=4, num_stages=1)
del primals_97
buf369 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf371 = reinterpret_tensor(buf369, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf369
buf372 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072,
1024), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_37[grid(1024)](buf371,
buf11, buf372, 1024, 9216, XBLOCK=1, RBLOCK=1024, num_warps=16,
num_stages=1)
buf373 = extern_kernels.convolution(buf367, buf372, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf373, (4, 1024, 4, 4), (16384, 1, 4096, 1024))
buf374 = buf364
del buf364
buf375 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf377 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_38[grid(128)](buf373, buf374,
buf375, buf377, 128, 512, num_warps=4, num_stages=1)
buf378 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_39[grid(65536)](buf373,
buf374, buf375, primals_99, primals_100, buf378, 65536, XBLOCK=
512, num_warps=4, num_stages=1)
del primals_100
buf380 = empty_strided_cuda((4096, 1, 1, 1), (1, 4096, 4096, 4096),
torch.float32)
buf382 = reinterpret_tensor(buf380, (4096, 1, 1, 1), (1, 1, 1, 1), 0)
del buf380
buf383 = empty_strided_cuda((4096, 1024, 1, 1), (1024, 1, 1024,
1024), torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_40[grid(4096)](buf382,
primals_101, buf383, 4096, 1024, num_warps=8, num_stages=1)
buf384 = extern_kernels.convolution(buf378, buf383, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf384, (4, 4096, 4, 4), (65536, 1, 16384, 4096))
buf385 = buf375
del buf375
buf386 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf388 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_41[grid(128)](buf384, buf385,
buf386, buf388, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf389 = empty_strided_cuda((4, 4096, 4, 4), (65536, 1, 16384, 4096
), torch.float32)
triton_poi_fused_add_native_group_norm_relu_44[grid(262144)](buf356,
buf384, buf385, buf386, primals_102, primals_103, buf389,
262144, XBLOCK=512, num_warps=8, num_stages=1)
del primals_103
buf391 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf393 = reinterpret_tensor(buf391, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf391
buf394 = empty_strided_cuda((1024, 4096, 1, 1), (4096, 1, 4096,
4096), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_43[grid(1024)](buf393,
primals_104, buf394, 1024, 4096, XBLOCK=1, RBLOCK=2048,
num_warps=16, num_stages=1)
buf395 = extern_kernels.convolution(buf389, buf394, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf395, (4, 1024, 4, 4), (16384, 1, 4096, 1024))
buf396 = buf386
del buf386
buf397 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf399 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_38[grid(128)](buf395, buf396,
buf397, buf399, 128, 512, num_warps=4, num_stages=1)
buf400 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_39[grid(65536)](buf395,
buf396, buf397, primals_105, primals_106, buf400, 65536, XBLOCK
=512, num_warps=4, num_stages=1)
del primals_106
buf402 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf404 = reinterpret_tensor(buf402, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf402
buf405 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072,
1024), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_37[grid(1024)](buf404,
buf12, buf405, 1024, 9216, XBLOCK=1, RBLOCK=1024, num_warps=16,
num_stages=1)
buf406 = extern_kernels.convolution(buf400, buf405, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf406, (4, 1024, 4, 4), (16384, 1, 4096, 1024))
buf407 = buf397
del buf397
buf408 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf410 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_38[grid(128)](buf406, buf407,
buf408, buf410, 128, 512, num_warps=4, num_stages=1)
buf411 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_39[grid(65536)](buf406,
buf407, buf408, primals_108, primals_109, buf411, 65536, XBLOCK
=512, num_warps=4, num_stages=1)
del primals_109
buf413 = empty_strided_cuda((4096, 1, 1, 1), (1, 4096, 4096, 4096),
torch.float32)
buf415 = reinterpret_tensor(buf413, (4096, 1, 1, 1), (1, 1, 1, 1), 0)
del buf413
buf416 = empty_strided_cuda((4096, 1024, 1, 1), (1024, 1, 1024,
1024), torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_40[grid(4096)](buf415,
primals_110, buf416, 4096, 1024, num_warps=8, num_stages=1)
buf417 = extern_kernels.convolution(buf411, buf416, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf417, (4, 4096, 4, 4), (65536, 1, 16384, 4096))
buf418 = buf408
del buf408
buf419 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf421 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_41[grid(128)](buf417, buf418,
buf419, buf421, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf422 = empty_strided_cuda((4, 4096, 4, 4), (65536, 1, 16384, 4096
), torch.float32)
triton_poi_fused_add_native_group_norm_relu_44[grid(262144)](buf389,
buf417, buf418, buf419, primals_111, primals_112, buf422,
262144, XBLOCK=512, num_warps=8, num_stages=1)
del primals_112
buf424 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf426 = reinterpret_tensor(buf424, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf424
buf427 = empty_strided_cuda((1024, 4096, 1, 1), (4096, 1, 4096,
4096), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_43[grid(1024)](buf426,
primals_113, buf427, 1024, 4096, XBLOCK=1, RBLOCK=2048,
num_warps=16, num_stages=1)
buf428 = extern_kernels.convolution(buf422, buf427, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf428, (4, 1024, 4, 4), (16384, 1, 4096, 1024))
buf429 = buf419
del buf419
buf430 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf432 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_38[grid(128)](buf428, buf429,
buf430, buf432, 128, 512, num_warps=4, num_stages=1)
buf433 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_39[grid(65536)](buf428,
buf429, buf430, primals_114, primals_115, buf433, 65536, XBLOCK
=512, num_warps=4, num_stages=1)
del primals_115
buf435 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf437 = reinterpret_tensor(buf435, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf435
buf438 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072,
1024), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_37[grid(1024)](buf437,
buf13, buf438, 1024, 9216, XBLOCK=1, RBLOCK=1024, num_warps=16,
num_stages=1)
buf439 = extern_kernels.convolution(buf433, buf438, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf439, (4, 1024, 4, 4), (16384, 1, 4096, 1024))
buf440 = buf430
del buf430
buf441 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf443 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_38[grid(128)](buf439, buf440,
buf441, buf443, 128, 512, num_warps=4, num_stages=1)
buf444 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_39[grid(65536)](buf439,
buf440, buf441, primals_117, primals_118, buf444, 65536, XBLOCK
=512, num_warps=4, num_stages=1)
del primals_118
buf446 = empty_strided_cuda((4096, 1, 1, 1), (1, 4096, 4096, 4096),
torch.float32)
buf448 = reinterpret_tensor(buf446, (4096, 1, 1, 1), (1, 1, 1, 1), 0)
del buf446
buf449 = empty_strided_cuda((4096, 1024, 1, 1), (1024, 1, 1024,
1024), torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_40[grid(4096)](buf448,
primals_119, buf449, 4096, 1024, num_warps=8, num_stages=1)
buf450 = extern_kernels.convolution(buf444, buf449, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf450, (4, 4096, 4, 4), (65536, 1, 16384, 4096))
buf451 = buf441
del buf441
buf452 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf454 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_41[grid(128)](buf450, buf451,
buf452, buf454, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf455 = empty_strided_cuda((4, 4096, 4, 4), (65536, 16, 4, 1),
torch.float32)
triton_poi_fused_add_native_group_norm_relu_45[grid(64, 4096)](buf422,
buf450, buf451, buf452, primals_120, primals_121, buf455, 64,
4096, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del buf452
del primals_121
buf456 = empty_strided_cuda((4, 4096, 4, 4), (65536, 1, 16384, 4096
), torch.bool)
triton_poi_fused_threshold_backward_46[grid(16384, 16)](buf455,
buf456, 16384, 16, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
return (buf455, buf0, buf1, primals_3, primals_5, primals_6, primals_8,
primals_9, buf2, primals_12, primals_14, primals_15, primals_17,
primals_18, buf3, primals_21, primals_23, primals_24, primals_26,
primals_27, buf4, primals_30, primals_32, primals_33, primals_35,
primals_36, buf5, primals_39, primals_41, primals_42, primals_44,
primals_45, primals_47, primals_48, buf6, primals_51, primals_53,
primals_54, primals_56, primals_57, buf7, primals_60, primals_62,
primals_63, primals_65, primals_66, buf8, primals_69, primals_71,
primals_72, primals_74, primals_75, buf9, primals_78, primals_80,
primals_81, primals_83, primals_84, primals_86, primals_87, buf10,
primals_90, primals_92, primals_93, primals_95, primals_96, buf11,
primals_99, primals_101, primals_102, primals_104, primals_105,
buf12, primals_108, primals_110, primals_111, primals_113,
primals_114, buf13, primals_117, primals_119, primals_120, buf17,
buf18, buf19, reinterpret_tensor(buf20, (4, 32), (32, 1), 0),
reinterpret_tensor(buf23, (4, 32), (32, 1), 0), buf24, buf25, buf26,
buf30, buf31, buf32, reinterpret_tensor(buf33, (4, 1024), (1024, 1),
0), reinterpret_tensor(buf36, (4, 1024), (1024, 1), 0), buf40,
buf41, buf42, reinterpret_tensor(buf43, (4, 32), (32, 1), 0),
reinterpret_tensor(buf46, (4, 32), (32, 1), 0), buf47, buf51, buf52,
buf53, reinterpret_tensor(buf54, (4, 32), (32, 1), 0),
reinterpret_tensor(buf57, (4, 32), (32, 1), 0), buf58, buf62, buf63,
buf64, reinterpret_tensor(buf65, (4, 32), (32, 1), 0),
reinterpret_tensor(buf68, (4, 32), (32, 1), 0), buf70, buf74, buf75,
buf76, reinterpret_tensor(buf77, (4, 32), (32, 1), 0),
reinterpret_tensor(buf80, (4, 32), (32, 1), 0), buf81, buf85, buf86,
buf87, reinterpret_tensor(buf88, (4, 32), (32, 1), 0),
reinterpret_tensor(buf91, (4, 32), (32, 1), 0), buf92, buf96, buf97,
buf98, reinterpret_tensor(buf99, (4, 32), (32, 1), 0),
reinterpret_tensor(buf102, (4, 32), (32, 1), 0), buf103, buf107,
buf108, buf109, reinterpret_tensor(buf110, (4, 32), (32, 1), 0),
reinterpret_tensor(buf113, (4, 32), (32, 1), 0), buf114, buf118,
buf119, buf120, reinterpret_tensor(buf121, (4, 32), (32, 1), 0),
reinterpret_tensor(buf124, (4, 32), (32, 1), 0), buf125, buf129,
buf130, buf131, reinterpret_tensor(buf132, (4, 32), (32, 1), 0),
reinterpret_tensor(buf135, (4, 32), (32, 1), 0), buf136, buf140,
buf141, buf142, reinterpret_tensor(buf143, (4, 32), (32, 1), 0),
reinterpret_tensor(buf146, (4, 32), (32, 1), 0), buf147, buf151,
buf152, buf153, reinterpret_tensor(buf154, (4, 32), (32, 1), 0),
reinterpret_tensor(buf157, (4, 32), (32, 1), 0), buf158, buf162,
buf163, buf164, reinterpret_tensor(buf165, (4, 32), (32, 1), 0),
reinterpret_tensor(buf168, (4, 32), (32, 1), 0), buf169, buf173,
buf174, buf175, reinterpret_tensor(buf176, (4, 2048), (2048, 1), 0),
reinterpret_tensor(buf179, (4, 2048), (2048, 1), 0), buf183, buf184,
buf185, reinterpret_tensor(buf186, (4, 32), (32, 1), 0),
reinterpret_tensor(buf189, (4, 32), (32, 1), 0), buf190, buf194,
buf195, buf196, reinterpret_tensor(buf197, (4, 32), (32, 1), 0),
reinterpret_tensor(buf200, (4, 32), (32, 1), 0), buf201, buf205,
buf206, buf207, reinterpret_tensor(buf208, (4, 32), (32, 1), 0),
reinterpret_tensor(buf211, (4, 32), (32, 1), 0), buf213, buf217,
buf218, buf219, reinterpret_tensor(buf220, (4, 32), (32, 1), 0),
reinterpret_tensor(buf223, (4, 32), (32, 1), 0), buf224, buf228,
buf229, buf230, reinterpret_tensor(buf231, (4, 32), (32, 1), 0),
reinterpret_tensor(buf234, (4, 32), (32, 1), 0), buf235, buf239,
buf240, buf241, reinterpret_tensor(buf242, (4, 32), (32, 1), 0),
reinterpret_tensor(buf245, (4, 32), (32, 1), 0), buf246, buf250,
buf251, buf252, reinterpret_tensor(buf253, (4, 32), (32, 1), 0),
reinterpret_tensor(buf256, (4, 32), (32, 1), 0), buf257, buf261,
buf262, buf263, reinterpret_tensor(buf264, (4, 32), (32, 1), 0),
reinterpret_tensor(buf267, (4, 32), (32, 1), 0), buf268, buf272,
buf273, buf274, reinterpret_tensor(buf275, (4, 32), (32, 1), 0),
reinterpret_tensor(buf278, (4, 32), (32, 1), 0), buf279, buf283,
buf284, buf285, reinterpret_tensor(buf286, (4, 32), (32, 1), 0),
reinterpret_tensor(buf289, (4, 32), (32, 1), 0), buf290, buf294,
buf295, buf296, reinterpret_tensor(buf297, (4, 32), (32, 1), 0),
reinterpret_tensor(buf300, (4, 32), (32, 1), 0), buf301, buf305,
buf306, buf307, reinterpret_tensor(buf308, (4, 32), (32, 1), 0),
reinterpret_tensor(buf311, (4, 32), (32, 1), 0), buf312, buf316,
buf317, buf318, reinterpret_tensor(buf319, (4, 4096), (4096, 1), 0),
reinterpret_tensor(buf322, (4, 4096), (4096, 1), 0), buf326, buf327,
buf328, reinterpret_tensor(buf329, (4, 32), (32, 1), 0),
reinterpret_tensor(buf332, (4, 32), (32, 1), 0), buf333, buf337,
buf338, buf339, reinterpret_tensor(buf340, (4, 32), (32, 1), 0),
reinterpret_tensor(buf343, (4, 32), (32, 1), 0), buf344, buf348,
buf349, buf350, reinterpret_tensor(buf351, (4, 32), (32, 1), 0),
reinterpret_tensor(buf354, (4, 32), (32, 1), 0), buf356, buf360,
buf361, buf362, reinterpret_tensor(buf363, (4, 32), (32, 1), 0),
reinterpret_tensor(buf366, (4, 32), (32, 1), 0), buf367, buf371,
buf372, buf373, reinterpret_tensor(buf374, (4, 32), (32, 1), 0),
reinterpret_tensor(buf377, (4, 32), (32, 1), 0), buf378, buf382,
buf383, buf384, reinterpret_tensor(buf385, (4, 32), (32, 1), 0),
reinterpret_tensor(buf388, (4, 32), (32, 1), 0), buf389, buf393,
buf394, buf395, reinterpret_tensor(buf396, (4, 32), (32, 1), 0),
reinterpret_tensor(buf399, (4, 32), (32, 1), 0), buf400, buf404,
buf405, buf406, reinterpret_tensor(buf407, (4, 32), (32, 1), 0),
reinterpret_tensor(buf410, (4, 32), (32, 1), 0), buf411, buf415,
buf416, buf417, reinterpret_tensor(buf418, (4, 32), (32, 1), 0),
reinterpret_tensor(buf421, (4, 32), (32, 1), 0), buf422, buf426,
buf427, buf428, reinterpret_tensor(buf429, (4, 32), (32, 1), 0),
reinterpret_tensor(buf432, (4, 32), (32, 1), 0), buf433, buf437,
buf438, buf439, reinterpret_tensor(buf440, (4, 32), (32, 1), 0),
reinterpret_tensor(buf443, (4, 32), (32, 1), 0), buf444, buf448,
buf449, buf450, reinterpret_tensor(buf451, (4, 32), (32, 1), 0),
reinterpret_tensor(buf454, (4, 32), (32, 1), 0), buf456)
def conv1x1(cin, cout, stride=1, bias=False):
return StdConv2d(cin, cout, kernel_size=1, stride=stride, padding=0,
bias=bias)
def conv3x3(cin, cout, stride=1, groups=1, bias=False):
return StdConv2d(cin, cout, kernel_size=3, stride=stride, padding=1,
bias=bias, groups=groups)
def np2th(weights, conv=False):
"""Possibly convert HWIO to OIHW."""
if conv:
weights = weights.transpose([3, 2, 0, 1])
return torch.from_numpy(weights)
class StdConv2d(nn.Conv2d):
def forward(self, x):
w = self.weight
v, m = torch.var_mean(w, dim=[1, 2, 3], keepdim=True, unbiased=False)
w = (w - m) / torch.sqrt(v + 1e-05)
return F.conv2d(x, w, self.bias, self.stride, self.padding, self.
dilation, self.groups)
class PreActBottleneck(nn.Module):
"""Pre-activation (v2) bottleneck block.
"""
def __init__(self, cin, cout=None, cmid=None, stride=1):
super().__init__()
cout = cout or cin
cmid = cmid or cout // 4
self.gn1 = nn.GroupNorm(32, cmid, eps=1e-06)
self.conv1 = conv1x1(cin, cmid, bias=False)
self.gn2 = nn.GroupNorm(32, cmid, eps=1e-06)
self.conv2 = conv3x3(cmid, cmid, stride, bias=False)
self.gn3 = nn.GroupNorm(32, cout, eps=1e-06)
self.conv3 = conv1x1(cmid, cout, bias=False)
self.relu = nn.ReLU(inplace=True)
if stride != 1 or cin != cout:
self.downsample = conv1x1(cin, cout, stride, bias=False)
self.gn_proj = nn.GroupNorm(cout, cout)
def forward(self, x):
residual = x
if hasattr(self, 'downsample'):
residual = self.downsample(x)
residual = self.gn_proj(residual)
y = self.relu(self.gn1(self.conv1(x)))
y = self.relu(self.gn2(self.conv2(y)))
y = self.gn3(self.conv3(y))
y = self.relu(residual + y)
return y
def load_from(self, weights, n_block, n_unit):
conv1_weight = np2th(weights[n_block + '/' + n_unit + '/' +
'conv1/kernel'], conv=True)
conv2_weight = np2th(weights[n_block + '/' + n_unit + '/' +
'conv2/kernel'], conv=True)
conv3_weight = np2th(weights[n_block + '/' + n_unit + '/' +
'conv3/kernel'], conv=True)
gn1_weight = np2th(weights[n_block + '/' + n_unit + '/' + 'gn1/scale'])
gn1_bias = np2th(weights[n_block + '/' + n_unit + '/' + 'gn1/bias'])
gn2_weight = np2th(weights[n_block + '/' + n_unit + '/' + 'gn2/scale'])
gn2_bias = np2th(weights[n_block + '/' + n_unit + '/' + 'gn2/bias'])
gn3_weight = np2th(weights[n_block + '/' + n_unit + '/' + 'gn3/scale'])
gn3_bias = np2th(weights[n_block + '/' + n_unit + '/' + 'gn3/bias'])
self.conv1.weight.copy_(conv1_weight)
self.conv2.weight.copy_(conv2_weight)
self.conv3.weight.copy_(conv3_weight)
self.gn1.weight.copy_(gn1_weight.view(-1))
self.gn1.bias.copy_(gn1_bias.view(-1))
self.gn2.weight.copy_(gn2_weight.view(-1))
self.gn2.bias.copy_(gn2_bias.view(-1))
self.gn3.weight.copy_(gn3_weight.view(-1))
self.gn3.bias.copy_(gn3_bias.view(-1))
if hasattr(self, 'downsample'):
proj_conv_weight = np2th(weights[n_block + '/' + n_unit + '/' +
'conv_proj/kernel'], conv=True)
proj_gn_weight = np2th(weights[n_block + '/' + n_unit + '/' +
'gn_proj/scale'])
proj_gn_bias = np2th(weights[n_block + '/' + n_unit + '/' +
'gn_proj/bias'])
self.downsample.weight.copy_(proj_conv_weight)
self.gn_proj.weight.copy_(proj_gn_weight.view(-1))
self.gn_proj.bias.copy_(proj_gn_bias.view(-1))
class ResNetV2New(nn.Module):
"""Implementation of Pre-activation (v2) ResNet mode."""
def __init__(self, block_units, width_factor):
super().__init__()
width = int(64 * width_factor)
self.width = width
self.root = nn.Sequential(OrderedDict([('conv', StdConv2d(3, width,
kernel_size=7, stride=2, bias=False, padding=3)), ('gn', nn.
GroupNorm(32, width, eps=1e-06)), ('relu', nn.ReLU(inplace=True
)), ('pool', nn.MaxPool2d(kernel_size=3, stride=2, padding=0))]))
self.body = nn.Sequential(OrderedDict([('block1', nn.Sequential(
OrderedDict([('unit1', PreActBottleneck(cin=width, cout=width *
4, cmid=width))] + [(f'unit{i:d}', PreActBottleneck(cin=width *
4, cout=width * 4, cmid=width)) for i in range(2, block_units[0
] + 1)]))), ('block2', nn.Sequential(OrderedDict([('unit1',
PreActBottleneck(cin=width * 4, cout=width * 8, cmid=width * 2,
stride=2))] + [(f'unit{i:d}', PreActBottleneck(cin=width * 8,
cout=width * 8, cmid=width * 2)) for i in range(2, block_units[
1] + 1)]))), ('block3', nn.Sequential(OrderedDict([('unit1',
PreActBottleneck(cin=width * 8, cout=width * 16, cmid=width * 4,
stride=2))] + [(f'unit{i:d}', PreActBottleneck(cin=width * 16,
cout=width * 16, cmid=width * 4)) for i in range(2, block_units
[2] + 1)])))]))
def forward(self, input_0):
primals_1 = self.root.conv.weight
primals_3 = self.root.gn.weight
primals_4 = self.root.gn.bias
primals_9 = self.body.block1.unit1.gn1.weight
primals_10 = self.body.block1.unit1.gn1.bias
primals_8 = self.body.block1.unit1.conv1.weight
primals_12 = self.body.block1.unit1.gn2.weight
primals_13 = self.body.block1.unit1.gn2.bias
primals_11 = self.body.block1.unit1.conv2.weight
primals_6 = self.body.block1.unit1.gn3.weight
primals_7 = self.body.block1.unit1.gn3.bias
primals_5 = self.body.block1.unit1.conv3.weight
primals_14 = self.body.block1.unit1.downsample.weight
primals_15 = self.body.block1.unit1.gn_proj.weight
primals_16 = self.body.block1.unit1.gn_proj.bias
primals_18 = self.body.block1.unit2.gn1.weight
primals_19 = self.body.block1.unit2.gn1.bias
primals_17 = self.body.block1.unit2.conv1.weight
primals_21 = self.body.block1.unit2.gn2.weight
primals_22 = self.body.block1.unit2.gn2.bias
primals_20 = self.body.block1.unit2.conv2.weight
primals_24 = self.body.block1.unit2.gn3.weight
primals_25 = self.body.block1.unit2.gn3.bias
primals_23 = self.body.block1.unit2.conv3.weight
primals_27 = self.body.block1.unit3.gn1.weight
primals_28 = self.body.block1.unit3.gn1.bias
primals_26 = self.body.block1.unit3.conv1.weight
primals_30 = self.body.block1.unit3.gn2.weight
primals_31 = self.body.block1.unit3.gn2.bias
primals_29 = self.body.block1.unit3.conv2.weight
primals_33 = self.body.block1.unit3.gn3.weight
primals_34 = self.body.block1.unit3.gn3.bias
primals_32 = self.body.block1.unit3.conv3.weight
primals_36 = self.body.block1.unit4.gn1.weight
primals_37 = self.body.block1.unit4.gn1.bias
primals_35 = self.body.block1.unit4.conv1.weight
primals_39 = self.body.block1.unit4.gn2.weight
primals_40 = self.body.block1.unit4.gn2.bias
primals_38 = self.body.block1.unit4.conv2.weight
primals_42 = self.body.block1.unit4.gn3.weight
primals_43 = self.body.block1.unit4.gn3.bias
primals_41 = self.body.block1.unit4.conv3.weight
primals_48 = self.body.block2.unit1.gn1.weight
primals_49 = self.body.block2.unit1.gn1.bias
primals_47 = self.body.block2.unit1.conv1.weight
primals_51 = self.body.block2.unit1.gn2.weight
primals_52 = self.body.block2.unit1.gn2.bias
primals_50 = self.body.block2.unit1.conv2.weight
primals_45 = self.body.block2.unit1.gn3.weight
primals_46 = self.body.block2.unit1.gn3.bias
primals_53 = self.body.block2.unit1.conv3.weight
primals_44 = self.body.block2.unit1.downsample.weight
primals_54 = self.body.block2.unit1.gn_proj.weight
primals_55 = self.body.block2.unit1.gn_proj.bias
primals_57 = self.body.block2.unit2.gn1.weight
primals_58 = self.body.block2.unit2.gn1.bias
primals_56 = self.body.block2.unit2.conv1.weight
primals_60 = self.body.block2.unit2.gn2.weight
primals_61 = self.body.block2.unit2.gn2.bias
primals_59 = self.body.block2.unit2.conv2.weight
primals_63 = self.body.block2.unit2.gn3.weight
primals_64 = self.body.block2.unit2.gn3.bias
primals_62 = self.body.block2.unit2.conv3.weight
primals_66 = self.body.block2.unit3.gn1.weight
primals_67 = self.body.block2.unit3.gn1.bias
primals_65 = self.body.block2.unit3.conv1.weight
primals_69 = self.body.block2.unit3.gn2.weight
primals_70 = self.body.block2.unit3.gn2.bias
primals_68 = self.body.block2.unit3.conv2.weight
primals_72 = self.body.block2.unit3.gn3.weight
primals_73 = self.body.block2.unit3.gn3.bias
primals_71 = self.body.block2.unit3.conv3.weight
primals_75 = self.body.block2.unit4.gn1.weight
primals_76 = self.body.block2.unit4.gn1.bias
primals_74 = self.body.block2.unit4.conv1.weight
primals_78 = self.body.block2.unit4.gn2.weight
primals_79 = self.body.block2.unit4.gn2.bias
primals_77 = self.body.block2.unit4.conv2.weight
primals_81 = self.body.block2.unit4.gn3.weight
primals_82 = self.body.block2.unit4.gn3.bias
primals_80 = self.body.block2.unit4.conv3.weight
primals_87 = self.body.block3.unit1.gn1.weight
primals_88 = self.body.block3.unit1.gn1.bias
primals_86 = self.body.block3.unit1.conv1.weight
primals_90 = self.body.block3.unit1.gn2.weight
primals_91 = self.body.block3.unit1.gn2.bias
primals_89 = self.body.block3.unit1.conv2.weight
primals_84 = self.body.block3.unit1.gn3.weight
primals_85 = self.body.block3.unit1.gn3.bias
primals_92 = self.body.block3.unit1.conv3.weight
primals_83 = self.body.block3.unit1.downsample.weight
primals_93 = self.body.block3.unit1.gn_proj.weight
primals_94 = self.body.block3.unit1.gn_proj.bias
primals_96 = self.body.block3.unit2.gn1.weight
primals_97 = self.body.block3.unit2.gn1.bias
primals_95 = self.body.block3.unit2.conv1.weight
primals_99 = self.body.block3.unit2.gn2.weight
primals_100 = self.body.block3.unit2.gn2.bias
primals_98 = self.body.block3.unit2.conv2.weight
primals_102 = self.body.block3.unit2.gn3.weight
primals_103 = self.body.block3.unit2.gn3.bias
primals_101 = self.body.block3.unit2.conv3.weight
primals_105 = self.body.block3.unit3.gn1.weight
primals_106 = self.body.block3.unit3.gn1.bias
primals_104 = self.body.block3.unit3.conv1.weight
primals_108 = self.body.block3.unit3.gn2.weight
primals_109 = self.body.block3.unit3.gn2.bias
primals_107 = self.body.block3.unit3.conv2.weight
primals_111 = self.body.block3.unit3.gn3.weight
primals_112 = self.body.block3.unit3.gn3.bias
primals_110 = self.body.block3.unit3.conv3.weight
primals_114 = self.body.block3.unit4.gn1.weight
primals_115 = self.body.block3.unit4.gn1.bias
primals_113 = self.body.block3.unit4.conv1.weight
primals_117 = self.body.block3.unit4.gn2.weight
primals_118 = self.body.block3.unit4.gn2.bias
primals_116 = self.body.block3.unit4.conv2.weight
primals_120 = self.body.block3.unit4.gn3.weight
primals_121 = self.body.block3.unit4.gn3.bias
primals_119 = self.body.block3.unit4.conv3.weight
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,
primals_20, primals_21, primals_22, primals_23, primals_24,
primals_25, primals_26, primals_27, primals_28, primals_29,
primals_30, primals_31, primals_32, primals_33, primals_34,
primals_35, primals_36, primals_37, primals_38, primals_39,
primals_40, primals_41, primals_42, primals_43, primals_44,
primals_45, primals_46, primals_47, primals_48, primals_49,
primals_50, primals_51, primals_52, primals_53, primals_54,
primals_55, primals_56, primals_57, primals_58, primals_59,
primals_60, primals_61, primals_62, primals_63, primals_64,
primals_65, primals_66, primals_67, primals_68, primals_69,
primals_70, primals_71, primals_72, primals_73, primals_74,
primals_75, primals_76, primals_77, primals_78, primals_79,
primals_80, primals_81, primals_82, primals_83, primals_84,
primals_85, primals_86, primals_87, primals_88, primals_89,
primals_90, primals_91, primals_92, primals_93, primals_94,
primals_95, primals_96, primals_97, primals_98, primals_99,
primals_100, primals_101, primals_102, primals_103, primals_104,
primals_105, primals_106, primals_107, primals_108, primals_109,
primals_110, primals_111, primals_112, primals_113, primals_114,
primals_115, primals_116, primals_117, primals_118, primals_119,
primals_120, primals_121])
return output[0]
|
MetaMain/ViTRobust
|
ResNetV2
| false
| 17,999
|
[
"BSD-3-Clause"
] | 6
|
5bca523f430933469d9f82022e334839388cee7a
|
https://github.com/MetaMain/ViTRobust/tree/5bca523f430933469d9f82022e334839388cee7a
|
ConcatConv2d
|
import torch
import torch.utils.data
import torch.nn as nn
class ConcatConv2d(nn.Module):
def __init__(self, dim_in, dim_out, ksize=3, stride=1, padding=0,
dilation=1, groups=1, bias=True, transpose=False):
super(ConcatConv2d, self).__init__()
module = nn.ConvTranspose2d if transpose else nn.Conv2d
self._layer = module(dim_in + 1, dim_out, kernel_size=ksize, stride
=stride, padding=padding, dilation=dilation, groups=groups,
bias=bias)
def forward(self, t, x):
tt = torch.ones_like(x[:, :1, :, :]) * t
ttx = torch.cat([tt, x], 1)
return self._layer(ttx)
def get_inputs():
return [torch.rand([4, 1, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'dim_in': 4, 'dim_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
import torch.utils.data
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 320
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16 % 5
x0 = xindex % 16
x2 = xindex // 80
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 1, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 16 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 5, tl.int64)
tmp9 = tl.load(in_ptr1 + (x0 + 16 * (-1 + x1) + 64 * x2), tmp6 & xmask,
other=0.0)
tmp10 = tl.where(tmp4, tmp5, tmp9)
tl.store(out_ptr0 + x3, tmp10, xmask)
@triton.jit
def triton_poi_fused_convolution_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
x3 = xindex
x1 = xindex // 4 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 1, 4, 4), (16, 16, 4, 1))
assert_size_stride(primals_3, (4, 5, 3, 3), (45, 9, 3, 1))
assert_size_stride(primals_4, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 5, 4, 4), (80, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(320)](primals_2, primals_1, buf0, 320,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_1
del primals_2
buf1 = extern_kernels.convolution(buf0, primals_3, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf1, (4, 4, 2, 2), (16, 4, 2, 1))
buf2 = buf1
del buf1
triton_poi_fused_convolution_1[grid(64)](buf2, primals_4, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del primals_4
return buf2, primals_3, buf0
class ConcatConv2dNew(nn.Module):
def __init__(self, dim_in, dim_out, ksize=3, stride=1, padding=0,
dilation=1, groups=1, bias=True, transpose=False):
super(ConcatConv2dNew, self).__init__()
module = nn.ConvTranspose2d if transpose else nn.Conv2d
self._layer = module(dim_in + 1, dim_out, kernel_size=ksize, stride
=stride, padding=padding, dilation=dilation, groups=groups,
bias=bias)
def forward(self, input_0, input_1):
primals_3 = self._layer.weight
primals_4 = self._layer.bias
primals_2 = input_0
primals_1 = input_1
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
TevenLeScao/BasicSR
|
ConcatConv2d
| false
| 18,000
|
[
"Apache-2.0"
] | 4
|
1a7bd8754de00f3a9c9f2031acfc447350459ea0
|
https://github.com/TevenLeScao/BasicSR/tree/1a7bd8754de00f3a9c9f2031acfc447350459ea0
|
INN_loss
|
import torch
from torch import nn
class INN_loss(nn.Module):
def __init__(self, num_dim):
super(INN_loss, self).__init__()
self.num_dim = num_dim
def forward(self, Z, log_jac_det):
losses = 0.5 * torch.sum(Z ** 2, 1) - log_jac_det
loss = losses.mean() / self.num_dim
return loss
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'num_dim': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_div_mean_mul_pow_sub_sum_0(in_out_ptr0, in_ptr0,
in_ptr1, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r0 = rindex % 16
r1 = rindex // 16 % 4
r3 = rindex
tmp0 = tl.load(in_ptr0 + (r0 + 64 * r1), None, eviction_policy='evict_last'
)
tmp2 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None, eviction_policy=
'evict_last')
tmp5 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None, eviction_policy=
'evict_last')
tmp8 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None, eviction_policy=
'evict_last')
tmp13 = tl.load(in_ptr1 + r3, None)
tmp1 = tmp0 * tmp0
tmp3 = tmp2 * tmp2
tmp4 = tmp1 + tmp3
tmp6 = tmp5 * tmp5
tmp7 = tmp4 + tmp6
tmp9 = tmp8 * tmp8
tmp10 = tmp7 + tmp9
tmp11 = 0.5
tmp12 = tmp10 * tmp11
tmp14 = tmp12 - tmp13
tmp15 = tl.broadcast_to(tmp14, [RBLOCK])
tmp17 = triton_helpers.promote_to_tensor(tl.sum(tmp15, 0))
tmp18 = 256.0
tmp19 = tmp17 / tmp18
tmp20 = 0.25
tmp21 = tmp19 * tmp20
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp21, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((), (), torch.float32)
buf1 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_div_mean_mul_pow_sub_sum_0[grid(1)](buf1, arg0_1,
arg1_1, 1, 256, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
return buf1,
class INN_lossNew(nn.Module):
def __init__(self, num_dim):
super(INN_lossNew, self).__init__()
self.num_dim = num_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]
|
ThorstenBuss/jet-inn
|
INN_loss
| false
| 18,001
|
[
"Apache-2.0"
] | 4
|
3777aac712fc99aa2c48031db0c09eaebee70f37
|
https://github.com/ThorstenBuss/jet-inn/tree/3777aac712fc99aa2c48031db0c09eaebee70f37
|
Upsample
|
import torch
from torch import nn
class Upsample(nn.Module):
def __init__(self, scale_factor, mode='bilinear'):
super().__init__()
self.scale_factor = scale_factor
self.mode = mode
def forward(self, input):
return nn.functional.interpolate(input, scale_factor=self.
scale_factor, mode=self.mode, align_corners=False)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'scale_factor': 1.0}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0(
in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 4 % 4
x0 = xindex % 4
x2 = xindex // 16
x4 = xindex
tmp0 = x1
tmp1 = tmp0.to(tl.float32)
tmp2 = 0.5
tmp3 = tmp1 + tmp2
tmp4 = 1.0
tmp5 = tmp3 * tmp4
tmp6 = tmp5 - tmp2
tmp7 = 0.0
tmp8 = triton_helpers.maximum(tmp6, tmp7)
tmp9 = tmp8.to(tl.int32)
tmp10 = tl.full([1], 1, tl.int64)
tmp11 = tmp9 + tmp10
tmp12 = tl.full([1], 3, tl.int64)
tmp13 = triton_helpers.minimum(tmp11, tmp12)
tmp14 = x0
tmp15 = tmp14.to(tl.float32)
tmp16 = tmp15 + tmp2
tmp17 = tmp16 * tmp4
tmp18 = tmp17 - tmp2
tmp19 = triton_helpers.maximum(tmp18, tmp7)
tmp20 = tmp19.to(tl.int32)
tmp21 = tmp20 + tmp10
tmp22 = triton_helpers.minimum(tmp21, tmp12)
tmp23 = tl.load(in_ptr0 + (tmp22 + 4 * tmp13 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp24 = tl.load(in_ptr0 + (tmp20 + 4 * tmp13 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp25 = tmp23 - tmp24
tmp26 = tmp20.to(tl.float32)
tmp27 = tmp19 - tmp26
tmp28 = triton_helpers.maximum(tmp27, tmp7)
tmp29 = triton_helpers.minimum(tmp28, tmp4)
tmp30 = tmp25 * tmp29
tmp31 = tmp24 + tmp30
tmp32 = tl.load(in_ptr0 + (tmp20 + 4 * tmp9 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp33 = tl.load(in_ptr0 + (tmp22 + 4 * tmp9 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp34 = tmp33 - tmp32
tmp35 = tmp34 * tmp29
tmp36 = tmp32 + tmp35
tmp37 = tmp31 - tmp36
tmp38 = tmp9.to(tl.float32)
tmp39 = tmp8 - tmp38
tmp40 = triton_helpers.maximum(tmp39, tmp7)
tmp41 = triton_helpers.minimum(tmp40, tmp4)
tmp42 = tmp37 * tmp41
tmp43 = tmp36 + tmp42
tl.store(in_out_ptr0 + x4, tmp43, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf1 = buf0
del buf0
buf2 = buf1
del buf1
get_raw_stream(0)
triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0[grid
(256)](buf2, arg0_1, 256, XBLOCK=128, num_warps=4, num_stages=1)
del arg0_1
return buf2,
class UpsampleNew(nn.Module):
def __init__(self, scale_factor, mode='bilinear'):
super().__init__()
self.scale_factor = scale_factor
self.mode = mode
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
Tomaz-Vieira/tiktorch
|
Upsample
| false
| 18,002
|
[
"MIT"
] | 8
|
2d6803c4ba5e26e4b27bf8af6638040fa4fc5628
|
https://github.com/Tomaz-Vieira/tiktorch/tree/2d6803c4ba5e26e4b27bf8af6638040fa4fc5628
|
SelfAttention
|
import torch
import torch.nn.functional as F
import torch.nn as nn
class SelfAttention(nn.Module):
def __init__(self, input_size, heads, embed_size):
super().__init__()
self.input_size = input_size
self.heads = heads
self.emb_size = embed_size
self.tokeys = nn.Linear(self.input_size, self.emb_size * heads,
bias=False)
self.toqueries = nn.Linear(self.input_size, self.emb_size * heads,
bias=False)
self.tovalues = nn.Linear(self.input_size, self.emb_size * heads,
bias=False)
def forward(self, x):
b, t, hin = x.size()
assert hin == self.input_size, 'Input size {hin} should match {self.input_size}'
h = self.heads
e = self.emb_size
keys = self.tokeys(x).view(b, t, h, e)
queries = self.toqueries(x).view(b, t, h, e)
values = self.tovalues(x).view(b, t, h, e)
keys = keys.transpose(1, 2).contiguous().view(b * h, t, e)
queries = queries.transpose(1, 2).contiguous().view(b * h, t, e)
values = values.transpose(1, 2).contiguous().view(b * h, t, e)
queries = queries / e ** (1 / 4)
keys = keys / e ** (1 / 4)
dot = torch.bmm(queries, keys.transpose(1, 2))
assert dot.size() == (b * h, t, t)
dot = F.softmax(dot, dim=2)
out = torch.bmm(dot, values).view(b, h, t, e)
out = out.transpose(1, 2).contiguous().view(b, t, h * e)
return out
def get_inputs():
return [torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'input_size': 4, 'heads': 4, 'embed_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_div_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4 % 16
x2 = xindex // 64
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4 * (x1 % 4) + 16 * x2 + 64 * (x1 // 4)),
xmask)
tmp1 = 0.7071067811865475
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x3, tmp2, xmask)
@triton.jit
def triton_poi_fused_div_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4 % 4
x2 = xindex // 16
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4 * (x2 % 4) + 16 * x1 + 64 * (x2 // 4)),
xmask)
tmp1 = 0.7071067811865475
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x3, tmp2, xmask)
@triton.jit
def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = 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_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused_clone_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4 % 4
x2 = xindex // 16 % 4
x3 = xindex // 64
x4 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), xmask)
tl.store(out_ptr0 + x4, tmp0, xmask)
@triton.jit
def triton_poi_fused_transpose_5(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4 % 4
x2 = xindex // 16
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 64 * x1), xmask)
tl.store(out_ptr0 + x3, tmp0, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (16, 4), (4, 1))
assert_size_stride(primals_3, (16, 4), (4, 1))
assert_size_stride(primals_4, (16, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((16, 16), (16, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_2, (4, 16), (1, 4), 0), out=buf0)
del primals_2
buf1 = empty_strided_cuda((16, 16), (16, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_3, (4, 16), (1, 4), 0), out=buf1)
del primals_3
buf2 = empty_strided_cuda((16, 16), (16, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_4, (4, 16), (1, 4), 0), out=buf2)
del primals_4
buf3 = empty_strided_cuda((16, 4, 4), (4, 64, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_div_0[grid(256)](buf1, buf3, 256, XBLOCK=128,
num_warps=4, num_stages=1)
buf4 = reinterpret_tensor(buf1, (16, 4, 4), (16, 4, 1), 0)
del buf1
triton_poi_fused_div_1[grid(256)](buf0, buf4, 256, XBLOCK=256,
num_warps=4, num_stages=1)
buf5 = reinterpret_tensor(buf0, (16, 4, 4), (16, 4, 1), 0)
del buf0
extern_kernels.bmm(buf3, reinterpret_tensor(buf4, (16, 4, 4), (16,
1, 4), 0), out=buf5)
buf6 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_2[grid(256)](buf5, buf6, 256, XBLOCK=256,
num_warps=4, num_stages=1)
buf7 = buf5
del buf5
triton_poi_fused__softmax_3[grid(256)](buf6, buf7, 256, XBLOCK=128,
num_warps=4, num_stages=1)
buf8 = reinterpret_tensor(buf6, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf6
triton_poi_fused_clone_4[grid(256)](buf2, buf8, 256, XBLOCK=256,
num_warps=4, num_stages=1)
buf9 = reinterpret_tensor(buf2, (16, 4, 4), (16, 4, 1), 0)
del buf2
extern_kernels.bmm(buf7, reinterpret_tensor(buf8, (16, 4, 4), (16,
4, 1), 0), out=buf9)
buf10 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_clone_4[grid(256)](buf9, buf10, 256, XBLOCK=256,
num_warps=4, num_stages=1)
buf11 = reinterpret_tensor(buf9, (16, 4, 4), (16, 1, 4), 0)
del buf9
triton_poi_fused_transpose_5[grid(256)](buf3, buf11, 256, XBLOCK=
256, num_warps=4, num_stages=1)
del buf3
return reinterpret_tensor(buf10, (4, 4, 16), (64, 16, 1), 0
), reinterpret_tensor(primals_1, (16, 4), (4, 1), 0
), buf7, reinterpret_tensor(buf8, (16, 4, 4), (16, 1, 4), 0
), buf11, buf4
class SelfAttentionNew(nn.Module):
def __init__(self, input_size, heads, embed_size):
super().__init__()
self.input_size = input_size
self.heads = heads
self.emb_size = embed_size
self.tokeys = nn.Linear(self.input_size, self.emb_size * heads,
bias=False)
self.toqueries = nn.Linear(self.input_size, self.emb_size * heads,
bias=False)
self.tovalues = nn.Linear(self.input_size, self.emb_size * heads,
bias=False)
def forward(self, input_0):
primals_2 = self.tokeys.weight
primals_3 = self.toqueries.weight
primals_4 = self.tovalues.weight
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
Sud0x67/mrmix
|
SelfAttention
| false
| 18,003
|
[
"Apache-2.0"
] | 4
|
4f4784e421c768509bd007e21b4455b56edc7cd2
|
https://github.com/Sud0x67/mrmix/tree/4f4784e421c768509bd007e21b4455b56edc7cd2
|
Conv2dTime
|
import torch
import torch.utils.data
import torch.nn as nn
class Conv2dTime(nn.Conv2d):
"""
Implements time dependent 2d convolutions, by appending the time variable as
an extra channel.
"""
def __init__(self, in_channels, *args, **kwargs):
super(Conv2dTime, self).__init__(in_channels + 1, *args, **kwargs)
def forward(self, t, x):
t_img = torch.ones_like(x[:, :1, :, :]) * t
t_and_x = torch.cat([t_img, x], 1)
return super(Conv2dTime, self).forward(t_and_x)
def get_inputs():
return [torch.rand([4, 1, 4, 4]), 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.utils.data
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 320
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16 % 5
x0 = xindex % 16
x2 = xindex // 80
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 1, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 16 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 5, tl.int64)
tmp9 = tl.load(in_ptr1 + (x0 + 16 * (-1 + x1) + 64 * x2), tmp6 & xmask,
other=0.0)
tmp10 = tl.where(tmp4, tmp5, tmp9)
tl.store(out_ptr0 + x3, tmp10, xmask)
@triton.jit
def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x2, tmp2, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 1, 4, 4), (16, 16, 4, 1))
assert_size_stride(primals_3, (4, 5, 4, 4), (80, 16, 4, 1))
assert_size_stride(primals_4, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 5, 4, 4), (80, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(320)](primals_2, primals_1, buf0, 320,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_1
del primals_2
buf1 = extern_kernels.convolution(buf0, primals_3, stride=(1, 1),
padding=(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))
buf2 = buf1
del buf1
triton_poi_fused_convolution_1[grid(16)](buf2, primals_4, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del primals_4
return buf2, primals_3, buf0
class Conv2dTimeNew(nn.Conv2d):
"""
Implements time dependent 2d convolutions, by appending the time variable as
an extra channel.
"""
def __init__(self, in_channels, *args, **kwargs):
super(Conv2dTimeNew, self).__init__(in_channels + 1, *args, **kwargs)
def forward(self, input_0, input_1):
primals_3 = self.weight
primals_4 = self.bias
primals_2 = input_0
primals_1 = input_1
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
TevenLeScao/BasicSR
|
Conv2dTime
| false
| 18,004
|
[
"Apache-2.0"
] | 4
|
1a7bd8754de00f3a9c9f2031acfc447350459ea0
|
https://github.com/TevenLeScao/BasicSR/tree/1a7bd8754de00f3a9c9f2031acfc447350459ea0
|
ResBlock
|
import torch
import torch.utils.data
import torch.nn as nn
def norm(dim):
return nn.GroupNorm(min(32, dim), dim)
def conv3x3(in_planes, out_planes, stride=1):
"""3x3 convolution with padding"""
return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride,
padding=1, bias=False)
class ResBlock(nn.Module):
expansion = 1
def __init__(self, inplanes, planes, stride=1, downsample=None):
super(ResBlock, self).__init__()
self.norm1 = norm(inplanes)
self.relu = nn.ReLU(inplace=True)
self.downsample = downsample
self.conv1 = conv3x3(inplanes, planes, stride)
self.norm2 = norm(planes)
self.conv2 = conv3x3(planes, planes)
def forward(self, x):
shortcut = x
out = self.relu(self.norm1(x))
if self.downsample is not None:
shortcut = self.downsample(out)
out = self.conv1(out)
out = self.norm2(out)
out = self.relu(out)
out = self.conv2(out)
return out + shortcut
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'inplanes': 4, 'planes': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
import torch.utils.data
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_per_fused_native_group_norm_relu_0(in_ptr0, in_ptr1, in_ptr2,
out_ptr0, out_ptr2, out_ptr3, xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
x2 = xindex % 4
tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
tmp24 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last')
tmp26 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last')
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tl.where(xmask, tmp1, 0)
tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp6 = tl.where(xmask, tmp4, 0)
tmp7 = tl.sum(tmp6, 1)[:, None]
tmp8 = tl.full([XBLOCK, 1], 16, tl.int32)
tmp9 = tmp8.to(tl.float32)
tmp10 = tmp7 / tmp9
tmp11 = tmp1 - tmp10
tmp12 = tmp11 * tmp11
tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK])
tmp15 = tl.where(xmask, tmp13, 0)
tmp16 = tl.sum(tmp15, 1)[:, None]
tmp17 = tmp0 - tmp10
tmp18 = 16.0
tmp19 = tmp16 / tmp18
tmp20 = 1e-05
tmp21 = tmp19 + tmp20
tmp22 = libdevice.rsqrt(tmp21)
tmp23 = tmp17 * tmp22
tmp25 = tmp23 * tmp24
tmp27 = tmp25 + tmp26
tmp28 = tl.full([1, 1], 0, tl.int32)
tmp29 = triton_helpers.maximum(tmp28, tmp27)
tl.store(out_ptr2 + (r1 + 16 * x0), tmp29, xmask)
tl.store(out_ptr3 + x0, tmp22, xmask)
tl.store(out_ptr0 + x0, tmp10, xmask)
@triton.jit
def triton_poi_fused_add_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
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x0, tmp2, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (4,), (1,))
assert_size_stride(primals_7, (4, 4, 3, 3), (36, 9, 3, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32)
buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf12 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32)
get_raw_stream(0)
triton_per_fused_native_group_norm_relu_0[grid(16)](primals_1,
primals_2, primals_3, buf0, buf3, buf12, 16, 16, XBLOCK=8,
num_warps=2, num_stages=1)
del primals_2
del primals_3
buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 4, 4, 4), (64, 16, 4, 1))
buf5 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32)
buf9 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf8 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32)
triton_per_fused_native_group_norm_relu_0[grid(16)](buf4, primals_5,
primals_6, buf5, buf9, buf8, 16, 16, XBLOCK=8, num_warps=2,
num_stages=1)
del primals_6
buf10 = extern_kernels.convolution(buf9, primals_7, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf10, (4, 4, 4, 4), (64, 16, 4, 1))
buf11 = buf10
del buf10
triton_poi_fused_add_1[grid(256)](buf11, primals_1, 256, XBLOCK=256,
num_warps=4, num_stages=1)
return (buf11, primals_1, primals_4, primals_5, primals_7, buf3, buf4,
reinterpret_tensor(buf5, (4, 4), (4, 1), 0), reinterpret_tensor(
buf8, (4, 4), (4, 1), 0), buf9, reinterpret_tensor(buf0, (4, 4, 1),
(4, 1, 1), 0), reinterpret_tensor(buf12, (4, 4, 1), (4, 1, 1), 0))
def norm(dim):
return nn.GroupNorm(min(32, dim), dim)
def conv3x3(in_planes, out_planes, stride=1):
"""3x3 convolution with padding"""
return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride,
padding=1, bias=False)
class ResBlockNew(nn.Module):
expansion = 1
def __init__(self, inplanes, planes, stride=1, downsample=None):
super(ResBlockNew, self).__init__()
self.norm1 = norm(inplanes)
self.relu = nn.ReLU(inplace=True)
self.downsample = downsample
self.conv1 = conv3x3(inplanes, planes, stride)
self.norm2 = norm(planes)
self.conv2 = conv3x3(planes, planes)
def forward(self, input_0):
primals_2 = self.norm1.weight
primals_3 = self.norm1.bias
primals_4 = self.conv1.weight
primals_5 = self.norm2.weight
primals_6 = self.norm2.bias
primals_7 = self.conv2.weight
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7])
return output[0]
|
TevenLeScao/BasicSR
|
ResBlock
| false
| 18,005
|
[
"Apache-2.0"
] | 4
|
1a7bd8754de00f3a9c9f2031acfc447350459ea0
|
https://github.com/TevenLeScao/BasicSR/tree/1a7bd8754de00f3a9c9f2031acfc447350459ea0
|
LayerNorm
|
import torch
import torch.nn as nn
class LayerNorm(nn.LayerNorm):
def __init__(self, normalized_shape, eps=1e-05, elementwise_affine=True):
"""Layer Norm."""
super(LayerNorm, self).__init__(normalized_shape, eps=eps,
elementwise_affine=elementwise_affine)
def forward(self, x):
x = x.permute(0, 2, 1)
y = super(LayerNorm, self).forward(x)
y = y.permute(0, 2, 1)
return y
def get_inputs():
return [torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'normalized_shape': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_native_layer_norm_0(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 16 * x1), xmask)
tmp1 = tl.load(in_ptr0 + (4 + x0 + 16 * x1), xmask)
tmp3 = tl.load(in_ptr0 + (8 + x0 + 16 * x1), xmask)
tmp5 = tl.load(in_ptr0 + (12 + x0 + 16 * x1), xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp7 = 4.0
tmp8 = tmp6 / tmp7
tmp9 = tmp0 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tmp1 - tmp8
tmp12 = tmp11 * tmp11
tmp13 = tmp10 + tmp12
tmp14 = tmp3 - tmp8
tmp15 = tmp14 * tmp14
tmp16 = tmp13 + tmp15
tmp17 = tmp5 - tmp8
tmp18 = tmp17 * tmp17
tmp19 = tmp16 + tmp18
tmp20 = tmp19 / tmp7
tmp21 = 1e-05
tmp22 = tmp20 + tmp21
tmp23 = libdevice.rsqrt(tmp22)
tl.store(out_ptr0 + x2, tmp8, xmask)
tl.store(out_ptr1 + x2, tmp23, xmask)
@triton.jit
def triton_poi_fused_native_layer_norm_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
in_ptr4, 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 + y3, ymask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + y3, ymask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr3 + x2, xmask, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr4 + x2, xmask, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = tmp2 * tmp3
tmp6 = tmp4 * tmp5
tmp8 = tmp6 + tmp7
tl.store(out_ptr0 + (x2 + 4 * y3), tmp8, xmask & ymask)
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,), (1,))
assert_size_stride(primals_3, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
buf1 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
get_raw_stream(0)
triton_poi_fused_native_layer_norm_0[grid(16)](primals_1, buf0,
buf1, 16, XBLOCK=16, num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_native_layer_norm_1[grid(16, 4)](primals_1, buf0,
buf1, primals_2, primals_3, buf2, 16, 4, XBLOCK=4, YBLOCK=8,
num_warps=1, num_stages=1)
del buf0
del buf1
del primals_2
del primals_3
return reinterpret_tensor(buf2, (4, 4, 4), (16, 1, 4), 0), primals_1
class LayerNormNew(nn.LayerNorm):
def __init__(self, normalized_shape, eps=1e-05, elementwise_affine=True):
"""Layer Norm."""
super(LayerNormNew, self).__init__(normalized_shape, eps=eps,
elementwise_affine=elementwise_affine)
def forward(self, input_0):
primals_2 = self.weight
primals_3 = self.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
TraceOnBrainOff/pytorch-dc-tts
|
LayerNorm
| false
| 18,006
|
[
"MIT"
] | 4
|
993a0fbace561729b04df2179b41a0a7ea502e93
|
https://github.com/TraceOnBrainOff/pytorch-dc-tts/tree/993a0fbace561729b04df2179b41a0a7ea502e93
|
CrossEntropy
|
import torch
import torch.nn as nn
from torch.nn import functional as F
import torch.optim
class CrossEntropy(nn.Module):
def __init__(self, ignore_label=-1, weight=None, reduction='mean'):
super(CrossEntropy, self).__init__()
self.ignore_label = ignore_label
self.criterion = nn.CrossEntropyLoss(weight=weight, ignore_index=
ignore_label, reduction=reduction)
def forward(self, score, target):
ph, pw = score.size(2), score.size(3)
h, w = target.size(1), target.size(2)
if ph != h or pw != w:
score = F.interpolate(score, size=(h, w), mode='bilinear',
align_corners=False)
loss = self.criterion(score, target)
return loss
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
import torch.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__log_softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tl.store(out_ptr0 + x3, tmp8, xmask)
@triton.jit
def triton_per_fused__log_softmax_div_mul_neg_sum_1(in_out_ptr0, in_ptr0,
in_ptr1, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r3 = rindex
r0 = rindex % 16
r2 = rindex // 64
tmp0 = tl.load(in_ptr0 + r3, None)
tmp1 = tl.load(in_ptr0 + (r0 + 64 * r2), None, eviction_policy='evict_last'
)
tmp3 = tl.load(in_ptr0 + (16 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (32 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr0 + (48 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp14 = tl.load(in_ptr1 + r3, None)
tmp2 = tl_math.exp(tmp1)
tmp4 = tl_math.exp(tmp3)
tmp5 = tmp2 + tmp4
tmp7 = tl_math.exp(tmp6)
tmp8 = tmp5 + tmp7
tmp10 = tl_math.exp(tmp9)
tmp11 = tmp8 + tmp10
tmp12 = tl_math.log(tmp11)
tmp13 = tmp0 - tmp12
tmp15 = tmp13 * tmp14
tmp16 = tl.broadcast_to(tmp15, [RBLOCK])
tmp18 = triton_helpers.promote_to_tensor(tl.sum(tmp16, 0))
tmp19 = -tmp18
tmp20 = 0.015625
tmp21 = tmp19 * tmp20
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp21, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__log_softmax_0[grid(256)](arg0_1, buf0, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del arg0_1
buf1 = empty_strided_cuda((), (), torch.float32)
buf2 = buf1
del buf1
triton_per_fused__log_softmax_div_mul_neg_sum_1[grid(1)](buf2, buf0,
arg1_1, 1, 256, num_warps=2, num_stages=1)
del arg1_1
del buf0
return buf2,
class CrossEntropyNew(nn.Module):
def __init__(self, ignore_label=-1, weight=None, reduction='mean'):
super(CrossEntropyNew, self).__init__()
self.ignore_label = ignore_label
self.criterion = nn.CrossEntropyLoss(weight=weight, ignore_index=
ignore_label, reduction=reduction)
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
TotalVariation/Flattenet
|
CrossEntropy
| false
| 18,007
|
[
"MIT"
] | 3
|
828d1f95f6f77dd0b681318f2a544e84cf4be834
|
https://github.com/TotalVariation/Flattenet/tree/828d1f95f6f77dd0b681318f2a544e84cf4be834
|
DistillLoss
|
import torch
import torch.nn as nn
class DistillLoss(nn.Module):
def __init__(self):
super(DistillLoss, self).__init__()
def forward(self, t_feat, feat, cams):
assert len(cams) == feat.shape[0] and feat.shape[0] == t_feat.shape[0]
t_feat = t_feat / t_feat.norm(p=2, dim=1, keepdim=True)
t_dist = self.cdist(t_feat, t_feat)
feat = feat / feat.norm(p=2, dim=1, keepdim=True)
dist = self.cdist(feat, feat)
same_cam_mask = torch.eq(cams.unsqueeze(1), cams.unsqueeze(0)).float()
for i in range(len(same_cam_mask)):
same_cam_mask[i, i] = 0
same_cam_mask = same_cam_mask if cams.is_cuda else same_cam_mask
diff = (t_dist - dist) * same_cam_mask
mse_loss = torch.norm(diff) / feat.shape[0]
return mse_loss
def cdist(self, a, b):
"""
Returns euclidean distance between (all feature pairs) in a and b
Args:
a (2D Tensor): A batch of vectors shaped (B1, D)
b (2D Tensor): A batch of vectors shaped (B2, D)
Returns:
A matrix of all pairwise distance between all vectors in a and b,
will be shape of (B1, B2)
"""
diff = a.unsqueeze(1) - b.unsqueeze(0)
return ((diff ** 2).sum(2) + 1e-12).sqrt()
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand(
[4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_div_linalg_vector_norm_0(in_ptr0, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = tmp0 / tmp12
tl.store(out_ptr0 + x3, tmp13, xmask)
@triton.jit
def triton_poi_fused_add_pow_sqrt_sub_sum_1(in_ptr0, in_ptr1, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 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_ptr0 + (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_ptr0 + (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_ptr0 + (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_ptr0 + (48 + x0 + 64 * x1), xmask, eviction_policy=
'evict_last')
tmp22 = tl.load(in_ptr1 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp23 = tl.load(in_ptr1 + (x0 + 64 * x1), xmask, eviction_policy=
'evict_last')
tmp26 = tl.load(in_ptr1 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp27 = tl.load(in_ptr1 + (16 + x0 + 64 * x1), xmask, eviction_policy=
'evict_last')
tmp31 = tl.load(in_ptr1 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp32 = tl.load(in_ptr1 + (32 + x0 + 64 * x1), xmask, eviction_policy=
'evict_last')
tmp36 = tl.load(in_ptr1 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp37 = tl.load(in_ptr1 + (48 + x0 + 64 * x1), xmask, eviction_policy=
'evict_last')
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 = 1e-12
tmp20 = tmp18 + tmp19
tmp21 = libdevice.sqrt(tmp20)
tmp24 = tmp22 - tmp23
tmp25 = tmp24 * tmp24
tmp28 = tmp26 - tmp27
tmp29 = tmp28 * tmp28
tmp30 = tmp25 + tmp29
tmp33 = tmp31 - tmp32
tmp34 = tmp33 * tmp33
tmp35 = tmp30 + tmp34
tmp38 = tmp36 - tmp37
tmp39 = tmp38 * tmp38
tmp40 = tmp35 + tmp39
tmp41 = tmp40 + tmp19
tmp42 = libdevice.sqrt(tmp41)
tmp43 = tmp21 - tmp42
tl.store(out_ptr0 + x3, tmp43, xmask)
@triton.jit
def triton_poi_fused__to_copy_eq_fill_lift_fresh_2(in_ptr0, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex // 256
x1 = xindex // 64 % 4
x0 = xindex % 64
x3 = xindex % 256
x5 = xindex
tmp11 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last')
tmp17 = tl.load(in_ptr0 + (64 + x0), xmask, eviction_policy='evict_last')
tmp23 = tl.load(in_ptr0 + (128 + x0), xmask, eviction_policy='evict_last')
tmp31 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp0 = x2
tmp1 = tl.full([1], 2, tl.int32)
tmp2 = tmp0 == tmp1
tmp3 = x1
tmp4 = tmp3 == tmp1
tmp5 = tl.full([1], 1, tl.int32)
tmp6 = tmp1 == tmp5
tmp7 = tmp3 == tmp5
tmp8 = tl.full([1], 0, tl.int32)
tmp9 = tmp5 == tmp8
tmp10 = tmp3 == tmp8
tmp13 = tmp11 == tmp12
tmp14 = tmp13.to(tl.float32)
tmp15 = 0.0
tmp16 = tl.where(tmp10, tmp15, tmp14)
tmp18 = tmp17 == tmp12
tmp19 = tmp18.to(tl.float32)
tmp20 = tl.where(tmp9, tmp16, tmp19)
tmp21 = tl.where(tmp7, tmp15, tmp20)
tmp22 = tmp1 == tmp8
tmp24 = tmp23 == tmp12
tmp25 = tmp24.to(tl.float32)
tmp26 = tl.where(tmp22, tmp16, tmp25)
tmp27 = tl.where(tmp6, tmp21, tmp26)
tmp28 = tl.where(tmp4, tmp15, tmp27)
tmp29 = tmp0 == tmp5
tmp30 = tmp0 == tmp8
tmp32 = tmp31 == tmp12
tmp33 = tmp32.to(tl.float32)
tmp34 = tl.where(tmp30, tmp16, tmp33)
tmp35 = tl.where(tmp29, tmp21, tmp34)
tmp36 = tl.where(tmp2, tmp28, tmp35)
tl.store(out_ptr0 + x5, tmp36, xmask)
@triton.jit
def triton_per_fused_div_fill_lift_fresh_linalg_vector_norm_mul_3(in_out_ptr0,
in_ptr0, in_ptr1, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 1024
xoffset = tl.program_id(0) * XBLOCK
tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r3 = rindex % 256
r2 = rindex // 256
r1 = rindex // 64 % 4
r4 = rindex
tmp0 = tl.load(in_ptr0 + r3, None, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr1 + (768 + r3), None, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr1 + r4, None)
tmp1 = r2
tmp2 = tl.full([1], 3, tl.int32)
tmp3 = tmp1 == tmp2
tmp4 = r1
tmp5 = tmp4 == tmp2
tmp7 = 0.0
tmp8 = tl.where(tmp5, tmp7, tmp6)
tmp10 = tl.where(tmp3, tmp8, tmp9)
tmp11 = tmp0 * tmp10
tmp12 = tmp11 * tmp11
tmp13 = tl.broadcast_to(tmp12, [RBLOCK])
tmp15 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0))
tmp16 = libdevice.sqrt(tmp15)
tmp17 = 0.25
tmp18 = tmp16 * tmp17
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp18, None)
def call(args):
arg0_1, arg1_1, arg2_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_div_linalg_vector_norm_0[grid(256)](arg2_1, buf0,
256, XBLOCK=128, num_warps=4, num_stages=1)
del arg2_1
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_div_linalg_vector_norm_0[grid(256)](arg1_1, buf1,
256, XBLOCK=128, num_warps=4, num_stages=1)
del arg1_1
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_add_pow_sqrt_sub_sum_1[grid(256)](buf0, buf1, buf2,
256, XBLOCK=128, num_warps=4, num_stages=1)
del buf0
del buf1
buf3 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1),
torch.float32)
triton_poi_fused__to_copy_eq_fill_lift_fresh_2[grid(1024)](arg0_1,
buf3, 1024, XBLOCK=256, num_warps=4, num_stages=1)
del arg0_1
buf4 = empty_strided_cuda((), (), torch.float32)
buf5 = buf4
del buf4
triton_per_fused_div_fill_lift_fresh_linalg_vector_norm_mul_3[grid(1)](
buf5, buf2, buf3, 1, 1024, num_warps=8, num_stages=1)
del buf2
del buf3
return buf5,
class DistillLossNew(nn.Module):
def __init__(self):
super(DistillLossNew, self).__init__()
def cdist(self, a, b):
"""
Returns euclidean distance between (all feature pairs) in a and b
Args:
a (2D Tensor): A batch of vectors shaped (B1, D)
b (2D Tensor): A batch of vectors shaped (B2, D)
Returns:
A matrix of all pairwise distance between all vectors in a and b,
will be shape of (B1, B2)
"""
diff = a.unsqueeze(1) - b.unsqueeze(0)
return ((diff ** 2).sum(2) + 1e-12).sqrt()
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]
|
Terminator8758/Precise-ICS-master
|
DistillLoss
| false
| 18,009
|
[
"MIT"
] | 4
|
9f4591fee6ab64d9dd91f551355d29562bf663cb
|
https://github.com/Terminator8758/Precise-ICS-master/tree/9f4591fee6ab64d9dd91f551355d29562bf663cb
|
Coral
|
import torch
import torch.nn as nn
import torch.nn.init
class Coral(nn.Module):
def __init__(self):
super(Coral, self).__init__()
def forward(self, a, b):
"""
Arguments:
a: a float tensor with shape [n, d].
b: a float tensor with shape [m, d].
Returns:
a float tensor with shape [].
"""
d = a.size(1)
a = a - a.mean(0)
b = b - b.mean(0)
cs = torch.matmul(a.t(), a)
ct = torch.matmul(b.t(), b)
normalizer = 4 * d * d
return ((cs - ct) ** 2).sum() / normalizer
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.nn as nn
import torch.nn.init
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_mean_sub_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (4 + x0), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (8 + x0), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (12 + x0), xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = 4.0
tmp9 = tmp7 / tmp8
tmp10 = tmp0 - tmp9
tl.store(out_ptr0 + x2, tmp10, xmask)
@triton.jit
def triton_per_fused_div_pow_sub_sum_1(in_out_ptr0, in_ptr0, in_ptr1,
xnumel, rnumel, XBLOCK: tl.constexpr):
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp1 = tl.load(in_ptr1 + r0, None)
tmp2 = tmp0 - tmp1
tmp3 = tmp2 * tmp2
tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
tmp6 = tl.sum(tmp4, 1)[:, None]
tmp7 = 0.015625
tmp8 = tmp6 * tmp7
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp8, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4), (4, 1))
assert_size_stride(arg1_1, (4, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_mean_sub_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(reinterpret_tensor(buf0, (4, 4), (1, 4), 0), buf0,
out=buf1)
buf2 = buf0
del buf0
triton_poi_fused_mean_sub_0[grid(16)](arg1_1, buf2, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del arg1_1
buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf2, (4, 4), (1, 4), 0), buf2,
out=buf3)
del buf2
buf4 = empty_strided_cuda((), (), torch.float32)
buf5 = buf4
del buf4
triton_per_fused_div_pow_sub_sum_1[grid(1)](buf5, buf1, buf3, 1, 16,
XBLOCK=1, num_warps=2, num_stages=1)
del buf1
del buf3
return buf5,
class CoralNew(nn.Module):
def __init__(self):
super(CoralNew, 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]
|
TropComplique/associative-domain-adaptation
|
Coral
| false
| 18,010
|
[
"MIT"
] | 8
|
a2ec0a9e678af20624f79e40c8042c969a69e8f3
|
https://github.com/TropComplique/associative-domain-adaptation/tree/a2ec0a9e678af20624f79e40c8042c969a69e8f3
|
TotalVariationLoss
|
import torch
import torch.nn as nn
class TotalVariationLoss(nn.Module):
def __init__(self):
super(TotalVariationLoss, self).__init__()
def forward(self, x):
"""
Arguments:
x: a float tensor with shape [b, 3, h, w].
It represents a RGB image with pixel values in [0, 1] range.
Returns:
a float tensor with shape [].
"""
h, w = x.size()[2:]
h_tv = torch.pow(x[:, :, 1:, :] - x[:, :, :h - 1, :], 2)
w_tv = torch.pow(x[:, :, :, 1:] - x[:, :, :, :w - 1], 2)
return h_tv.mean([0, 1, 2, 3]) + w_tv.mean([0, 1, 2, 3])
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_per_fused_add_mean_pow_sub_0(in_out_ptr0, in_ptr0, xnumel,
rnumel, XBLOCK: tl.constexpr):
rnumel = 192
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
rmask = rindex < rnumel
r0 = rindex % 12
r1 = rindex // 12
r2 = rindex % 3
r3 = rindex // 3
tmp0 = tl.load(in_ptr0 + (4 + r0 + 16 * r1), rmask, other=0.0)
tmp1 = tl.load(in_ptr0 + (r0 + 16 * r1), rmask, other=0.0)
tmp8 = tl.load(in_ptr0 + (1 + r2 + 4 * r3), rmask, other=0.0)
tmp9 = tl.load(in_ptr0 + (r2 + 4 * r3), rmask, other=0.0)
tmp2 = tmp0 - tmp1
tmp3 = tmp2 * tmp2
tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
tmp6 = tl.where(rmask, tmp4, 0)
tmp7 = tl.sum(tmp6, 1)[:, None]
tmp10 = tmp8 - tmp9
tmp11 = tmp10 * tmp10
tmp12 = tl.broadcast_to(tmp11, [XBLOCK, RBLOCK])
tmp14 = tl.where(rmask, tmp12, 0)
tmp15 = tl.sum(tmp14, 1)[:, None]
tmp16 = 192.0
tmp17 = tmp7 / tmp16
tmp18 = tmp15 / tmp16
tmp19 = tmp17 + tmp18
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp19, 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)
buf2 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_add_mean_pow_sub_0[grid(1)](buf2, arg0_1, 1, 192,
XBLOCK=1, num_warps=2, num_stages=1)
del arg0_1
return buf2,
class TotalVariationLossNew(nn.Module):
def __init__(self):
super(TotalVariationLossNew, self).__init__()
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
TropComplique/CNNMRF
|
TotalVariationLoss
| false
| 18,011
|
[
"MIT"
] | 3
|
602f861b14ed240acac89e6502e69f797d4f4a49
|
https://github.com/TropComplique/CNNMRF/tree/602f861b14ed240acac89e6502e69f797d4f4a49
|
LayerNorm
|
import torch
import torch.nn as nn
import torch.nn.parallel
import torch.optim
import torch.utils.data
import torch.utils.data.distributed
class LayerNorm(nn.Module):
def __init__(self, num_features, eps=1e-05, affine=True):
super(LayerNorm, self).__init__()
self.num_features = num_features
self.affine = affine
self.eps = eps
if self.affine:
self.gamma = nn.Parameter(torch.Tensor(num_features).uniform_())
self.beta = nn.Parameter(torch.zeros(num_features))
def forward(self, x):
shape = [-1] + [1] * (x.dim() - 1)
if x.size(0) == 1:
mean = x.view(-1).mean().view(*shape)
std = x.view(-1).std().view(*shape)
else:
mean = x.view(x.size(0), -1).mean(1).view(*shape)
std = x.view(x.size(0), -1).std(1).view(*shape)
x = (x - mean) / (std + self.eps)
if self.affine:
shape = [1, -1] + [1] * (x.dim() - 2)
x = x * self.gamma.view(*shape) + self.beta.view(*shape)
return x
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
import torch.nn.parallel
import torch.optim
import torch.utils.data
import torch.utils.data.distributed
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_per_fused_add_div_mean_mul_std_sub_0(in_out_ptr0, in_out_ptr1,
in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 4
RBLOCK: tl.constexpr = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
r3 = rindex // 16
tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0)
tmp28 = tl.load(in_ptr1 + r3, None, eviction_policy='evict_last')
tmp30 = tl.load(in_ptr2 + r3, None, eviction_policy='evict_last')
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(xmask, tmp1, 0)
tmp4 = tl.sum(tmp3, 1)[:, None]
tmp6 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp8 = tl.where(xmask, tmp6, 0)
tmp9 = tl.sum(tmp8, 1)[:, None]
tmp10 = tl.full([XBLOCK, 1], 64, tl.int32)
tmp11 = tmp10.to(tl.float32)
tmp12 = tmp9 / tmp11
tmp13 = tmp1 - tmp12
tmp14 = tmp13 * tmp13
tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK])
tmp17 = tl.where(xmask, tmp15, 0)
tmp18 = tl.sum(tmp17, 1)[:, None]
tmp19 = 64.0
tmp20 = tmp4 / tmp19
tmp21 = 63.0
tmp22 = tmp18 / tmp21
tmp23 = libdevice.sqrt(tmp22)
tmp24 = 1e-05
tmp25 = tmp23 + tmp24
tmp26 = tmp0 - tmp20
tmp27 = tmp26 / tmp25
tmp29 = tmp27 * tmp28
tmp31 = tmp29 + tmp30
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp20, xmask)
tl.debug_barrier()
tl.store(in_out_ptr1 + x0, tmp25, xmask)
tl.store(out_ptr0 + (r1 + 64 * x0), tmp31, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4,), (1,), torch.float32)
buf3 = empty_strided_cuda((4,), (1,), torch.float32)
buf1 = buf0
del buf0
buf5 = reinterpret_tensor(buf3, (4, 1, 1, 1), (1, 1, 1, 1), 0)
del buf3
buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_per_fused_add_div_mean_mul_std_sub_0[grid(4)](buf1, buf5,
primals_1, primals_2, primals_3, buf6, 4, 64, XBLOCK=1,
num_warps=2, num_stages=1)
del primals_2
del primals_3
return buf6, primals_1, reinterpret_tensor(buf1, (4, 1, 1, 1), (1, 1, 1,
1), 0), buf5
class LayerNormNew(nn.Module):
def __init__(self, num_features, eps=1e-05, affine=True):
super(LayerNormNew, self).__init__()
self.num_features = num_features
self.affine = affine
self.eps = eps
if self.affine:
self.gamma = nn.Parameter(torch.Tensor(num_features).uniform_())
self.beta = nn.Parameter(torch.zeros(num_features))
def forward(self, input_0):
primals_2 = self.gamma
primals_3 = self.beta
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
ToniChopp/MIRACLE-Paper-Sharing-Album
|
LayerNorm
| false
| 18,012
|
[
"MIT"
] | 7
|
72a3843101483fc8b53df2746c488da066eda2a1
|
https://github.com/ToniChopp/MIRACLE-Paper-Sharing-Album/tree/72a3843101483fc8b53df2746c488da066eda2a1
|
DistillKL
|
import torch
import torch.nn.functional as F
import torch.nn as nn
import torch.nn.parallel
import torch.optim
import torch.utils.data
import torch.utils.data.distributed
class DistillKL(nn.Module):
"""Distilling the Knowledge in a Neural Network"""
def __init__(self, T):
super(DistillKL, self).__init__()
self.T = T
def forward(self, y_s, y_t):
p_s = F.log_softmax(y_s / self.T, dim=1)
p_t = F.softmax(y_t / self.T, dim=1)
loss = F.kl_div(p_s, p_t, reduction='sum') * self.T ** 2 / y_s.shape[0]
return loss
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'T': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
import torch.nn as nn
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
@triton.jit
def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp3 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp5 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp8 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp11 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp1 = 1.0
tmp2 = tmp0 * tmp1
tmp4 = tmp3 * tmp1
tmp6 = tmp5 * tmp1
tmp7 = triton_helpers.maximum(tmp4, tmp6)
tmp9 = tmp8 * tmp1
tmp10 = triton_helpers.maximum(tmp7, tmp9)
tmp12 = tmp11 * tmp1
tmp13 = triton_helpers.maximum(tmp10, tmp12)
tmp14 = tmp2 - tmp13
tmp15 = 0.25
tmp16 = tmp14 * tmp15
tmp17 = tl_math.exp(tmp16)
tl.store(out_ptr0 + x3, tmp17, xmask)
@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
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp3 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp5 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp8 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp11 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp1 = 1.0
tmp2 = tmp0 * tmp1
tmp4 = tmp3 * tmp1
tmp6 = tmp5 * tmp1
tmp7 = triton_helpers.maximum(tmp4, tmp6)
tmp9 = tmp8 * tmp1
tmp10 = triton_helpers.maximum(tmp7, tmp9)
tmp12 = tmp11 * tmp1
tmp13 = triton_helpers.maximum(tmp10, tmp12)
tmp14 = tmp2 - tmp13
tmp15 = 0.25
tmp16 = tmp14 * tmp15
tl.store(out_ptr0 + x3, tmp16, xmask)
@triton.jit
def triton_per_fused__log_softmax__softmax_div_mul_sub_sum_xlogy_2(in_out_ptr0,
in_ptr0, in_ptr1, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r3 = rindex
r0 = rindex % 16
r2 = rindex // 64
tmp0 = tl.load(in_ptr0 + r3, None)
tmp1 = tl.load(in_ptr0 + (r0 + 64 * r2), None, eviction_policy='evict_last'
)
tmp2 = tl.load(in_ptr0 + (16 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (32 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (48 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp17 = tl.load(in_ptr1 + r3, None)
tmp18 = tl.load(in_ptr1 + (r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp20 = tl.load(in_ptr1 + (16 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp23 = tl.load(in_ptr1 + (32 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp26 = tl.load(in_ptr1 + (48 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tmp9 = libdevice.isnan(tmp8).to(tl.int1)
tmp10 = 0.0
tmp11 = tmp8 == tmp10
tmp12 = tl_math.log(tmp8)
tmp13 = tmp8 * tmp12
tmp14 = tl.where(tmp11, tmp10, tmp13)
tmp15 = float('nan')
tmp16 = tl.where(tmp9, tmp15, tmp14)
tmp19 = tl_math.exp(tmp18)
tmp21 = tl_math.exp(tmp20)
tmp22 = tmp19 + tmp21
tmp24 = tl_math.exp(tmp23)
tmp25 = tmp22 + tmp24
tmp27 = tl_math.exp(tmp26)
tmp28 = tmp25 + tmp27
tmp29 = tl_math.log(tmp28)
tmp30 = tmp17 - tmp29
tmp31 = tmp8 * tmp30
tmp32 = tmp16 - tmp31
tmp33 = tl.broadcast_to(tmp32, [RBLOCK])
tmp35 = triton_helpers.promote_to_tensor(tl.sum(tmp33, 0))
tmp36 = 16.0
tmp37 = tmp35 * tmp36
tmp38 = 0.25
tmp39 = tmp37 * tmp38
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp39, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__softmax_0[grid(256)](arg1_1, buf0, 256, XBLOCK=
128, num_warps=4, num_stages=1)
del arg1_1
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_1[grid(256)](arg0_1, buf2, 256, XBLOCK=128,
num_warps=4, num_stages=1)
del arg0_1
buf3 = empty_strided_cuda((), (), torch.float32)
buf4 = buf3
del buf3
triton_per_fused__log_softmax__softmax_div_mul_sub_sum_xlogy_2[grid(1)
](buf4, buf0, buf2, 1, 256, num_warps=2, num_stages=1)
del buf0
del buf2
return buf4,
class DistillKLNew(nn.Module):
"""Distilling the Knowledge in a Neural Network"""
def __init__(self, T):
super(DistillKLNew, self).__init__()
self.T = T
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
ToniChopp/MIRACLE-Paper-Sharing-Album
|
DistillKL
| false
| 18,013
|
[
"MIT"
] | 7
|
72a3843101483fc8b53df2746c488da066eda2a1
|
https://github.com/ToniChopp/MIRACLE-Paper-Sharing-Album/tree/72a3843101483fc8b53df2746c488da066eda2a1
|
TwoLinearsModel
|
import torch
import torch.nn as nn
import torch.nn
import torch.utils.data
import torch.utils.tensorboard._pytorch_graph
import torch.onnx.symbolic_caffe2
class TwoLinearsModel(nn.Module):
def __init__(self, per_sample_shape: 'list', hidden_size: 'int',
output_size: 'int'):
super(TwoLinearsModel, self).__init__()
assert len(per_sample_shape) == 3
self.per_sample_shape = per_sample_shape
input_size = per_sample_shape[0]
for dim in per_sample_shape[1:]:
input_size *= dim
self.linear1 = nn.Linear(input_size, hidden_size)
self.linear2 = nn.Linear(hidden_size, output_size)
def forward(self, x: 'torch.Tensor'):
batch_size = x.size(0)
x = x.view(batch_size, -1)
h_relu = self.linear1(x).clamp(min=0)
y_pred = self.linear2(h_relu)
return y_pred
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'per_sample_shape': [4, 4, 4], 'hidden_size': 4,
'output_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
import torch.nn
import torch.utils.data
import torch.utils.tensorboard._pytorch_graph
import torch.onnx.symbolic_caffe2
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_clamp_ge_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = triton_helpers.maximum(tmp2, tmp3)
tmp5 = tmp2 >= tmp3
tl.store(out_ptr0 + x2, tmp4, xmask)
tl.store(out_ptr1 + x2, tmp5, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 64), (64, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (4, 64), (64, 1), 0
), reinterpret_tensor(primals_2, (64, 4), (1, 64), 0), out=buf0)
del primals_2
buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf3 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
get_raw_stream(0)
triton_poi_fused_clamp_ge_0[grid(16)](buf0, primals_3, buf1, buf3,
16, XBLOCK=16, num_warps=1, num_stages=1)
del primals_3
buf2 = buf0
del buf0
extern_kernels.addmm(primals_5, buf1, reinterpret_tensor(primals_4,
(4, 4), (1, 4), 0), alpha=1, beta=1, out=buf2)
del primals_5
return buf2, reinterpret_tensor(primals_1, (4, 64), (64, 1), 0
), buf1, primals_4, buf3
class TwoLinearsModelNew(nn.Module):
def __init__(self, per_sample_shape: 'list', hidden_size: 'int',
output_size: 'int'):
super(TwoLinearsModelNew, self).__init__()
assert len(per_sample_shape) == 3
self.per_sample_shape = per_sample_shape
input_size = per_sample_shape[0]
for dim in per_sample_shape[1:]:
input_size *= dim
self.linear1 = nn.Linear(input_size, hidden_size)
self.linear2 = nn.Linear(hidden_size, output_size)
def forward(self, input_0):
primals_2 = self.linear1.weight
primals_3 = self.linear1.bias
primals_4 = self.linear2.weight
primals_5 = self.linear2.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
Rohan-Chaudhury/aimet
|
TwoLinearsModel
| false
| 18,014
|
[
"BSD-3-Clause"
] | 3
|
1c38cac8cc0fd32dca40ce5e39940805d29f7a4a
|
https://github.com/Rohan-Chaudhury/aimet/tree/1c38cac8cc0fd32dca40ce5e39940805d29f7a4a
|
PrefModel
|
import torch
import torch.nn as nn
class PrefModel(nn.Module):
def __init__(self, input_dim):
super(PrefModel, self).__init__()
self.combination = nn.Linear(input_dim, 2)
self.softmax = nn.Softmax(1)
def forward(self, features):
h = self.combination(features)
out = self.softmax(h)
return out
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'input_dim': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 8
x2 = xindex // 32
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 32 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr0 + (8 + x0 + 32 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (16 + x0 + 32 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (24 + x0 + 32 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x3, tmp9, xmask)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 8
x2 = xindex // 32
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 32 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr0 + (8 + x0 + 32 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (16 + x0 + 32 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (24 + x0 + 32 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x3, tmp8, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (2, 4), (4, 1))
assert_size_stride(primals_2, (2,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 2), (2, 1), torch.float32)
extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64,
4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 2), (1, 4), 0
), alpha=1, beta=1, out=buf0)
del primals_1
del primals_2
buf1 = empty_strided_cuda((4, 4, 4, 2), (32, 8, 2, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__softmax_0[grid(128)](buf0, buf1, 128, XBLOCK=128,
num_warps=4, num_stages=1)
buf2 = reinterpret_tensor(buf0, (4, 4, 4, 2), (32, 8, 2, 1), 0)
del buf0
triton_poi_fused__softmax_1[grid(128)](buf1, buf2, 128, XBLOCK=128,
num_warps=4, num_stages=1)
del buf1
return buf2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf2
class PrefModelNew(nn.Module):
def __init__(self, input_dim):
super(PrefModelNew, self).__init__()
self.combination = nn.Linear(input_dim, 2)
self.softmax = nn.Softmax(1)
def forward(self, input_0):
primals_1 = self.combination.weight
primals_2 = self.combination.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
UKPLab/ijcai2019-relis
|
PrefModel
| false
| 18,015
|
[
"MIT"
] | 5
|
8a40762dcfa90c075a4f6591cbdceb468026ef17
|
https://github.com/UKPLab/ijcai2019-relis/tree/8a40762dcfa90c075a4f6591cbdceb468026ef17
|
TinyConvNet2d
|
import torch
class TinyConvNet2d(torch.nn.Module):
def __init__(self, in_channels=1, out_channels=1):
super().__init__()
self.conv1 = torch.nn.Conv2d(in_channels, 16, 1)
self.nlin1 = torch.nn.ReLU()
self.conv2 = torch.nn.Conv2d(16, 64, 1)
self.nlin2 = torch.nn.ReLU()
self.conv3 = torch.nn.Conv2d(64, out_channels, 1)
self.nlin3 = torch.nn.Sigmoid()
def forward(self, x):
return torch.nn.Sequential(self.conv1, self.nlin1, self.conv2, self
.nlin2, self.conv3, self.nlin3)(x)
def get_inputs():
return [torch.rand([4, 1, 64, 64])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
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 % 16
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x3, tmp4, None)
@triton.jit
def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel,
XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 4096 % 64
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x3, tmp4, None)
@triton.jit
def triton_poi_fused_convolution_sigmoid_2(in_out_ptr0, in_ptr0, xnumel,
XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, None)
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, None)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7) = args
args.clear()
assert_size_stride(primals_1, (16, 1, 1, 1), (1, 1, 1, 1))
assert_size_stride(primals_2, (16,), (1,))
assert_size_stride(primals_3, (4, 1, 64, 64), (4096, 4096, 64, 1))
assert_size_stride(primals_4, (64, 16, 1, 1), (16, 1, 1, 1))
assert_size_stride(primals_5, (64,), (1,))
assert_size_stride(primals_6, (1, 64, 1, 1), (64, 1, 1, 1))
assert_size_stride(primals_7, (1,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 16, 64, 64), (65536, 4096, 64, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_relu_0[grid(262144)](buf1, primals_2,
262144, XBLOCK=512, num_warps=8, num_stages=1)
del primals_2
buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 64, 64, 64), (262144, 4096, 64, 1))
buf3 = buf2
del buf2
triton_poi_fused_convolution_relu_1[grid(1048576)](buf3, primals_5,
1048576, XBLOCK=1024, num_warps=4, num_stages=1)
del primals_5
buf4 = extern_kernels.convolution(buf3, primals_6, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 1, 64, 64), (4096, 4096, 64, 1))
buf5 = buf4
del buf4
triton_poi_fused_convolution_sigmoid_2[grid(16384)](buf5, primals_7,
16384, XBLOCK=128, num_warps=4, num_stages=1)
del primals_7
return buf5, primals_1, primals_3, primals_4, primals_6, buf1, buf3, buf5
class TinyConvNet2dNew(torch.nn.Module):
def __init__(self, in_channels=1, out_channels=1):
super().__init__()
self.conv1 = torch.nn.Conv2d(in_channels, 16, 1)
self.nlin1 = torch.nn.ReLU()
self.conv2 = torch.nn.Conv2d(16, 64, 1)
self.nlin2 = torch.nn.ReLU()
self.conv3 = torch.nn.Conv2d(64, out_channels, 1)
self.nlin3 = torch.nn.Sigmoid()
def forward(self, input_0):
primals_1 = self.conv1.weight
primals_2 = self.conv1.bias
primals_4 = self.conv2.weight
primals_5 = self.conv2.bias
primals_6 = self.conv3.weight
primals_7 = self.conv3.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7])
return output[0]
|
Tomaz-Vieira/tiktorch
|
TinyConvNet2d
| false
| 18,016
|
[
"MIT"
] | 8
|
2d6803c4ba5e26e4b27bf8af6638040fa4fc5628
|
https://github.com/Tomaz-Vieira/tiktorch/tree/2d6803c4ba5e26e4b27bf8af6638040fa4fc5628
|
TVLoss
|
import torch
import torch.nn as nn
import torch.nn.init
class TVLoss(nn.Module):
def __init__(self):
super(TVLoss, self).__init__()
def forward(self, x):
"""
Arguments:
x: a float tensor with shape [b, 3, h, w].
It represents a RGB image with pixel values in [0, 1] range.
Returns:
a float tensor with shape [].
"""
b, c, h, w = x.size()
h_tv = torch.pow(x[:, :, 1:, :] - x[:, :, :h - 1, :], 2).sum()
w_tv = torch.pow(x[:, :, :, 1:] - x[:, :, :, :w - 1], 2).sum()
return (h_tv + w_tv) / (b * c * h * w)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
import torch.nn.init
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_add_div_pow_sub_sum_0(in_out_ptr0, in_ptr0, xnumel,
rnumel, XBLOCK: tl.constexpr):
rnumel = 192
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
rmask = rindex < rnumel
r0 = rindex % 12
r1 = rindex // 12
r2 = rindex % 3
r3 = rindex // 3
tmp0 = tl.load(in_ptr0 + (4 + r0 + 16 * r1), rmask, other=0.0)
tmp1 = tl.load(in_ptr0 + (r0 + 16 * r1), rmask, other=0.0)
tmp8 = tl.load(in_ptr0 + (1 + r2 + 4 * r3), rmask, other=0.0)
tmp9 = tl.load(in_ptr0 + (r2 + 4 * r3), rmask, other=0.0)
tmp2 = tmp0 - tmp1
tmp3 = tmp2 * tmp2
tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
tmp6 = tl.where(rmask, tmp4, 0)
tmp7 = tl.sum(tmp6, 1)[:, None]
tmp10 = tmp8 - tmp9
tmp11 = tmp10 * tmp10
tmp12 = tl.broadcast_to(tmp11, [XBLOCK, RBLOCK])
tmp14 = tl.where(rmask, tmp12, 0)
tmp15 = tl.sum(tmp14, 1)[:, None]
tmp16 = tmp7 + tmp15
tmp17 = 0.00390625
tmp18 = tmp16 * tmp17
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp18, 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)
buf2 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_add_div_pow_sub_sum_0[grid(1)](buf2, arg0_1, 1,
192, XBLOCK=1, num_warps=2, num_stages=1)
del arg0_1
return buf2,
class TVLossNew(nn.Module):
def __init__(self):
super(TVLossNew, self).__init__()
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
TropComplique/WESPE
|
TVLoss
| false
| 18,017
|
[
"MIT"
] | 5
|
84738f1ed802a3f6a4a0549677d8137997fac617
|
https://github.com/TropComplique/WESPE/tree/84738f1ed802a3f6a4a0549677d8137997fac617
|
Grayscale
|
import torch
import torch.nn as nn
import torch.nn.init
class Grayscale(nn.Module):
def __init__(self):
super(Grayscale, self).__init__()
def forward(self, x):
"""
Arguments:
x: a float tensor with shape [b, 3, h, w].
It represents a RGB image with pixel values in [0, 1] range.
Returns:
a float tensor with shape [b, 1, h, w].
"""
result = 0.299 * x[:, 0] + 0.587 * x[:, 1] + 0.114 * x[:, 2]
return result.unsqueeze(1)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
import torch.nn.init
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_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)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_add_mul_0[grid(64)](arg0_1, buf0, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del arg0_1
return reinterpret_tensor(buf0, (4, 1, 4, 4), (16, 16, 4, 1), 0),
class GrayscaleNew(nn.Module):
def __init__(self):
super(GrayscaleNew, self).__init__()
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
TropComplique/WESPE
|
Grayscale
| false
| 18,018
|
[
"MIT"
] | 5
|
84738f1ed802a3f6a4a0549677d8137997fac617
|
https://github.com/TropComplique/WESPE/tree/84738f1ed802a3f6a4a0549677d8137997fac617
|
TinyConvNet3d
|
import torch
class TinyConvNet3d(torch.nn.Module):
def __init__(self, in_channels=1, out_channels=1):
super().__init__()
self.conv1 = torch.nn.Conv3d(in_channels, 16, 1)
self.nlin1 = torch.nn.ReLU()
self.conv2 = torch.nn.Conv3d(16, 64, 1)
self.nlin2 = torch.nn.ReLU()
self.conv3 = torch.nn.Conv3d(64, out_channels, 1)
self.nlin3 = torch.nn.Sigmoid()
def forward(self, x):
return torch.nn.Sequential(self.conv1, self.nlin1, self.conv2, self
.nlin2, self.conv3, self.nlin3)(x)
def get_inputs():
return [torch.rand([4, 1, 64, 64, 64])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
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 // 262144 % 16
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x3, tmp4, None)
@triton.jit
def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel,
XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 262144 % 64
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x3, tmp4, None)
@triton.jit
def triton_poi_fused_convolution_sigmoid_2(in_out_ptr0, in_ptr0, xnumel,
XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, None)
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, None)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7) = args
args.clear()
assert_size_stride(primals_1, (16, 1, 1, 1, 1), (1, 1, 1, 1, 1))
assert_size_stride(primals_2, (16,), (1,))
assert_size_stride(primals_3, (4, 1, 64, 64, 64), (262144, 262144, 4096,
64, 1))
assert_size_stride(primals_4, (64, 16, 1, 1, 1), (16, 1, 1, 1, 1))
assert_size_stride(primals_5, (64,), (1,))
assert_size_stride(primals_6, (1, 64, 1, 1, 1), (64, 1, 1, 1, 1))
assert_size_stride(primals_7, (1,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,
1, 1), padding=(0, 0, 0), dilation=(1, 1, 1), transposed=False,
output_padding=(0, 0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 16, 64, 64, 64), (4194304, 262144,
4096, 64, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_relu_0[grid(16777216)](buf1, primals_2,
16777216, XBLOCK=1024, num_warps=4, num_stages=1)
del primals_2
buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1, 1),
padding=(0, 0, 0), dilation=(1, 1, 1), transposed=False,
output_padding=(0, 0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 64, 64, 64, 64), (16777216, 262144,
4096, 64, 1))
buf3 = buf2
del buf2
triton_poi_fused_convolution_relu_1[grid(67108864)](buf3, primals_5,
67108864, XBLOCK=1024, num_warps=4, num_stages=1)
del primals_5
buf4 = extern_kernels.convolution(buf3, primals_6, stride=(1, 1, 1),
padding=(0, 0, 0), dilation=(1, 1, 1), transposed=False,
output_padding=(0, 0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 1, 64, 64, 64), (262144, 262144, 4096,
64, 1))
buf5 = buf4
del buf4
triton_poi_fused_convolution_sigmoid_2[grid(1048576)](buf5,
primals_7, 1048576, XBLOCK=1024, num_warps=4, num_stages=1)
del primals_7
return buf5, primals_1, primals_3, primals_4, primals_6, buf1, buf3, buf5
class TinyConvNet3dNew(torch.nn.Module):
def __init__(self, in_channels=1, out_channels=1):
super().__init__()
self.conv1 = torch.nn.Conv3d(in_channels, 16, 1)
self.nlin1 = torch.nn.ReLU()
self.conv2 = torch.nn.Conv3d(16, 64, 1)
self.nlin2 = torch.nn.ReLU()
self.conv3 = torch.nn.Conv3d(64, out_channels, 1)
self.nlin3 = torch.nn.Sigmoid()
def forward(self, input_0):
primals_1 = self.conv1.weight
primals_2 = self.conv1.bias
primals_4 = self.conv2.weight
primals_5 = self.conv2.bias
primals_6 = self.conv3.weight
primals_7 = self.conv3.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7])
return output[0]
|
Tomaz-Vieira/tiktorch
|
TinyConvNet3d
| false
| 18,019
|
[
"MIT"
] | 8
|
2d6803c4ba5e26e4b27bf8af6638040fa4fc5628
|
https://github.com/Tomaz-Vieira/tiktorch/tree/2d6803c4ba5e26e4b27bf8af6638040fa4fc5628
|
Dummy
|
import torch
from torch import nn
class Dummy(nn.Module):
def forward(self, input):
x = input
return x + 1
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_add_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 1.0
tmp2 = tmp0 + tmp1
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=256,
num_warps=4, num_stages=1)
del arg0_1
return buf0,
class DummyNew(nn.Module):
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
Tomaz-Vieira/tiktorch
|
Dummy
| false
| 18,020
|
[
"MIT"
] | 8
|
2d6803c4ba5e26e4b27bf8af6638040fa4fc5628
|
https://github.com/Tomaz-Vieira/tiktorch/tree/2d6803c4ba5e26e4b27bf8af6638040fa4fc5628
|
AttPool
|
import torch
from torch import nn
from torch.nn import functional as F
class AttPool(nn.Module):
"""
Pool representations along a dimension with learned softmax scores.
Args:
input_size (int): Input size.
dim (int): Dimension on which to apply the attention pooling.
"""
def __init__(self, input_size, dim):
super(AttPool, self).__init__()
self.lin = nn.Linear(input_size, 1)
self.dim = dim
def forward(self, x):
scores = F.softmax(self.lin(x), dim=self.dim)
x = (scores * x).sum(dim=self.dim, keepdim=True)
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4, 4])]
def get_init_inputs():
return [[], {'input_size': 4, '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 math as tl_math
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused__softmax_mul_sum_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)
tmp4 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp1 = tmp0 - tmp0
tmp2 = tl_math.exp(tmp1)
tmp3 = tmp2 / tmp2
tmp5 = tmp3 * tmp4
tmp7 = tmp3 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp3 * tmp9
tmp11 = tmp8 + tmp10
tmp13 = tmp3 * tmp12
tmp14 = tmp11 + tmp13
tl.store(out_ptr0 + x0, tmp14, xmask)
def call(args):
primals_1, primals_2, primals_3 = 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, 4), (256, 64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf1 = empty_strided_cuda((256, 1), (1, 1), torch.float32)
extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (256,
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, 4, 1), (64, 16, 4, 1, 1), torch
.float32)
get_raw_stream(0)
triton_poi_fused__softmax_mul_sum_0[grid(256)](buf1, primals_3,
buf2, 256, XBLOCK=128, num_warps=4, num_stages=1)
return buf2, primals_3, buf1
class AttPoolNew(nn.Module):
"""
Pool representations along a dimension with learned softmax scores.
Args:
input_size (int): Input size.
dim (int): Dimension on which to apply the attention pooling.
"""
def __init__(self, input_size, dim):
super(AttPoolNew, self).__init__()
self.lin = nn.Linear(input_size, 1)
self.dim = dim
def forward(self, input_0):
primals_1 = self.lin.weight
primals_2 = self.lin.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
TorchSpatiotemporal/tsl
|
AttPool
| false
| 18,021
|
[
"MIT"
] | 4
|
da13493b0cf83826bf41fe78a67e8d4ce1d7a8a0
|
https://github.com/TorchSpatiotemporal/tsl/tree/da13493b0cf83826bf41fe78a67e8d4ce1d7a8a0
|
Sobel
|
import torch
import torch.nn as nn
import torch.nn.init
import torch.nn.functional as F
class Sobel(nn.Module):
def __init__(self):
super(Sobel, self).__init__()
kernel = [[[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], [[-1, -2, -1], [0,
0, 0], [1, 2, 1]]]
kernel = torch.Tensor(kernel).unsqueeze(1).repeat([3, 1, 1, 1])
self.kernel = nn.Parameter(data=kernel, requires_grad=False)
def forward(self, x):
"""
Arguments:
x: a float tensor with shape [b, 3, h, w].
It represents a RGB image with pixel values in [0, 1] range.
Returns:
a float tensor with shape [b, 3*2, h, w].
"""
x = F.conv2d(x, self.kernel, padding=1, groups=3)
return x
def get_inputs():
return [torch.rand([4, 3, 64, 64])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
import torch.nn.init
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_convolution_0(in_ptr0, out_ptr0, ynumel, xnumel,
YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 12
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
x2 = xindex
y3 = yindex
y0 = yindex % 3
y1 = yindex // 3
tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (y0 + 3 * x2 + 12288 * y1), tmp0, ymask)
@triton.jit
def triton_poi_fused_convolution_1(in_ptr0, out_ptr0, ynumel, xnumel,
YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 24
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
x2 = xindex
y0 = yindex % 6
y1 = yindex // 6
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 6 * x2 + 24576 * y1), ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 4096 * y3), tmp0, ymask)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (6, 1, 3, 3), (9, 9, 3, 1))
assert_size_stride(arg1_1, (4, 3, 64, 64), (12288, 4096, 64, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 3, 64, 64), (12288, 1, 192, 3), torch
.float32)
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(12, 4096)](arg1_1, buf0, 12,
4096, XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1)
del arg1_1
buf1 = extern_kernels.convolution(buf0, arg0_1, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=3, bias=None)
assert_size_stride(buf1, (4, 6, 64, 64), (24576, 1, 384, 6))
del arg0_1
del buf0
buf2 = empty_strided_cuda((4, 6, 64, 64), (24576, 4096, 64, 1),
torch.float32)
triton_poi_fused_convolution_1[grid(24, 4096)](buf1, buf2, 24, 4096,
XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
del buf1
return buf2,
class SobelNew(nn.Module):
def __init__(self):
super(SobelNew, self).__init__()
kernel = [[[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], [[-1, -2, -1], [0,
0, 0], [1, 2, 1]]]
kernel = torch.Tensor(kernel).unsqueeze(1).repeat([3, 1, 1, 1])
self.kernel = nn.Parameter(data=kernel, requires_grad=False)
def forward(self, input_0):
arg0_1 = self.kernel
arg1_1 = input_0
output = call([arg0_1, arg1_1])
return output[0]
|
TropComplique/WESPE
|
Sobel
| false
| 18,023
|
[
"MIT"
] | 5
|
84738f1ed802a3f6a4a0549677d8137997fac617
|
https://github.com/TropComplique/WESPE/tree/84738f1ed802a3f6a4a0549677d8137997fac617
|
MaxPool3x3
|
import torch
import torch.nn as nn
class MaxPool3x3(nn.Module):
"""3x3 max pool with no subsampling."""
def __init__(self, in_channels, out_channels, kernel_size=3, stride=1,
padding=1):
super(MaxPool3x3, self).__init__()
self.maxpool = nn.MaxPool2d(kernel_size, stride, padding)
def forward(self, x):
x = self.maxpool(x)
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'out_channels': 4}]
|
import torch
import triton
import triton.language 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_max_pool2d_with_indices_0(in_ptr0, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 4 % 4
x0 = xindex % 4
x4 = xindex
tmp0 = -1 + x1
tmp1 = tl.full([1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tmp2 & tmp4
tmp6 = -1 + x0
tmp7 = tmp6 >= tmp1
tmp8 = tmp6 < tmp3
tmp9 = tmp7 & tmp8
tmp10 = tmp5 & tmp9
tmp11 = tl.load(in_ptr0 + (-5 + x4), tmp10 & xmask, other=float('-inf'))
tmp12 = x0
tmp13 = tmp12 >= tmp1
tmp14 = tmp12 < tmp3
tmp15 = tmp13 & tmp14
tmp16 = tmp5 & tmp15
tmp17 = tl.load(in_ptr0 + (-4 + x4), tmp16 & xmask, other=float('-inf'))
tmp18 = triton_helpers.maximum(tmp17, tmp11)
tmp19 = 1 + x0
tmp20 = tmp19 >= tmp1
tmp21 = tmp19 < tmp3
tmp22 = tmp20 & tmp21
tmp23 = tmp5 & tmp22
tmp24 = tl.load(in_ptr0 + (-3 + x4), tmp23 & xmask, other=float('-inf'))
tmp25 = triton_helpers.maximum(tmp24, tmp18)
tmp26 = x1
tmp27 = tmp26 >= tmp1
tmp28 = tmp26 < tmp3
tmp29 = tmp27 & tmp28
tmp30 = tmp29 & tmp9
tmp31 = tl.load(in_ptr0 + (-1 + x4), tmp30 & xmask, other=float('-inf'))
tmp32 = triton_helpers.maximum(tmp31, tmp25)
tmp33 = tmp29 & tmp15
tmp34 = tl.load(in_ptr0 + x4, tmp33 & xmask, other=float('-inf'))
tmp35 = triton_helpers.maximum(tmp34, tmp32)
tmp36 = tmp29 & tmp22
tmp37 = tl.load(in_ptr0 + (1 + x4), tmp36 & xmask, other=float('-inf'))
tmp38 = triton_helpers.maximum(tmp37, tmp35)
tmp39 = 1 + x1
tmp40 = tmp39 >= tmp1
tmp41 = tmp39 < tmp3
tmp42 = tmp40 & tmp41
tmp43 = tmp42 & tmp9
tmp44 = tl.load(in_ptr0 + (3 + x4), tmp43 & xmask, other=float('-inf'))
tmp45 = triton_helpers.maximum(tmp44, tmp38)
tmp46 = tmp42 & tmp15
tmp47 = tl.load(in_ptr0 + (4 + x4), tmp46 & xmask, other=float('-inf'))
tmp48 = triton_helpers.maximum(tmp47, tmp45)
tmp49 = tmp42 & tmp22
tmp50 = tl.load(in_ptr0 + (5 + x4), tmp49 & xmask, other=float('-inf'))
tmp51 = triton_helpers.maximum(tmp50, tmp48)
tl.store(out_ptr0 + x4, tmp51, 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_max_pool2d_with_indices_0[grid(256)](arg0_1, buf0,
256, XBLOCK=256, num_warps=4, num_stages=1)
del arg0_1
return buf0,
class MaxPool3x3New(nn.Module):
"""3x3 max pool with no subsampling."""
def __init__(self, in_channels, out_channels, kernel_size=3, stride=1,
padding=1):
super(MaxPool3x3New, self).__init__()
self.maxpool = nn.MaxPool2d(kernel_size, stride, padding)
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
VascoLopes/GEA
|
MaxPool3x3
| false
| 18,024
|
[
"MIT"
] | 4
|
ab80dbb9851dfc215102e5222e8d5f70e855dd15
|
https://github.com/VascoLopes/GEA/tree/ab80dbb9851dfc215102e5222e8d5f70e855dd15
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.