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
|
|---|---|---|---|---|---|---|---|---|---|---|
TRPO
|
import torch
import numpy as np
import torch.nn as nn
import torch.nn.functional as F
def flat_grad(grads):
grad_flatten = []
for grad in grads:
grad_flatten.append(grad.view(-1))
grad_flatten = torch.cat(grad_flatten)
return grad_flatten
def flat_hessian(hessians):
hessians_flatten = []
for hessian in hessians:
hessians_flatten.append(hessian.contiguous().view(-1))
hessians_flatten = torch.cat(hessians_flatten).data
return hessians_flatten
def kl_divergence(policy, old_policy):
kl = old_policy * torch.log(old_policy / policy)
kl = kl.sum(1, keepdim=True)
return kl
def fisher_vector_product(net, states, p, cg_damp=0.1):
policy = net(states)
old_policy = net(states).detach()
kl = kl_divergence(policy, old_policy)
kl = kl.mean()
kl_grad = torch.autograd.grad(kl, net.parameters(), create_graph=True)
kl_grad = flat_grad(kl_grad)
kl_grad_p = (kl_grad * p.detach()).sum()
kl_hessian_p = torch.autograd.grad(kl_grad_p, net.parameters())
kl_hessian_p = flat_hessian(kl_hessian_p)
return kl_hessian_p + cg_damp * p.detach()
def conjugate_gradient(net, states, loss_grad, n_step=10, residual_tol=1e-10):
x = torch.zeros(loss_grad.size())
r = loss_grad.clone()
p = loss_grad.clone()
r_dot_r = torch.dot(r, r)
for i in range(n_step):
A_dot_p = fisher_vector_product(net, states, p)
alpha = r_dot_r / torch.dot(p, A_dot_p)
x += alpha * p
r -= alpha * A_dot_p
new_r_dot_r = torch.dot(r, r)
betta = new_r_dot_r / r_dot_r
p = r + betta * p
r_dot_r = new_r_dot_r
if r_dot_r < residual_tol:
break
return x
def flat_params(model):
params = []
for param in model.parameters():
params.append(param.data.view(-1))
params_flatten = torch.cat(params)
return params_flatten
def update_model(model, new_params):
index = 0
for params in model.parameters():
params_length = len(params.view(-1))
new_param = new_params[index:index + params_length]
new_param = new_param.view(params.size())
params.data.copy_(new_param)
index += params_length
class TRPO(nn.Module):
def __init__(self, num_inputs, num_outputs):
super(TRPO, self).__init__()
self.t = 0
self.num_inputs = num_inputs
self.num_outputs = num_outputs
self.fc_1 = nn.Linear(num_inputs, 128)
self.fc_2 = nn.Linear(128, num_outputs)
for m in self.modules():
if isinstance(m, nn.Linear):
nn.init.xavier_uniform(m.weight)
def forward(self, input):
x = torch.relu(self.fc_1(input))
policy = F.softmax(self.fc_2(x))
return policy
@classmethod
def train_model(cls, net, transitions):
states, actions, rewards, masks = (transitions.state, transitions.
action, transitions.reward, transitions.mask)
states = torch.stack(states)
actions = torch.stack(actions)
rewards = torch.Tensor(rewards)
masks = torch.Tensor(masks)
returns = torch.zeros_like(rewards)
running_return = 0
for t in reversed(range(len(rewards))):
running_return = rewards[t] + gamma * running_return * masks[t]
returns[t] = running_return
policy = net(states)
policy = policy.view(-1, net.num_outputs)
policy_action = (policy * actions.detach()).sum(dim=1)
old_policy = net(states).detach()
old_policy = old_policy.view(-1, net.num_outputs)
old_policy_action = (old_policy * actions.detach()).sum(dim=1)
surrogate_loss = (policy_action / old_policy_action * returns).mean()
surrogate_loss_grad = torch.autograd.grad(surrogate_loss, net.
parameters())
surrogate_loss_grad = flat_grad(surrogate_loss_grad)
step_dir = conjugate_gradient(net, states, surrogate_loss_grad.data)
params = flat_params(net)
shs = (step_dir * fisher_vector_product(net, states, step_dir)).sum(
0, keepdim=True)
step_size = torch.sqrt(2 * max_kl / shs)[0]
full_step = step_size * step_dir
fraction = 1.0
for _ in range(10):
new_params = params + fraction * full_step
update_model(net, new_params)
policy = net(states)
policy = policy.view(-1, net.num_outputs)
policy_action = (policy * actions.detach()).sum(dim=1)
surrogate_loss = (policy_action / old_policy_action * returns
).mean()
kl = kl_divergence(policy, old_policy)
kl = kl.mean()
if kl < max_kl:
break
fraction = fraction * 0.5
return -surrogate_loss
def get_action(self, input):
policy = self.forward(input)
policy = policy[0].data.numpy()
action = np.random.choice(self.num_outputs, 1, p=policy)[0]
return action
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'num_inputs': 4, 'num_outputs': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import numpy as np
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x2 = xindex
x0 = xindex % 128
tmp0 = tl.load(in_out_ptr0 + x2, None)
tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x2, tmp4, None)
tl.store(out_ptr0 + x2, tmp6, None)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x3, tmp9, xmask)
@triton.jit
def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x3, tmp8, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (128, 4), (4, 1))
assert_size_stride(primals_2, (128,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4, 128), (128, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 128), (128, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 128), (1, 4), 0), out=buf0)
del primals_1
buf1 = reinterpret_tensor(buf0, (4, 4, 4, 128), (2048, 512, 128, 1), 0)
del buf0
buf5 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1),
torch.bool)
get_raw_stream(0)
triton_poi_fused_relu_threshold_backward_0[grid(8192)](buf1,
primals_2, buf5, 8192, XBLOCK=256, num_warps=4, num_stages=1)
del primals_2
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 128),
(128, 1), 0), reinterpret_tensor(primals_4, (128, 4), (1, 128),
0), alpha=1, beta=1, out=buf2)
del primals_5
buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__softmax_1[grid(256)](buf2, buf3, 256, XBLOCK=256,
num_warps=4, num_stages=1)
buf4 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf2
triton_poi_fused__softmax_2[grid(256)](buf3, buf4, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del buf3
return buf4, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), reinterpret_tensor(buf1, (64, 128), (128, 1), 0
), buf4, primals_4, buf5
def flat_grad(grads):
grad_flatten = []
for grad in grads:
grad_flatten.append(grad.view(-1))
grad_flatten = torch.cat(grad_flatten)
return grad_flatten
def flat_hessian(hessians):
hessians_flatten = []
for hessian in hessians:
hessians_flatten.append(hessian.contiguous().view(-1))
hessians_flatten = torch.cat(hessians_flatten).data
return hessians_flatten
def kl_divergence(policy, old_policy):
kl = old_policy * torch.log(old_policy / policy)
kl = kl.sum(1, keepdim=True)
return kl
def fisher_vector_product(net, states, p, cg_damp=0.1):
policy = net(states)
old_policy = net(states).detach()
kl = kl_divergence(policy, old_policy)
kl = kl.mean()
kl_grad = torch.autograd.grad(kl, net.parameters(), create_graph=True)
kl_grad = flat_grad(kl_grad)
kl_grad_p = (kl_grad * p.detach()).sum()
kl_hessian_p = torch.autograd.grad(kl_grad_p, net.parameters())
kl_hessian_p = flat_hessian(kl_hessian_p)
return kl_hessian_p + cg_damp * p.detach()
def conjugate_gradient(net, states, loss_grad, n_step=10, residual_tol=1e-10):
x = torch.zeros(loss_grad.size())
r = loss_grad.clone()
p = loss_grad.clone()
r_dot_r = torch.dot(r, r)
for i in range(n_step):
A_dot_p = fisher_vector_product(net, states, p)
alpha = r_dot_r / torch.dot(p, A_dot_p)
x += alpha * p
r -= alpha * A_dot_p
new_r_dot_r = torch.dot(r, r)
betta = new_r_dot_r / r_dot_r
p = r + betta * p
r_dot_r = new_r_dot_r
if r_dot_r < residual_tol:
break
return x
def flat_params(model):
params = []
for param in model.parameters():
params.append(param.data.view(-1))
params_flatten = torch.cat(params)
return params_flatten
def update_model(model, new_params):
index = 0
for params in model.parameters():
params_length = len(params.view(-1))
new_param = new_params[index:index + params_length]
new_param = new_param.view(params.size())
params.data.copy_(new_param)
index += params_length
class TRPONew(nn.Module):
def __init__(self, num_inputs, num_outputs):
super(TRPONew, self).__init__()
self.t = 0
self.num_inputs = num_inputs
self.num_outputs = num_outputs
self.fc_1 = nn.Linear(num_inputs, 128)
self.fc_2 = nn.Linear(128, num_outputs)
for m in self.modules():
if isinstance(m, nn.Linear):
nn.init.xavier_uniform(m.weight)
@classmethod
def train_model(cls, net, transitions):
states, actions, rewards, masks = (transitions.state, transitions.
action, transitions.reward, transitions.mask)
states = torch.stack(states)
actions = torch.stack(actions)
rewards = torch.Tensor(rewards)
masks = torch.Tensor(masks)
returns = torch.zeros_like(rewards)
running_return = 0
for t in reversed(range(len(rewards))):
running_return = rewards[t] + gamma * running_return * masks[t]
returns[t] = running_return
policy = net(states)
policy = policy.view(-1, net.num_outputs)
policy_action = (policy * actions.detach()).sum(dim=1)
old_policy = net(states).detach()
old_policy = old_policy.view(-1, net.num_outputs)
old_policy_action = (old_policy * actions.detach()).sum(dim=1)
surrogate_loss = (policy_action / old_policy_action * returns).mean()
surrogate_loss_grad = torch.autograd.grad(surrogate_loss, net.
parameters())
surrogate_loss_grad = flat_grad(surrogate_loss_grad)
step_dir = conjugate_gradient(net, states, surrogate_loss_grad.data)
params = flat_params(net)
shs = (step_dir * fisher_vector_product(net, states, step_dir)).sum(
0, keepdim=True)
step_size = torch.sqrt(2 * max_kl / shs)[0]
full_step = step_size * step_dir
fraction = 1.0
for _ in range(10):
new_params = params + fraction * full_step
update_model(net, new_params)
policy = net(states)
policy = policy.view(-1, net.num_outputs)
policy_action = (policy * actions.detach()).sum(dim=1)
surrogate_loss = (policy_action / old_policy_action * returns
).mean()
kl = kl_divergence(policy, old_policy)
kl = kl.mean()
if kl < max_kl:
break
fraction = fraction * 0.5
return -surrogate_loss
def get_action(self, input):
policy = self.forward(input)
policy = policy[0].data.numpy()
action = np.random.choice(self.num_outputs, 1, p=policy)[0]
return action
def forward(self, input_0):
primals_1 = self.fc_1.weight
primals_2 = self.fc_1.bias
primals_4 = self.fc_2.weight
primals_5 = self.fc_2.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
g6ling/Pytorch-Cartpole
|
TRPO
| false
| 15,388
|
[
"MIT"
] | 116
|
ecb7b622cfefe825ac95388cceb6752413d90a2a
|
https://github.com/g6ling/Pytorch-Cartpole/tree/ecb7b622cfefe825ac95388cceb6752413d90a2a
|
ResNetV2
|
import torch
import torch.nn.functional as F
import torch.nn as nn
from collections import OrderedDict
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 conv1x1(cin, cout, stride=1, bias=False):
return StdConv2d(cin, cout, kernel_size=1, stride=stride, padding=0,
bias=bias)
def tf2th(conv_weights):
"""Possibly convert HWIO to OIHW."""
if conv_weights.ndim == 4:
conv_weights = conv_weights.transpose([3, 2, 0, 1])
return torch.from_numpy(conv_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-10)
return F.conv2d(x, w, self.bias, self.stride, self.padding, self.
dilation, self.groups)
class PreActBottleneck(nn.Module):
"""Pre-activation (v2) bottleneck block.
Follows the implementation of "Identity Mappings in Deep Residual Networks":
https://github.com/KaimingHe/resnet-1k-layers/blob/master/resnet-pre-act.lua
Except it puts the stride on 3x3 conv when available.
"""
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, cin)
self.conv1 = conv1x1(cin, cmid)
self.gn2 = nn.GroupNorm(32, cmid)
self.conv2 = conv3x3(cmid, cmid, stride)
self.gn3 = nn.GroupNorm(32, cmid)
self.conv3 = conv1x1(cmid, cout)
self.relu = nn.ReLU(inplace=True)
if stride != 1 or cin != cout:
self.downsample = conv1x1(cin, cout, stride)
def forward(self, x):
out = self.relu(self.gn1(x))
residual = x
if hasattr(self, 'downsample'):
residual = self.downsample(out)
out = self.conv1(out)
out = self.conv2(self.relu(self.gn2(out)))
out = self.conv3(self.relu(self.gn3(out)))
return out + residual
def load_from(self, weights, prefix=''):
convname = 'standardized_conv2d'
with torch.no_grad():
self.conv1.weight.copy_(tf2th(weights[
f'{prefix}a/{convname}/kernel']))
self.conv2.weight.copy_(tf2th(weights[
f'{prefix}b/{convname}/kernel']))
self.conv3.weight.copy_(tf2th(weights[
f'{prefix}c/{convname}/kernel']))
self.gn1.weight.copy_(tf2th(weights[f'{prefix}a/group_norm/gamma'])
)
self.gn2.weight.copy_(tf2th(weights[f'{prefix}b/group_norm/gamma'])
)
self.gn3.weight.copy_(tf2th(weights[f'{prefix}c/group_norm/gamma'])
)
self.gn1.bias.copy_(tf2th(weights[f'{prefix}a/group_norm/beta']))
self.gn2.bias.copy_(tf2th(weights[f'{prefix}b/group_norm/beta']))
self.gn3.bias.copy_(tf2th(weights[f'{prefix}c/group_norm/beta']))
if hasattr(self, 'downsample'):
w = weights[f'{prefix}a/proj/{convname}/kernel']
self.downsample.weight.copy_(tf2th(w))
class ResNetV2(nn.Module):
"""Implementation of Pre-activation (v2) ResNet mode."""
def __init__(self, block_units, width_factor, head_size=21843,
zero_head=False):
super().__init__()
wf = width_factor
self.root = nn.Sequential(OrderedDict([('conv', StdConv2d(3, 64 *
wf, kernel_size=7, stride=2, padding=3, bias=False)), ('pad',
nn.ConstantPad2d(1, 0)), ('pool', nn.MaxPool2d(kernel_size=3,
stride=2, padding=0))]))
self.body = nn.Sequential(OrderedDict([('block1', nn.Sequential(
OrderedDict([('unit01', PreActBottleneck(cin=64 * wf, cout=256 *
wf, cmid=64 * wf))] + [(f'unit{i:02d}', PreActBottleneck(cin=
256 * wf, cout=256 * wf, cmid=64 * wf)) for i in range(2,
block_units[0] + 1)]))), ('block2', nn.Sequential(OrderedDict([
('unit01', PreActBottleneck(cin=256 * wf, cout=512 * wf, cmid=
128 * wf, stride=2))] + [(f'unit{i:02d}', PreActBottleneck(cin=
512 * wf, cout=512 * wf, cmid=128 * wf)) for i in range(2,
block_units[1] + 1)]))), ('block3', nn.Sequential(OrderedDict([
('unit01', PreActBottleneck(cin=512 * wf, cout=1024 * wf, cmid=
256 * wf, stride=2))] + [(f'unit{i:02d}', PreActBottleneck(cin=
1024 * wf, cout=1024 * wf, cmid=256 * wf)) for i in range(2,
block_units[2] + 1)]))), ('block4', nn.Sequential(OrderedDict([
('unit01', PreActBottleneck(cin=1024 * wf, cout=2048 * wf, cmid
=512 * wf, stride=2))] + [(f'unit{i:02d}', PreActBottleneck(cin
=2048 * wf, cout=2048 * wf, cmid=512 * wf)) for i in range(2,
block_units[3] + 1)])))]))
self.zero_head = zero_head
self.head = nn.Sequential(OrderedDict([('gn', nn.GroupNorm(32, 2048 *
wf)), ('relu', nn.ReLU(inplace=True)), ('avg', nn.
AdaptiveAvgPool2d(output_size=1)), ('conv', nn.Conv2d(2048 * wf,
head_size, kernel_size=1, bias=True))]))
def forward(self, x):
x = self.head(self.body(self.root(x)))
assert x.shape[-2:] == (1, 1)
return x[..., 0, 0]
def load_from(self, weights, prefix='resnet/'):
with torch.no_grad():
self.root.conv.weight.copy_(tf2th(weights[
f'{prefix}root_block/standardized_conv2d/kernel']))
self.head.gn.weight.copy_(tf2th(weights[
f'{prefix}group_norm/gamma']))
self.head.gn.bias.copy_(tf2th(weights[f'{prefix}group_norm/beta']))
if self.zero_head:
nn.init.zeros_(self.head.conv.weight)
nn.init.zeros_(self.head.conv.bias)
else:
self.head.conv.weight.copy_(tf2th(weights[
f'{prefix}head/conv2d/kernel']))
self.head.conv.bias.copy_(tf2th(weights[
f'{prefix}head/conv2d/bias']))
for bname, block in self.body.named_children():
for uname, unit in block.named_children():
unit.load_from(weights, prefix=f'{prefix}{bname}/{uname}/')
def get_inputs():
return [torch.rand([4, 3, 64, 64])]
def get_init_inputs():
return [[], {'block_units': [4, 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
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
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_poi_fused_5(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
xnumel = 9
yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1)
) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 2048
y1 = yindex // 2048
tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last'
)
tl.store(out_ptr0 + (y0 + 2048 * x2 + 18432 * y1), tmp0, xmask)
@triton.jit
def triton_per_fused_add_div_sqrt_sub_var_mean_6(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-10
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_poi_fused_constant_pad_nd_7(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x2 = xindex // 8704 % 34
x1 = xindex // 256 % 34
x3 = xindex // 295936
x4 = xindex % 8704
x6 = xindex
tmp0 = -1 + x2
tmp1 = tl.full([1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1], 32, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = -1 + x1
tmp6 = tmp5 >= tmp1
tmp7 = tmp5 < tmp3
tmp8 = tmp2 & tmp4
tmp9 = tmp8 & tmp6
tmp10 = tmp9 & tmp7
tmp11 = tl.load(in_ptr0 + (-8448 + x4 + 8192 * x2 + 262144 * x3), tmp10,
other=0.0)
tl.store(out_ptr0 + x6, tmp11, None)
@triton.jit
def triton_poi_fused_max_pool2d_with_indices_8(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex % 256
x1 = xindex // 256 % 16
x2 = xindex // 4096 % 16
x3 = xindex // 65536
x4 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 512 * x1 + 17408 * x2 + 295936 * x3), None)
tmp1 = tl.load(in_ptr0 + (256 + x0 + 512 * x1 + 17408 * x2 + 295936 *
x3), None)
tmp3 = tl.load(in_ptr0 + (512 + x0 + 512 * x1 + 17408 * x2 + 295936 *
x3), None)
tmp5 = tl.load(in_ptr0 + (8704 + x0 + 512 * x1 + 17408 * x2 + 295936 *
x3), None)
tmp7 = tl.load(in_ptr0 + (8960 + x0 + 512 * x1 + 17408 * x2 + 295936 *
x3), None)
tmp9 = tl.load(in_ptr0 + (9216 + x0 + 512 * x1 + 17408 * x2 + 295936 *
x3), None)
tmp11 = tl.load(in_ptr0 + (17408 + x0 + 512 * x1 + 17408 * x2 + 295936 *
x3), None)
tmp13 = tl.load(in_ptr0 + (17664 + x0 + 512 * x1 + 17408 * x2 + 295936 *
x3), None)
tmp15 = tl.load(in_ptr0 + (17920 + x0 + 512 * x1 + 17408 * x2 + 295936 *
x3), None)
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, None)
tl.store(out_ptr1 + x4, tmp41, None)
@triton.jit
def triton_red_fused_native_group_norm_9(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 % 8
r3 = rindex // 8
tmp0 = tl.load(in_ptr0 + (r2 + 8 * x0 + 256 * 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-05
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_native_group_norm_relu_10(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 // 65536
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 = 2048.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-05
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_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-10
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_add_div_sqrt_sub_var_mean_12(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-10
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_add_div_sqrt_sub_var_mean_13(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-10
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_poi_fused_add_14(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, None)
tmp1 = tl.load(in_out_ptr0 + x0, None)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x0, tmp2, None)
@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 = 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 % 32
r3 = rindex // 32
tmp0 = tl.load(in_ptr0 + (r2 + 32 * x0 + 1024 * 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-05
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_native_group_norm_relu_16(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 // 262144
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 = 8192.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-05
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_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-10
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_18(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, None)
tmp1 = tl.load(in_ptr0 + x0, None)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x0, tmp2, 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-10
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_add_div_sqrt_sub_var_mean_20(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-10
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_21(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 % 16
r3 = rindex // 16
tmp0 = tl.load(in_ptr0 + (r2 + 16 * x0 + 512 * 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-05
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_native_group_norm_relu_22(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 // 131072
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 = 4096.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-05
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_23(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-10
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_24(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-05
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_25(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-05
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_26(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-10
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_poi_fused_add_27(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_ptr0 + x0, None)
tmp1 = tl.load(in_out_ptr0 + x0, None)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x0, tmp2, 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-05
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_native_group_norm_relu_29(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 % 2048
x2 = xindex // 131072
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 64), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 64), 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 = 4096.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-05
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_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-10
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_31(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 + x0, None)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x0, tmp2, 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-10
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_red_fused_add_div_sqrt_sub_var_mean_33(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-10
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_34(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-05
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_native_group_norm_relu_35(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-05
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_36(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-10
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_37(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-05
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_38(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
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-05
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_39(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-10
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_40(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, None)
tmp1 = tl.load(in_out_ptr0 + x0, None)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x0, tmp2, 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-05
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_native_group_norm_relu_42(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 % 4096
x2 = xindex // 65536
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 128), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 128), 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-05
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_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-10
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_44(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 + x0, None)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x0, tmp2, None)
@triton.jit
def triton_red_fused_add_div_sqrt_sub_var_mean_45(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
rnumel = 4096
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 + 4096 * 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 = 4096.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-10
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 + 4096 * x0), rmask, eviction_policy=
'evict_first', other=0.0)
tmp11 = tmp10 - tmp2
tmp12 = tmp11 / tmp9
tl.store(out_ptr1 + (r1 + 4096 * x0), tmp12, rmask)
@triton.jit
def triton_red_fused_add_div_sqrt_sub_var_mean_46(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
rnumel = 4096
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 + 4096 * 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 = 4096.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-10
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 + 4096 * x0), rmask, eviction_policy=
'evict_first', other=0.0)
tmp11 = tmp10 - tmp2
tmp12 = tmp11 / tmp9
tl.store(out_ptr1 + (r1 + 4096 * x0), tmp12, rmask)
@triton.jit
def triton_per_fused_native_group_norm_47(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 % 64
r3 = rindex // 64
x0 = xindex % 32
x1 = xindex // 32
x4 = xindex
tmp0 = tl.load(in_ptr0 + (r2 + 64 * x0 + 2048 * 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-05
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_48(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 % 2048
x2 = xindex // 32768
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 64), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 64), 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-05
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_49(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
rnumel = 18432
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 + 18432 * 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 = 18432.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-10
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 + 18432 * x0), rmask, eviction_policy
='evict_first', other=0.0)
tmp11 = tmp10 - tmp2
tmp12 = tmp11 / tmp9
tl.store(out_ptr1 + (r1 + 18432 * x0), tmp12, rmask)
@triton.jit
def triton_per_fused_native_group_norm_50(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, 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)
r2 = rindex % 64
r3 = rindex // 64
x0 = xindex % 32
x1 = xindex // 32
x4 = xindex
tmp0 = tl.load(in_ptr0 + (r2 + 64 * x0 + 2048 * r3 + 8192 * 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], 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.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_51(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 % 2048
x2 = xindex // 8192
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 64), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 64), 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 = 256.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-05
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_52(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-10
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_poi_fused_add_53(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_ptr0 + x0, None)
tmp1 = tl.load(in_out_ptr0 + x0, None)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x0, tmp2, None)
@triton.jit
def triton_per_fused_native_group_norm_54(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 % 256
r3 = rindex // 256
x0 = xindex % 32
x1 = xindex // 32
x4 = xindex
tmp0 = tl.load(in_ptr0 + (r2 + 256 * x0 + 8192 * 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-05
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_55(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 % 8192
x2 = xindex // 32768
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 256), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 256), 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-05
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_56(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
rnumel = 8192
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 + 8192 * 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 = 8192.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-10
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 + 8192 * x0), rmask, eviction_policy=
'evict_first', other=0.0)
tmp11 = tmp10 - tmp2
tmp12 = tmp11 / tmp9
tl.store(out_ptr1 + (r1 + 8192 * x0), tmp12, rmask)
@triton.jit
def triton_poi_fused_add_57(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 + x0, None)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x0, tmp2, None)
@triton.jit
def triton_per_fused_native_group_norm_58(in_out_ptr0, in_ptr0, out_ptr0,
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 % 256
r3 = rindex // 256
x0 = xindex % 32
x1 = xindex // 32
x4 = xindex
tmp0 = tl.load(in_ptr0 + (r2 + 256 * x0 + 8192 * 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-05
tmp17 = tmp15 + tmp16
tmp18 = libdevice.rsqrt(tmp17)
tl.debug_barrier()
tl.store(in_out_ptr0 + x4, tmp18, None)
tl.store(out_ptr0 + x4, tmp8, None)
@triton.jit
def triton_poi_fused_mean_native_group_norm_relu_59(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)
x0 = xindex % 8192
x1 = xindex // 8192
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 32768 * x1), None)
tmp1 = tl.load(in_ptr1 + x2 // 256, None, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + x2 // 256, None, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr0 + (8192 + x0 + 32768 * x1), None)
tmp18 = tl.load(in_ptr0 + (16384 + x0 + 32768 * x1), None)
tmp25 = tl.load(in_ptr0 + (24576 + x0 + 32768 * x1), None)
tmp2 = tmp0 - tmp1
tmp4 = tmp2 * tmp3
tmp6 = tmp4 * tmp5
tmp8 = tmp6 + tmp7
tmp9 = tl.full([1], 0, tl.int32)
tmp10 = triton_helpers.maximum(tmp9, tmp8)
tmp12 = tmp11 - tmp1
tmp13 = tmp12 * tmp3
tmp14 = tmp13 * tmp5
tmp15 = tmp14 + tmp7
tmp16 = triton_helpers.maximum(tmp9, tmp15)
tmp17 = tmp10 + tmp16
tmp19 = tmp18 - tmp1
tmp20 = tmp19 * tmp3
tmp21 = tmp20 * tmp5
tmp22 = tmp21 + tmp7
tmp23 = triton_helpers.maximum(tmp9, tmp22)
tmp24 = tmp17 + tmp23
tmp26 = tmp25 - tmp1
tmp27 = tmp26 * tmp3
tmp28 = tmp27 * tmp5
tmp29 = tmp28 + tmp7
tmp30 = triton_helpers.maximum(tmp9, tmp29)
tmp31 = tmp24 + tmp30
tmp32 = 4.0
tmp33 = tmp31 / tmp32
tl.store(out_ptr0 + x2, tmp33, None)
@triton.jit
def triton_poi_fused_convolution_60(in_out_ptr0, in_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 87372
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 21843
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x2, tmp2, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, 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, primals_122,
primals_123, primals_124, primals_125, primals_126, primals_127,
primals_128, primals_129, primals_130, primals_131, primals_132,
primals_133, primals_134, primals_135, primals_136, primals_137,
primals_138, primals_139, primals_140, primals_141, primals_142,
primals_143, primals_144, primals_145, primals_146, primals_147,
primals_148, primals_149, primals_150, primals_151, primals_152,
primals_153, primals_154) = 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, (256, 256, 1, 1), (256, 1, 1, 1))
assert_size_stride(primals_7, (256,), (1,))
assert_size_stride(primals_8, (256,), (1,))
assert_size_stride(primals_9, (256, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_10, (256,), (1,))
assert_size_stride(primals_11, (256,), (1,))
assert_size_stride(primals_12, (1024, 256, 1, 1), (256, 1, 1, 1))
assert_size_stride(primals_13, (1024,), (1,))
assert_size_stride(primals_14, (1024,), (1,))
assert_size_stride(primals_15, (256, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_16, (256,), (1,))
assert_size_stride(primals_17, (256,), (1,))
assert_size_stride(primals_18, (256, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_19, (256,), (1,))
assert_size_stride(primals_20, (256,), (1,))
assert_size_stride(primals_21, (1024, 256, 1, 1), (256, 1, 1, 1))
assert_size_stride(primals_22, (1024,), (1,))
assert_size_stride(primals_23, (1024,), (1,))
assert_size_stride(primals_24, (256, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_25, (256,), (1,))
assert_size_stride(primals_26, (256,), (1,))
assert_size_stride(primals_27, (256, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_28, (256,), (1,))
assert_size_stride(primals_29, (256,), (1,))
assert_size_stride(primals_30, (1024, 256, 1, 1), (256, 1, 1, 1))
assert_size_stride(primals_31, (1024,), (1,))
assert_size_stride(primals_32, (1024,), (1,))
assert_size_stride(primals_33, (256, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_34, (256,), (1,))
assert_size_stride(primals_35, (256,), (1,))
assert_size_stride(primals_36, (256, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_37, (256,), (1,))
assert_size_stride(primals_38, (256,), (1,))
assert_size_stride(primals_39, (1024, 256, 1, 1), (256, 1, 1, 1))
assert_size_stride(primals_40, (1024,), (1,))
assert_size_stride(primals_41, (1024,), (1,))
assert_size_stride(primals_42, (2048, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_43, (512, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_44, (512,), (1,))
assert_size_stride(primals_45, (512,), (1,))
assert_size_stride(primals_46, (512, 512, 3, 3), (4608, 9, 3, 1))
assert_size_stride(primals_47, (512,), (1,))
assert_size_stride(primals_48, (512,), (1,))
assert_size_stride(primals_49, (2048, 512, 1, 1), (512, 1, 1, 1))
assert_size_stride(primals_50, (2048,), (1,))
assert_size_stride(primals_51, (2048,), (1,))
assert_size_stride(primals_52, (512, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_53, (512,), (1,))
assert_size_stride(primals_54, (512,), (1,))
assert_size_stride(primals_55, (512, 512, 3, 3), (4608, 9, 3, 1))
assert_size_stride(primals_56, (512,), (1,))
assert_size_stride(primals_57, (512,), (1,))
assert_size_stride(primals_58, (2048, 512, 1, 1), (512, 1, 1, 1))
assert_size_stride(primals_59, (2048,), (1,))
assert_size_stride(primals_60, (2048,), (1,))
assert_size_stride(primals_61, (512, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_62, (512,), (1,))
assert_size_stride(primals_63, (512,), (1,))
assert_size_stride(primals_64, (512, 512, 3, 3), (4608, 9, 3, 1))
assert_size_stride(primals_65, (512,), (1,))
assert_size_stride(primals_66, (512,), (1,))
assert_size_stride(primals_67, (2048, 512, 1, 1), (512, 1, 1, 1))
assert_size_stride(primals_68, (2048,), (1,))
assert_size_stride(primals_69, (2048,), (1,))
assert_size_stride(primals_70, (512, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_71, (512,), (1,))
assert_size_stride(primals_72, (512,), (1,))
assert_size_stride(primals_73, (512, 512, 3, 3), (4608, 9, 3, 1))
assert_size_stride(primals_74, (512,), (1,))
assert_size_stride(primals_75, (512,), (1,))
assert_size_stride(primals_76, (2048, 512, 1, 1), (512, 1, 1, 1))
assert_size_stride(primals_77, (2048,), (1,))
assert_size_stride(primals_78, (2048,), (1,))
assert_size_stride(primals_79, (4096, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_80, (1024, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_81, (1024,), (1,))
assert_size_stride(primals_82, (1024,), (1,))
assert_size_stride(primals_83, (1024, 1024, 3, 3), (9216, 9, 3, 1))
assert_size_stride(primals_84, (1024,), (1,))
assert_size_stride(primals_85, (1024,), (1,))
assert_size_stride(primals_86, (4096, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_87, (4096,), (1,))
assert_size_stride(primals_88, (4096,), (1,))
assert_size_stride(primals_89, (1024, 4096, 1, 1), (4096, 1, 1, 1))
assert_size_stride(primals_90, (1024,), (1,))
assert_size_stride(primals_91, (1024,), (1,))
assert_size_stride(primals_92, (1024, 1024, 3, 3), (9216, 9, 3, 1))
assert_size_stride(primals_93, (1024,), (1,))
assert_size_stride(primals_94, (1024,), (1,))
assert_size_stride(primals_95, (4096, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_96, (4096,), (1,))
assert_size_stride(primals_97, (4096,), (1,))
assert_size_stride(primals_98, (1024, 4096, 1, 1), (4096, 1, 1, 1))
assert_size_stride(primals_99, (1024,), (1,))
assert_size_stride(primals_100, (1024,), (1,))
assert_size_stride(primals_101, (1024, 1024, 3, 3), (9216, 9, 3, 1))
assert_size_stride(primals_102, (1024,), (1,))
assert_size_stride(primals_103, (1024,), (1,))
assert_size_stride(primals_104, (4096, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_105, (4096,), (1,))
assert_size_stride(primals_106, (4096,), (1,))
assert_size_stride(primals_107, (1024, 4096, 1, 1), (4096, 1, 1, 1))
assert_size_stride(primals_108, (1024,), (1,))
assert_size_stride(primals_109, (1024,), (1,))
assert_size_stride(primals_110, (1024, 1024, 3, 3), (9216, 9, 3, 1))
assert_size_stride(primals_111, (1024,), (1,))
assert_size_stride(primals_112, (1024,), (1,))
assert_size_stride(primals_113, (4096, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_114, (4096,), (1,))
assert_size_stride(primals_115, (4096,), (1,))
assert_size_stride(primals_116, (8192, 4096, 1, 1), (4096, 1, 1, 1))
assert_size_stride(primals_117, (2048, 4096, 1, 1), (4096, 1, 1, 1))
assert_size_stride(primals_118, (2048,), (1,))
assert_size_stride(primals_119, (2048,), (1,))
assert_size_stride(primals_120, (2048, 2048, 3, 3), (18432, 9, 3, 1))
assert_size_stride(primals_121, (2048,), (1,))
assert_size_stride(primals_122, (2048,), (1,))
assert_size_stride(primals_123, (8192, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_124, (8192,), (1,))
assert_size_stride(primals_125, (8192,), (1,))
assert_size_stride(primals_126, (2048, 8192, 1, 1), (8192, 1, 1, 1))
assert_size_stride(primals_127, (2048,), (1,))
assert_size_stride(primals_128, (2048,), (1,))
assert_size_stride(primals_129, (2048, 2048, 3, 3), (18432, 9, 3, 1))
assert_size_stride(primals_130, (2048,), (1,))
assert_size_stride(primals_131, (2048,), (1,))
assert_size_stride(primals_132, (8192, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_133, (8192,), (1,))
assert_size_stride(primals_134, (8192,), (1,))
assert_size_stride(primals_135, (2048, 8192, 1, 1), (8192, 1, 1, 1))
assert_size_stride(primals_136, (2048,), (1,))
assert_size_stride(primals_137, (2048,), (1,))
assert_size_stride(primals_138, (2048, 2048, 3, 3), (18432, 9, 3, 1))
assert_size_stride(primals_139, (2048,), (1,))
assert_size_stride(primals_140, (2048,), (1,))
assert_size_stride(primals_141, (8192, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_142, (8192,), (1,))
assert_size_stride(primals_143, (8192,), (1,))
assert_size_stride(primals_144, (2048, 8192, 1, 1), (8192, 1, 1, 1))
assert_size_stride(primals_145, (2048,), (1,))
assert_size_stride(primals_146, (2048,), (1,))
assert_size_stride(primals_147, (2048, 2048, 3, 3), (18432, 9, 3, 1))
assert_size_stride(primals_148, (2048,), (1,))
assert_size_stride(primals_149, (2048,), (1,))
assert_size_stride(primals_150, (8192, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_151, (8192,), (1,))
assert_size_stride(primals_152, (8192,), (1,))
assert_size_stride(primals_153, (21843, 8192, 1, 1), (8192, 1, 1, 1))
assert_size_stride(primals_154, (21843,), (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_9, buf2, 65536, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_9
buf3 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_poi_fused_2[grid(65536, 9)](primals_18, buf3, 65536, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_18
buf4 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_poi_fused_2[grid(65536, 9)](primals_27, buf4, 65536, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_27
buf5 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_poi_fused_2[grid(65536, 9)](primals_36, buf5, 65536, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_36
buf6 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512),
torch.float32)
triton_poi_fused_3[grid(262144, 9)](primals_46, buf6, 262144, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_46
buf7 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512),
torch.float32)
triton_poi_fused_3[grid(262144, 9)](primals_55, buf7, 262144, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_55
buf8 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512),
torch.float32)
triton_poi_fused_3[grid(262144, 9)](primals_64, buf8, 262144, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_64
buf9 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512),
torch.float32)
triton_poi_fused_3[grid(262144, 9)](primals_73, buf9, 262144, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_73
buf10 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072, 1024
), torch.float32)
triton_poi_fused_4[grid(1048576, 9)](primals_83, buf10, 1048576, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_83
buf11 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072, 1024
), torch.float32)
triton_poi_fused_4[grid(1048576, 9)](primals_92, buf11, 1048576, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_92
buf12 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072, 1024
), torch.float32)
triton_poi_fused_4[grid(1048576, 9)](primals_101, buf12, 1048576, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_101
buf13 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072, 1024
), torch.float32)
triton_poi_fused_4[grid(1048576, 9)](primals_110, buf13, 1048576, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_110
buf14 = empty_strided_cuda((2048, 2048, 3, 3), (18432, 1, 6144,
2048), torch.float32)
triton_poi_fused_5[grid(4194304, 9)](primals_120, buf14, 4194304, 9,
XBLOCK=16, YBLOCK=128, num_warps=8, num_stages=1)
del primals_120
buf15 = empty_strided_cuda((2048, 2048, 3, 3), (18432, 1, 6144,
2048), torch.float32)
triton_poi_fused_5[grid(4194304, 9)](primals_129, buf15, 4194304, 9,
XBLOCK=16, YBLOCK=128, num_warps=8, num_stages=1)
del primals_129
buf16 = empty_strided_cuda((2048, 2048, 3, 3), (18432, 1, 6144,
2048), torch.float32)
triton_poi_fused_5[grid(4194304, 9)](primals_138, buf16, 4194304, 9,
XBLOCK=16, YBLOCK=128, num_warps=8, num_stages=1)
del primals_138
buf17 = empty_strided_cuda((2048, 2048, 3, 3), (18432, 1, 6144,
2048), torch.float32)
triton_poi_fused_5[grid(4194304, 9)](primals_147, buf17, 4194304, 9,
XBLOCK=16, YBLOCK=128, num_warps=8, num_stages=1)
del primals_147
buf19 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256),
torch.float32)
buf21 = reinterpret_tensor(buf19, (256, 1, 1, 1), (1, 1, 1, 1), 0)
del buf19
buf22 = empty_strided_cuda((256, 3, 7, 7), (147, 1, 21, 3), torch.
float32)
triton_per_fused_add_div_sqrt_sub_var_mean_6[grid(256)](buf21, buf0,
buf22, 256, 147, XBLOCK=1, num_warps=2, num_stages=1)
buf23 = extern_kernels.convolution(buf1, buf22, stride=(2, 2),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf23, (4, 256, 32, 32), (262144, 1, 8192, 256))
buf24 = empty_strided_cuda((4, 256, 34, 34), (295936, 1, 8704, 256),
torch.float32)
triton_poi_fused_constant_pad_nd_7[grid(1183744)](buf23, buf24,
1183744, XBLOCK=1024, num_warps=4, num_stages=1)
buf25 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
buf26 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.int8)
triton_poi_fused_max_pool2d_with_indices_8[grid(262144)](buf24,
buf25, buf26, 262144, XBLOCK=512, num_warps=8, num_stages=1)
buf27 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf28 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf30 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_9[grid(128)](buf25, buf27, buf28,
buf30, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1
)
buf31 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf25,
buf27, buf28, primals_3, primals_4, buf31, 262144, XBLOCK=1024,
num_warps=4, num_stages=1)
del primals_4
buf33 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf35 = reinterpret_tensor(buf33, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf33
buf36 = empty_strided_cuda((1024, 256, 1, 1), (256, 1, 256, 256),
torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_11[grid(1024)](buf35,
primals_5, buf36, 1024, 256, num_warps=2, num_stages=1)
buf37 = extern_kernels.convolution(buf31, buf36, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf37, (4, 1024, 16, 16), (262144, 1, 16384, 1024))
buf39 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256),
torch.float32)
buf41 = reinterpret_tensor(buf39, (256, 1, 1, 1), (1, 1, 1, 1), 0)
del buf39
buf42 = empty_strided_cuda((256, 256, 1, 1), (256, 1, 256, 256),
torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_12[grid(256)](buf41,
primals_6, buf42, 256, 256, num_warps=2, num_stages=1)
buf43 = extern_kernels.convolution(buf31, buf42, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf43, (4, 256, 16, 16), (65536, 1, 4096, 256))
buf44 = buf28
del buf28
buf45 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf47 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_9[grid(128)](buf43, buf44, buf45,
buf47, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1
)
buf48 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf43,
buf44, buf45, primals_7, primals_8, buf48, 262144, XBLOCK=1024,
num_warps=4, num_stages=1)
del primals_8
buf50 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256),
torch.float32)
buf52 = reinterpret_tensor(buf50, (256, 1, 1, 1), (1, 1, 1, 1), 0)
del buf50
buf53 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_13[grid(256)](buf52,
buf2, buf53, 256, 2304, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf54 = extern_kernels.convolution(buf48, buf53, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf54, (4, 256, 16, 16), (65536, 1, 4096, 256))
buf55 = buf45
del buf45
buf56 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf58 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_9[grid(128)](buf54, buf55, buf56,
buf58, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1
)
buf59 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf54,
buf55, buf56, primals_10, primals_11, buf59, 262144, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_11
buf61 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf63 = reinterpret_tensor(buf61, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf61
buf64 = empty_strided_cuda((1024, 256, 1, 1), (256, 1, 256, 256),
torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_11[grid(1024)](buf63,
primals_12, buf64, 1024, 256, num_warps=2, num_stages=1)
buf65 = extern_kernels.convolution(buf59, buf64, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf65, (4, 1024, 16, 16), (262144, 1, 16384, 1024))
buf66 = buf37
del buf37
triton_poi_fused_add_14[grid(1048576)](buf66, buf65, 1048576,
XBLOCK=512, num_warps=8, num_stages=1)
buf67 = buf56
del buf56
buf68 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf70 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_15[grid(128)](buf66, buf67,
buf68, buf70, 128, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf71 = buf65
del buf65
triton_poi_fused_native_group_norm_relu_16[grid(1048576)](buf66,
buf67, buf68, primals_13, primals_14, buf71, 1048576, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_14
buf73 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256),
torch.float32)
buf75 = reinterpret_tensor(buf73, (256, 1, 1, 1), (1, 1, 1, 1), 0)
del buf73
buf76 = 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)](buf75,
primals_15, buf76, 256, 1024, num_warps=8, num_stages=1)
buf77 = extern_kernels.convolution(buf71, buf76, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf77, (4, 256, 16, 16), (65536, 1, 4096, 256))
buf78 = buf68
del buf68
buf79 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf81 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_9[grid(128)](buf77, buf78, buf79,
buf81, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1
)
buf82 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf77,
buf78, buf79, primals_16, primals_17, buf82, 262144, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_17
buf84 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256),
torch.float32)
buf86 = reinterpret_tensor(buf84, (256, 1, 1, 1), (1, 1, 1, 1), 0)
del buf84
buf87 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_13[grid(256)](buf86,
buf3, buf87, 256, 2304, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf88 = extern_kernels.convolution(buf82, buf87, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf88, (4, 256, 16, 16), (65536, 1, 4096, 256))
buf89 = buf79
del buf79
buf90 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf92 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_9[grid(128)](buf88, buf89, buf90,
buf92, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1
)
buf93 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf88,
buf89, buf90, primals_19, primals_20, buf93, 262144, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_20
buf95 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf97 = reinterpret_tensor(buf95, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf95
buf98 = empty_strided_cuda((1024, 256, 1, 1), (256, 1, 256, 256),
torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_11[grid(1024)](buf97,
primals_21, buf98, 1024, 256, num_warps=2, num_stages=1)
buf99 = extern_kernels.convolution(buf93, buf98, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf99, (4, 1024, 16, 16), (262144, 1, 16384, 1024))
buf100 = buf99
del buf99
triton_poi_fused_add_18[grid(1048576)](buf100, buf66, 1048576,
XBLOCK=512, num_warps=8, num_stages=1)
buf101 = buf90
del buf90
buf102 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf104 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_15[grid(128)](buf100, buf101,
buf102, buf104, 128, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf105 = reinterpret_tensor(buf23, (4, 1024, 16, 16), (262144, 1,
16384, 1024), 0)
del buf23
triton_poi_fused_native_group_norm_relu_16[grid(1048576)](buf100,
buf101, buf102, primals_22, primals_23, buf105, 1048576, XBLOCK
=1024, num_warps=4, num_stages=1)
del primals_23
buf107 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256),
torch.float32)
buf109 = reinterpret_tensor(buf107, (256, 1, 1, 1), (1, 1, 1, 1), 0)
del buf107
buf110 = 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)](buf109,
primals_24, buf110, 256, 1024, num_warps=8, num_stages=1)
buf111 = extern_kernels.convolution(buf105, buf110, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf111, (4, 256, 16, 16), (65536, 1, 4096, 256))
buf112 = buf102
del buf102
buf113 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf115 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_9[grid(128)](buf111, buf112,
buf113, buf115, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf116 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf111,
buf112, buf113, primals_25, primals_26, buf116, 262144, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_26
buf118 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256),
torch.float32)
buf120 = reinterpret_tensor(buf118, (256, 1, 1, 1), (1, 1, 1, 1), 0)
del buf118
buf121 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_13[grid(256)](buf120,
buf4, buf121, 256, 2304, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf122 = extern_kernels.convolution(buf116, buf121, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf122, (4, 256, 16, 16), (65536, 1, 4096, 256))
buf123 = buf113
del buf113
buf124 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf126 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_9[grid(128)](buf122, buf123,
buf124, buf126, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf127 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf122,
buf123, buf124, primals_28, primals_29, buf127, 262144, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_29
buf129 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf131 = reinterpret_tensor(buf129, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf129
buf132 = empty_strided_cuda((1024, 256, 1, 1), (256, 1, 256, 256),
torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_11[grid(1024)](buf131,
primals_30, buf132, 1024, 256, num_warps=2, num_stages=1)
buf133 = extern_kernels.convolution(buf127, buf132, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf133, (4, 1024, 16, 16), (262144, 1, 16384, 1024))
buf134 = buf133
del buf133
triton_poi_fused_add_18[grid(1048576)](buf134, buf100, 1048576,
XBLOCK=512, num_warps=8, num_stages=1)
buf135 = buf124
del buf124
buf136 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf138 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_15[grid(128)](buf134, buf135,
buf136, buf138, 128, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf139 = empty_strided_cuda((4, 1024, 16, 16), (262144, 1, 16384,
1024), torch.float32)
triton_poi_fused_native_group_norm_relu_16[grid(1048576)](buf134,
buf135, buf136, primals_31, primals_32, buf139, 1048576, XBLOCK
=1024, num_warps=4, num_stages=1)
del primals_32
buf141 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256),
torch.float32)
buf143 = reinterpret_tensor(buf141, (256, 1, 1, 1), (1, 1, 1, 1), 0)
del buf141
buf144 = 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)](buf143,
primals_33, buf144, 256, 1024, num_warps=8, num_stages=1)
buf145 = extern_kernels.convolution(buf139, buf144, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf145, (4, 256, 16, 16), (65536, 1, 4096, 256))
buf146 = buf136
del buf136
buf147 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf149 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_9[grid(128)](buf145, buf146,
buf147, buf149, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf150 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf145,
buf146, buf147, primals_34, primals_35, buf150, 262144, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_35
buf152 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256),
torch.float32)
buf154 = reinterpret_tensor(buf152, (256, 1, 1, 1), (1, 1, 1, 1), 0)
del buf152
buf155 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_13[grid(256)](buf154,
buf5, buf155, 256, 2304, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf156 = extern_kernels.convolution(buf150, buf155, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf156, (4, 256, 16, 16), (65536, 1, 4096, 256))
buf157 = buf147
del buf147
buf158 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf160 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_9[grid(128)](buf156, buf157,
buf158, buf160, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf161 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf156,
buf157, buf158, primals_37, primals_38, buf161, 262144, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_38
buf163 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf165 = reinterpret_tensor(buf163, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf163
buf166 = empty_strided_cuda((1024, 256, 1, 1), (256, 1, 256, 256),
torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_11[grid(1024)](buf165,
primals_39, buf166, 1024, 256, num_warps=2, num_stages=1)
buf167 = extern_kernels.convolution(buf161, buf166, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf167, (4, 1024, 16, 16), (262144, 1, 16384, 1024))
buf168 = buf167
del buf167
triton_poi_fused_add_18[grid(1048576)](buf168, buf134, 1048576,
XBLOCK=512, num_warps=8, num_stages=1)
buf169 = buf158
del buf158
buf170 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf172 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_15[grid(128)](buf168, buf169,
buf170, buf172, 128, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf173 = empty_strided_cuda((4, 1024, 16, 16), (262144, 1, 16384,
1024), torch.float32)
triton_poi_fused_native_group_norm_relu_16[grid(1048576)](buf168,
buf169, buf170, primals_40, primals_41, buf173, 1048576, XBLOCK
=1024, num_warps=4, num_stages=1)
del primals_41
buf175 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048),
torch.float32)
buf177 = reinterpret_tensor(buf175, (2048, 1, 1, 1), (1, 1, 1, 1), 0)
del buf175
buf178 = 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)](buf177,
primals_42, buf178, 2048, 1024, num_warps=8, num_stages=1)
buf179 = extern_kernels.convolution(buf173, buf178, stride=(2, 2),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf179, (4, 2048, 8, 8), (131072, 1, 16384, 2048))
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_20[grid(512)](buf183,
primals_43, buf184, 512, 1024, num_warps=8, num_stages=1)
buf185 = extern_kernels.convolution(buf173, 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, 16, 16), (131072, 1, 8192, 512))
buf186 = buf170
del buf170
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_21[grid(128)](buf185, buf186,
buf187, buf189, 128, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf190 = empty_strided_cuda((4, 512, 16, 16), (131072, 1, 8192, 512
), torch.float32)
triton_poi_fused_native_group_norm_relu_22[grid(524288)](buf185,
buf186, buf187, primals_44, primals_45, buf190, 524288, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_45
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_23[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_24[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_25[grid(131072)](buf196,
buf197, buf198, primals_47, primals_48, buf201, 131072, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_48
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_26[grid(2048)](buf205,
primals_49, 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 = buf179
del buf179
triton_poi_fused_add_27[grid(524288)](buf208, buf207, 524288,
XBLOCK=512, num_warps=8, num_stages=1)
buf209 = buf198
del buf198
buf210 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf212 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_28[grid(128)](buf208, buf209,
buf210, buf212, 128, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf213 = buf207
del buf207
triton_poi_fused_native_group_norm_relu_29[grid(524288)](buf208,
buf209, buf210, primals_50, primals_51, buf213, 524288, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_51
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_52, 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 = buf210
del buf210
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_24[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_25[grid(131072)](buf219,
buf220, buf221, primals_53, primals_54, buf224, 131072, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_54
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_23[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_24[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_25[grid(131072)](buf230,
buf231, buf232, primals_56, primals_57, buf235, 131072, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_57
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_26[grid(2048)](buf239,
primals_58, 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 = buf241
del buf241
triton_poi_fused_add_31[grid(524288)](buf242, buf208, 524288,
XBLOCK=512, num_warps=8, num_stages=1)
buf243 = buf232
del buf232
buf244 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf246 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_28[grid(128)](buf242, buf243,
buf244, buf246, 128, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf247 = empty_strided_cuda((4, 2048, 8, 8), (131072, 1, 16384,
2048), torch.float32)
triton_poi_fused_native_group_norm_relu_29[grid(524288)](buf242,
buf243, buf244, primals_59, primals_60, buf247, 524288, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_60
buf249 = empty_strided_cuda((512, 1, 1, 1), (1, 512, 512, 512),
torch.float32)
buf251 = reinterpret_tensor(buf249, (512, 1, 1, 1), (1, 1, 1, 1), 0)
del buf249
buf252 = 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)](buf251,
primals_61, buf252, 512, 2048, XBLOCK=1, RBLOCK=2048, num_warps
=16, num_stages=1)
buf253 = extern_kernels.convolution(buf247, buf252, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf253, (4, 512, 8, 8), (32768, 1, 4096, 512))
buf254 = buf244
del buf244
buf255 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf257 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_24[grid(128)](buf253, buf254,
buf255, buf257, 128, 1024, num_warps=8, num_stages=1)
buf258 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512),
torch.float32)
triton_poi_fused_native_group_norm_relu_25[grid(131072)](buf253,
buf254, buf255, primals_62, primals_63, buf258, 131072, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_63
buf260 = empty_strided_cuda((512, 1, 1, 1), (1, 512, 512, 512),
torch.float32)
buf262 = reinterpret_tensor(buf260, (512, 1, 1, 1), (1, 1, 1, 1), 0)
del buf260
buf263 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512),
torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_23[grid(512)](buf262,
buf8, buf263, 512, 4608, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf264 = extern_kernels.convolution(buf258, buf263, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf264, (4, 512, 8, 8), (32768, 1, 4096, 512))
buf265 = buf255
del buf255
buf266 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf268 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_24[grid(128)](buf264, buf265,
buf266, buf268, 128, 1024, num_warps=8, num_stages=1)
buf269 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512),
torch.float32)
triton_poi_fused_native_group_norm_relu_25[grid(131072)](buf264,
buf265, buf266, primals_65, primals_66, buf269, 131072, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_66
buf271 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048),
torch.float32)
buf273 = reinterpret_tensor(buf271, (2048, 1, 1, 1), (1, 1, 1, 1), 0)
del buf271
buf274 = empty_strided_cuda((2048, 512, 1, 1), (512, 1, 512, 512),
torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_26[grid(2048)](buf273,
primals_67, buf274, 2048, 512, num_warps=4, num_stages=1)
buf275 = extern_kernels.convolution(buf269, buf274, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf275, (4, 2048, 8, 8), (131072, 1, 16384, 2048))
buf276 = buf275
del buf275
triton_poi_fused_add_31[grid(524288)](buf276, buf242, 524288,
XBLOCK=512, num_warps=8, num_stages=1)
buf277 = buf266
del buf266
buf278 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf280 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_28[grid(128)](buf276, buf277,
buf278, buf280, 128, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf281 = empty_strided_cuda((4, 2048, 8, 8), (131072, 1, 16384,
2048), torch.float32)
triton_poi_fused_native_group_norm_relu_29[grid(524288)](buf276,
buf277, buf278, primals_68, primals_69, buf281, 524288, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_69
buf283 = empty_strided_cuda((512, 1, 1, 1), (1, 512, 512, 512),
torch.float32)
buf285 = reinterpret_tensor(buf283, (512, 1, 1, 1), (1, 1, 1, 1), 0)
del buf283
buf286 = 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)](buf285,
primals_70, buf286, 512, 2048, XBLOCK=1, RBLOCK=2048, num_warps
=16, num_stages=1)
buf287 = extern_kernels.convolution(buf281, buf286, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf287, (4, 512, 8, 8), (32768, 1, 4096, 512))
buf288 = buf278
del buf278
buf289 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf291 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_24[grid(128)](buf287, buf288,
buf289, buf291, 128, 1024, num_warps=8, num_stages=1)
buf292 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512),
torch.float32)
triton_poi_fused_native_group_norm_relu_25[grid(131072)](buf287,
buf288, buf289, primals_71, primals_72, buf292, 131072, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_72
buf294 = empty_strided_cuda((512, 1, 1, 1), (1, 512, 512, 512),
torch.float32)
buf296 = reinterpret_tensor(buf294, (512, 1, 1, 1), (1, 1, 1, 1), 0)
del buf294
buf297 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512),
torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_23[grid(512)](buf296,
buf9, buf297, 512, 4608, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf298 = extern_kernels.convolution(buf292, buf297, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf298, (4, 512, 8, 8), (32768, 1, 4096, 512))
buf299 = buf289
del buf289
buf300 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf302 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_24[grid(128)](buf298, buf299,
buf300, buf302, 128, 1024, num_warps=8, num_stages=1)
buf303 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512),
torch.float32)
triton_poi_fused_native_group_norm_relu_25[grid(131072)](buf298,
buf299, buf300, primals_74, primals_75, buf303, 131072, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_75
buf305 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048),
torch.float32)
buf307 = reinterpret_tensor(buf305, (2048, 1, 1, 1), (1, 1, 1, 1), 0)
del buf305
buf308 = empty_strided_cuda((2048, 512, 1, 1), (512, 1, 512, 512),
torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_26[grid(2048)](buf307,
primals_76, buf308, 2048, 512, num_warps=4, num_stages=1)
buf309 = extern_kernels.convolution(buf303, buf308, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf309, (4, 2048, 8, 8), (131072, 1, 16384, 2048))
buf310 = buf309
del buf309
triton_poi_fused_add_31[grid(524288)](buf310, buf276, 524288,
XBLOCK=512, num_warps=8, num_stages=1)
buf311 = buf300
del buf300
buf312 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf314 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_28[grid(128)](buf310, buf311,
buf312, buf314, 128, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf315 = empty_strided_cuda((4, 2048, 8, 8), (131072, 1, 16384,
2048), torch.float32)
triton_poi_fused_native_group_norm_relu_29[grid(524288)](buf310,
buf311, buf312, primals_77, primals_78, buf315, 524288, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_78
buf317 = empty_strided_cuda((4096, 1, 1, 1), (1, 4096, 4096, 4096),
torch.float32)
buf319 = reinterpret_tensor(buf317, (4096, 1, 1, 1), (1, 1, 1, 1), 0)
del buf317
buf320 = 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)](buf319,
primals_79, buf320, 4096, 2048, XBLOCK=1, RBLOCK=2048,
num_warps=16, num_stages=1)
buf321 = extern_kernels.convolution(buf315, buf320, stride=(2, 2),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf321, (4, 4096, 4, 4), (65536, 1, 16384, 4096))
buf323 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf325 = reinterpret_tensor(buf323, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf323
buf326 = empty_strided_cuda((1024, 2048, 1, 1), (2048, 1, 2048,
2048), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_33[grid(1024)](buf325,
primals_80, buf326, 1024, 2048, XBLOCK=1, RBLOCK=2048,
num_warps=16, num_stages=1)
buf327 = extern_kernels.convolution(buf315, buf326, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf327, (4, 1024, 8, 8), (65536, 1, 8192, 1024))
buf328 = buf312
del buf312
buf329 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf331 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_34[grid(128)](buf327, buf328,
buf329, buf331, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf332 = empty_strided_cuda((4, 1024, 8, 8), (65536, 1, 8192, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_35[grid(262144)](buf327,
buf328, buf329, primals_81, primals_82, buf332, 262144, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_82
buf334 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf336 = reinterpret_tensor(buf334, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf334
buf337 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072,
1024), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_36[grid(1024)](buf336,
buf10, buf337, 1024, 9216, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf338 = extern_kernels.convolution(buf332, buf337, stride=(2, 2),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf338, (4, 1024, 4, 4), (16384, 1, 4096, 1024))
buf339 = buf329
del buf329
buf340 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf342 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_37[grid(128)](buf338, buf339,
buf340, buf342, 128, 512, num_warps=4, num_stages=1)
buf343 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_38[grid(65536)](buf338,
buf339, buf340, primals_84, primals_85, buf343, 65536, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_85
buf345 = empty_strided_cuda((4096, 1, 1, 1), (1, 4096, 4096, 4096),
torch.float32)
buf347 = reinterpret_tensor(buf345, (4096, 1, 1, 1), (1, 1, 1, 1), 0)
del buf345
buf348 = empty_strided_cuda((4096, 1024, 1, 1), (1024, 1, 1024,
1024), torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_39[grid(4096)](buf347,
primals_86, buf348, 4096, 1024, num_warps=8, num_stages=1)
buf349 = extern_kernels.convolution(buf343, buf348, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf349, (4, 4096, 4, 4), (65536, 1, 16384, 4096))
buf350 = buf321
del buf321
triton_poi_fused_add_40[grid(262144)](buf350, buf349, 262144,
XBLOCK=512, num_warps=8, num_stages=1)
buf351 = buf340
del buf340
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 = buf349
del buf349
triton_poi_fused_native_group_norm_relu_42[grid(262144)](buf350,
buf351, buf352, primals_87, primals_88, buf355, 262144, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_88
buf357 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf359 = reinterpret_tensor(buf357, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf357
buf360 = 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)](buf359,
primals_89, buf360, 1024, 4096, XBLOCK=1, RBLOCK=2048,
num_warps=16, num_stages=1)
buf361 = extern_kernels.convolution(buf355, buf360, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf361, (4, 1024, 4, 4), (16384, 1, 4096, 1024))
buf362 = buf352
del buf352
buf363 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf365 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_37[grid(128)](buf361, buf362,
buf363, buf365, 128, 512, num_warps=4, num_stages=1)
buf366 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_38[grid(65536)](buf361,
buf362, buf363, primals_90, primals_91, buf366, 65536, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_91
buf368 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf370 = reinterpret_tensor(buf368, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf368
buf371 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072,
1024), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_36[grid(1024)](buf370,
buf11, buf371, 1024, 9216, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf372 = extern_kernels.convolution(buf366, buf371, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf372, (4, 1024, 4, 4), (16384, 1, 4096, 1024))
buf373 = buf363
del buf363
buf374 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf376 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_37[grid(128)](buf372, buf373,
buf374, buf376, 128, 512, num_warps=4, num_stages=1)
buf377 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_38[grid(65536)](buf372,
buf373, buf374, primals_93, primals_94, buf377, 65536, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_94
buf379 = empty_strided_cuda((4096, 1, 1, 1), (1, 4096, 4096, 4096),
torch.float32)
buf381 = reinterpret_tensor(buf379, (4096, 1, 1, 1), (1, 1, 1, 1), 0)
del buf379
buf382 = empty_strided_cuda((4096, 1024, 1, 1), (1024, 1, 1024,
1024), torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_39[grid(4096)](buf381,
primals_95, buf382, 4096, 1024, num_warps=8, num_stages=1)
buf383 = extern_kernels.convolution(buf377, buf382, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf383, (4, 4096, 4, 4), (65536, 1, 16384, 4096))
buf384 = buf383
del buf383
triton_poi_fused_add_44[grid(262144)](buf384, buf350, 262144,
XBLOCK=1024, num_warps=4, num_stages=1)
buf385 = buf374
del buf374
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_native_group_norm_relu_42[grid(262144)](buf384,
buf385, buf386, primals_96, primals_97, buf389, 262144, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_97
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_98, 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_37[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_38[grid(65536)](buf395,
buf396, buf397, primals_99, primals_100, buf400, 65536, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_100
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_36[grid(1024)](buf404,
buf12, buf405, 1024, 9216, XBLOCK=1, RBLOCK=2048, 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_37[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_38[grid(65536)](buf406,
buf407, buf408, primals_102, primals_103, buf411, 65536, XBLOCK
=256, num_warps=4, num_stages=1)
del primals_103
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_39[grid(4096)](buf415,
primals_104, 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 = buf417
del buf417
triton_poi_fused_add_44[grid(262144)](buf418, buf384, 262144,
XBLOCK=1024, num_warps=4, num_stages=1)
buf419 = buf408
del buf408
buf420 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf422 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_41[grid(128)](buf418, buf419,
buf420, buf422, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf423 = empty_strided_cuda((4, 4096, 4, 4), (65536, 1, 16384, 4096
), torch.float32)
triton_poi_fused_native_group_norm_relu_42[grid(262144)](buf418,
buf419, buf420, primals_105, primals_106, buf423, 262144,
XBLOCK=512, num_warps=8, num_stages=1)
del primals_106
buf425 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf427 = reinterpret_tensor(buf425, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf425
buf428 = 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)](buf427,
primals_107, buf428, 1024, 4096, XBLOCK=1, RBLOCK=2048,
num_warps=16, num_stages=1)
buf429 = extern_kernels.convolution(buf423, buf428, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf429, (4, 1024, 4, 4), (16384, 1, 4096, 1024))
buf430 = buf420
del buf420
buf431 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf433 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_37[grid(128)](buf429, buf430,
buf431, buf433, 128, 512, num_warps=4, num_stages=1)
buf434 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_38[grid(65536)](buf429,
buf430, buf431, primals_108, primals_109, buf434, 65536, XBLOCK
=256, num_warps=4, num_stages=1)
del primals_109
buf436 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024),
torch.float32)
buf438 = reinterpret_tensor(buf436, (1024, 1, 1, 1), (1, 1, 1, 1), 0)
del buf436
buf439 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072,
1024), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_36[grid(1024)](buf438,
buf13, buf439, 1024, 9216, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf440 = extern_kernels.convolution(buf434, buf439, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf440, (4, 1024, 4, 4), (16384, 1, 4096, 1024))
buf441 = buf431
del buf431
buf442 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf444 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_37[grid(128)](buf440, buf441,
buf442, buf444, 128, 512, num_warps=4, num_stages=1)
buf445 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_38[grid(65536)](buf440,
buf441, buf442, primals_111, primals_112, buf445, 65536, XBLOCK
=256, num_warps=4, num_stages=1)
del primals_112
buf447 = empty_strided_cuda((4096, 1, 1, 1), (1, 4096, 4096, 4096),
torch.float32)
buf449 = reinterpret_tensor(buf447, (4096, 1, 1, 1), (1, 1, 1, 1), 0)
del buf447
buf450 = empty_strided_cuda((4096, 1024, 1, 1), (1024, 1, 1024,
1024), torch.float32)
triton_per_fused_add_div_sqrt_sub_var_mean_39[grid(4096)](buf449,
primals_113, buf450, 4096, 1024, num_warps=8, num_stages=1)
buf451 = extern_kernels.convolution(buf445, buf450, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf451, (4, 4096, 4, 4), (65536, 1, 16384, 4096))
buf452 = buf451
del buf451
triton_poi_fused_add_44[grid(262144)](buf452, buf418, 262144,
XBLOCK=1024, num_warps=4, num_stages=1)
buf453 = buf442
del buf442
buf454 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf456 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_41[grid(128)](buf452, buf453,
buf454, buf456, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf457 = empty_strided_cuda((4, 4096, 4, 4), (65536, 1, 16384, 4096
), torch.float32)
triton_poi_fused_native_group_norm_relu_42[grid(262144)](buf452,
buf453, buf454, primals_114, primals_115, buf457, 262144,
XBLOCK=512, num_warps=8, num_stages=1)
del primals_115
buf459 = empty_strided_cuda((8192, 1, 1, 1), (1, 8192, 8192, 8192),
torch.float32)
buf461 = reinterpret_tensor(buf459, (8192, 1, 1, 1), (1, 1, 1, 1), 0)
del buf459
buf462 = empty_strided_cuda((8192, 4096, 1, 1), (4096, 1, 4096,
4096), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_45[grid(8192)](buf461,
primals_116, buf462, 8192, 4096, XBLOCK=1, RBLOCK=2048,
num_warps=16, num_stages=1)
buf463 = extern_kernels.convolution(buf457, buf462, stride=(2, 2),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf463, (4, 8192, 2, 2), (32768, 1, 16384, 8192))
buf465 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048),
torch.float32)
buf467 = reinterpret_tensor(buf465, (2048, 1, 1, 1), (1, 1, 1, 1), 0)
del buf465
buf468 = empty_strided_cuda((2048, 4096, 1, 1), (4096, 1, 4096,
4096), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_46[grid(2048)](buf467,
primals_117, buf468, 2048, 4096, XBLOCK=1, RBLOCK=2048,
num_warps=16, num_stages=1)
buf469 = extern_kernels.convolution(buf457, buf468, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf469, (4, 2048, 4, 4), (32768, 1, 8192, 2048))
buf470 = buf454
del buf454
buf471 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf473 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_47[grid(128)](buf469, buf470,
buf471, buf473, 128, 1024, num_warps=8, num_stages=1)
buf474 = empty_strided_cuda((4, 2048, 4, 4), (32768, 1, 8192, 2048),
torch.float32)
triton_poi_fused_native_group_norm_relu_48[grid(131072)](buf469,
buf470, buf471, primals_118, primals_119, buf474, 131072,
XBLOCK=512, num_warps=8, num_stages=1)
del primals_119
buf476 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048),
torch.float32)
buf478 = reinterpret_tensor(buf476, (2048, 1, 1, 1), (1, 1, 1, 1), 0)
del buf476
buf479 = empty_strided_cuda((2048, 2048, 3, 3), (18432, 1, 6144,
2048), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_49[grid(2048)](buf478,
buf14, buf479, 2048, 18432, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf480 = extern_kernels.convolution(buf474, buf479, stride=(2, 2),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf480, (4, 2048, 2, 2), (8192, 1, 4096, 2048))
buf481 = buf471
del buf471
buf482 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf484 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_50[grid(128)](buf480, buf481,
buf482, buf484, 128, 256, num_warps=2, num_stages=1)
buf485 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048),
torch.float32)
triton_poi_fused_native_group_norm_relu_51[grid(32768)](buf480,
buf481, buf482, primals_121, primals_122, buf485, 32768, XBLOCK
=128, num_warps=4, num_stages=1)
del primals_122
buf487 = empty_strided_cuda((8192, 1, 1, 1), (1, 8192, 8192, 8192),
torch.float32)
buf489 = reinterpret_tensor(buf487, (8192, 1, 1, 1), (1, 1, 1, 1), 0)
del buf487
buf490 = empty_strided_cuda((8192, 2048, 1, 1), (2048, 1, 2048,
2048), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_52[grid(8192)](buf489,
primals_123, buf490, 8192, 2048, XBLOCK=1, RBLOCK=2048,
num_warps=16, num_stages=1)
buf491 = extern_kernels.convolution(buf485, buf490, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf491, (4, 8192, 2, 2), (32768, 1, 16384, 8192))
buf492 = buf463
del buf463
triton_poi_fused_add_53[grid(131072)](buf492, buf491, 131072,
XBLOCK=1024, num_warps=4, num_stages=1)
buf493 = buf482
del buf482
buf494 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf496 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_54[grid(128)](buf492, buf493,
buf494, buf496, 128, 1024, num_warps=8, num_stages=1)
buf497 = buf491
del buf491
triton_poi_fused_native_group_norm_relu_55[grid(131072)](buf492,
buf493, buf494, primals_124, primals_125, buf497, 131072,
XBLOCK=512, num_warps=8, num_stages=1)
del primals_125
buf499 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048),
torch.float32)
buf501 = reinterpret_tensor(buf499, (2048, 1, 1, 1), (1, 1, 1, 1), 0)
del buf499
buf502 = empty_strided_cuda((2048, 8192, 1, 1), (8192, 1, 8192,
8192), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_56[grid(2048)](buf501,
primals_126, buf502, 2048, 8192, XBLOCK=1, RBLOCK=2048,
num_warps=16, num_stages=1)
buf503 = extern_kernels.convolution(buf497, buf502, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf503, (4, 2048, 2, 2), (8192, 1, 4096, 2048))
buf504 = buf494
del buf494
buf505 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf507 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_50[grid(128)](buf503, buf504,
buf505, buf507, 128, 256, num_warps=2, num_stages=1)
buf508 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048),
torch.float32)
triton_poi_fused_native_group_norm_relu_51[grid(32768)](buf503,
buf504, buf505, primals_127, primals_128, buf508, 32768, XBLOCK
=128, num_warps=4, num_stages=1)
del primals_128
buf510 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048),
torch.float32)
buf512 = reinterpret_tensor(buf510, (2048, 1, 1, 1), (1, 1, 1, 1), 0)
del buf510
buf513 = empty_strided_cuda((2048, 2048, 3, 3), (18432, 1, 6144,
2048), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_49[grid(2048)](buf512,
buf15, buf513, 2048, 18432, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf514 = extern_kernels.convolution(buf508, buf513, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf514, (4, 2048, 2, 2), (8192, 1, 4096, 2048))
buf515 = buf505
del buf505
buf516 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf518 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_50[grid(128)](buf514, buf515,
buf516, buf518, 128, 256, num_warps=2, num_stages=1)
buf519 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048),
torch.float32)
triton_poi_fused_native_group_norm_relu_51[grid(32768)](buf514,
buf515, buf516, primals_130, primals_131, buf519, 32768, XBLOCK
=128, num_warps=4, num_stages=1)
del primals_131
buf521 = empty_strided_cuda((8192, 1, 1, 1), (1, 8192, 8192, 8192),
torch.float32)
buf523 = reinterpret_tensor(buf521, (8192, 1, 1, 1), (1, 1, 1, 1), 0)
del buf521
buf524 = empty_strided_cuda((8192, 2048, 1, 1), (2048, 1, 2048,
2048), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_52[grid(8192)](buf523,
primals_132, buf524, 8192, 2048, XBLOCK=1, RBLOCK=2048,
num_warps=16, num_stages=1)
buf525 = extern_kernels.convolution(buf519, buf524, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf525, (4, 8192, 2, 2), (32768, 1, 16384, 8192))
buf526 = buf525
del buf525
triton_poi_fused_add_57[grid(131072)](buf526, buf492, 131072,
XBLOCK=1024, num_warps=4, num_stages=1)
buf527 = buf516
del buf516
buf528 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf530 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_54[grid(128)](buf526, buf527,
buf528, buf530, 128, 1024, num_warps=8, num_stages=1)
buf531 = empty_strided_cuda((4, 8192, 2, 2), (32768, 1, 16384, 8192
), torch.float32)
triton_poi_fused_native_group_norm_relu_55[grid(131072)](buf526,
buf527, buf528, primals_133, primals_134, buf531, 131072,
XBLOCK=512, num_warps=8, num_stages=1)
del primals_134
buf533 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048),
torch.float32)
buf535 = reinterpret_tensor(buf533, (2048, 1, 1, 1), (1, 1, 1, 1), 0)
del buf533
buf536 = empty_strided_cuda((2048, 8192, 1, 1), (8192, 1, 8192,
8192), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_56[grid(2048)](buf535,
primals_135, buf536, 2048, 8192, XBLOCK=1, RBLOCK=2048,
num_warps=16, num_stages=1)
buf537 = extern_kernels.convolution(buf531, buf536, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf537, (4, 2048, 2, 2), (8192, 1, 4096, 2048))
buf538 = buf528
del buf528
buf539 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf541 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_50[grid(128)](buf537, buf538,
buf539, buf541, 128, 256, num_warps=2, num_stages=1)
buf542 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048),
torch.float32)
triton_poi_fused_native_group_norm_relu_51[grid(32768)](buf537,
buf538, buf539, primals_136, primals_137, buf542, 32768, XBLOCK
=128, num_warps=4, num_stages=1)
del primals_137
buf544 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048),
torch.float32)
buf546 = reinterpret_tensor(buf544, (2048, 1, 1, 1), (1, 1, 1, 1), 0)
del buf544
buf547 = empty_strided_cuda((2048, 2048, 3, 3), (18432, 1, 6144,
2048), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_49[grid(2048)](buf546,
buf16, buf547, 2048, 18432, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf548 = extern_kernels.convolution(buf542, buf547, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf548, (4, 2048, 2, 2), (8192, 1, 4096, 2048))
buf549 = buf539
del buf539
buf550 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf552 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_50[grid(128)](buf548, buf549,
buf550, buf552, 128, 256, num_warps=2, num_stages=1)
buf553 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048),
torch.float32)
triton_poi_fused_native_group_norm_relu_51[grid(32768)](buf548,
buf549, buf550, primals_139, primals_140, buf553, 32768, XBLOCK
=128, num_warps=4, num_stages=1)
del primals_140
buf555 = empty_strided_cuda((8192, 1, 1, 1), (1, 8192, 8192, 8192),
torch.float32)
buf557 = reinterpret_tensor(buf555, (8192, 1, 1, 1), (1, 1, 1, 1), 0)
del buf555
buf558 = empty_strided_cuda((8192, 2048, 1, 1), (2048, 1, 2048,
2048), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_52[grid(8192)](buf557,
primals_141, buf558, 8192, 2048, XBLOCK=1, RBLOCK=2048,
num_warps=16, num_stages=1)
buf559 = extern_kernels.convolution(buf553, buf558, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf559, (4, 8192, 2, 2), (32768, 1, 16384, 8192))
buf560 = buf559
del buf559
triton_poi_fused_add_57[grid(131072)](buf560, buf526, 131072,
XBLOCK=1024, num_warps=4, num_stages=1)
buf561 = buf550
del buf550
buf562 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf564 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_54[grid(128)](buf560, buf561,
buf562, buf564, 128, 1024, num_warps=8, num_stages=1)
buf565 = empty_strided_cuda((4, 8192, 2, 2), (32768, 1, 16384, 8192
), torch.float32)
triton_poi_fused_native_group_norm_relu_55[grid(131072)](buf560,
buf561, buf562, primals_142, primals_143, buf565, 131072,
XBLOCK=512, num_warps=8, num_stages=1)
del primals_143
buf567 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048),
torch.float32)
buf569 = reinterpret_tensor(buf567, (2048, 1, 1, 1), (1, 1, 1, 1), 0)
del buf567
buf570 = empty_strided_cuda((2048, 8192, 1, 1), (8192, 1, 8192,
8192), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_56[grid(2048)](buf569,
primals_144, buf570, 2048, 8192, XBLOCK=1, RBLOCK=2048,
num_warps=16, num_stages=1)
buf571 = extern_kernels.convolution(buf565, buf570, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf571, (4, 2048, 2, 2), (8192, 1, 4096, 2048))
buf572 = buf562
del buf562
buf573 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf575 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_50[grid(128)](buf571, buf572,
buf573, buf575, 128, 256, num_warps=2, num_stages=1)
buf576 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048),
torch.float32)
triton_poi_fused_native_group_norm_relu_51[grid(32768)](buf571,
buf572, buf573, primals_145, primals_146, buf576, 32768, XBLOCK
=128, num_warps=4, num_stages=1)
del primals_146
buf578 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048),
torch.float32)
buf580 = reinterpret_tensor(buf578, (2048, 1, 1, 1), (1, 1, 1, 1), 0)
del buf578
buf581 = empty_strided_cuda((2048, 2048, 3, 3), (18432, 1, 6144,
2048), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_49[grid(2048)](buf580,
buf17, buf581, 2048, 18432, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf582 = extern_kernels.convolution(buf576, buf581, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf582, (4, 2048, 2, 2), (8192, 1, 4096, 2048))
buf583 = buf573
del buf573
buf584 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf586 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_50[grid(128)](buf582, buf583,
buf584, buf586, 128, 256, num_warps=2, num_stages=1)
buf587 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048),
torch.float32)
triton_poi_fused_native_group_norm_relu_51[grid(32768)](buf582,
buf583, buf584, primals_148, primals_149, buf587, 32768, XBLOCK
=128, num_warps=4, num_stages=1)
del primals_149
buf589 = empty_strided_cuda((8192, 1, 1, 1), (1, 8192, 8192, 8192),
torch.float32)
buf591 = reinterpret_tensor(buf589, (8192, 1, 1, 1), (1, 1, 1, 1), 0)
del buf589
buf592 = empty_strided_cuda((8192, 2048, 1, 1), (2048, 1, 2048,
2048), torch.float32)
triton_red_fused_add_div_sqrt_sub_var_mean_52[grid(8192)](buf591,
primals_150, buf592, 8192, 2048, XBLOCK=1, RBLOCK=2048,
num_warps=16, num_stages=1)
buf593 = extern_kernels.convolution(buf587, buf592, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf593, (4, 8192, 2, 2), (32768, 1, 16384, 8192))
buf594 = buf593
del buf593
triton_poi_fused_add_57[grid(131072)](buf594, buf560, 131072,
XBLOCK=1024, num_warps=4, num_stages=1)
buf595 = reinterpret_tensor(buf584, (4, 32, 1, 1), (32, 1, 32, 32), 0)
del buf584
buf596 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf598 = reinterpret_tensor(buf596, (4, 32, 1, 1), (32, 1, 32, 32), 0)
del buf596
triton_per_fused_native_group_norm_58[grid(128)](buf598, buf594,
buf595, 128, 1024, num_warps=8, num_stages=1)
buf599 = empty_strided_cuda((4, 8192, 1, 1), (8192, 1, 8192, 8192),
torch.float32)
triton_poi_fused_mean_native_group_norm_relu_59[grid(32768)](buf594,
buf595, buf598, primals_151, primals_152, buf599, 32768, XBLOCK
=256, num_warps=4, num_stages=1)
buf600 = extern_kernels.convolution(buf599, primals_153, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf600, (4, 21843, 1, 1), (21843, 1, 21843, 21843))
buf601 = reinterpret_tensor(buf600, (4, 21843, 1, 1), (21843, 1,
87372, 87372), 0)
del buf600
triton_poi_fused_convolution_60[grid(87372)](buf601, primals_154,
87372, XBLOCK=512, num_warps=8, num_stages=1)
del primals_154
return (reinterpret_tensor(buf601, (4, 21843), (21843, 1), 0), buf0,
buf1, primals_3, primals_5, primals_6, primals_7, buf2, primals_10,
primals_12, primals_13, primals_15, primals_16, buf3, primals_19,
primals_21, primals_22, primals_24, primals_25, buf4, primals_28,
primals_30, primals_31, primals_33, primals_34, buf5, primals_37,
primals_39, primals_40, primals_42, primals_43, primals_44, buf6,
primals_47, primals_49, primals_50, primals_52, primals_53, buf7,
primals_56, primals_58, primals_59, primals_61, primals_62, buf8,
primals_65, primals_67, primals_68, primals_70, primals_71, buf9,
primals_74, primals_76, primals_77, primals_79, primals_80,
primals_81, buf10, primals_84, primals_86, primals_87, primals_89,
primals_90, buf11, primals_93, primals_95, primals_96, primals_98,
primals_99, buf12, primals_102, primals_104, primals_105,
primals_107, primals_108, buf13, primals_111, primals_113,
primals_114, primals_116, primals_117, primals_118, buf14,
primals_121, primals_123, primals_124, primals_126, primals_127,
buf15, primals_130, primals_132, primals_133, primals_135,
primals_136, buf16, primals_139, primals_141, primals_142,
primals_144, primals_145, buf17, primals_148, primals_150,
primals_151, primals_152, primals_153, buf21, buf22, buf24, buf25,
buf26, reinterpret_tensor(buf27, (4, 32), (32, 1), 0),
reinterpret_tensor(buf30, (4, 32), (32, 1), 0), buf31, buf35, buf36,
buf41, buf42, buf43, reinterpret_tensor(buf44, (4, 32), (32, 1), 0),
reinterpret_tensor(buf47, (4, 32), (32, 1), 0), buf48, buf52, buf53,
buf54, reinterpret_tensor(buf55, (4, 32), (32, 1), 0),
reinterpret_tensor(buf58, (4, 32), (32, 1), 0), buf59, buf63, buf64,
buf66, reinterpret_tensor(buf67, (4, 32), (32, 1), 0),
reinterpret_tensor(buf70, (4, 32), (32, 1), 0), buf71, buf75, buf76,
buf77, reinterpret_tensor(buf78, (4, 32), (32, 1), 0),
reinterpret_tensor(buf81, (4, 32), (32, 1), 0), buf82, buf86, buf87,
buf88, reinterpret_tensor(buf89, (4, 32), (32, 1), 0),
reinterpret_tensor(buf92, (4, 32), (32, 1), 0), buf93, buf97, buf98,
buf100, reinterpret_tensor(buf101, (4, 32), (32, 1), 0),
reinterpret_tensor(buf104, (4, 32), (32, 1), 0), buf105, buf109,
buf110, buf111, reinterpret_tensor(buf112, (4, 32), (32, 1), 0),
reinterpret_tensor(buf115, (4, 32), (32, 1), 0), buf116, buf120,
buf121, buf122, reinterpret_tensor(buf123, (4, 32), (32, 1), 0),
reinterpret_tensor(buf126, (4, 32), (32, 1), 0), buf127, buf131,
buf132, buf134, reinterpret_tensor(buf135, (4, 32), (32, 1), 0),
reinterpret_tensor(buf138, (4, 32), (32, 1), 0), buf139, buf143,
buf144, buf145, reinterpret_tensor(buf146, (4, 32), (32, 1), 0),
reinterpret_tensor(buf149, (4, 32), (32, 1), 0), buf150, buf154,
buf155, buf156, reinterpret_tensor(buf157, (4, 32), (32, 1), 0),
reinterpret_tensor(buf160, (4, 32), (32, 1), 0), buf161, buf165,
buf166, buf168, reinterpret_tensor(buf169, (4, 32), (32, 1), 0),
reinterpret_tensor(buf172, (4, 32), (32, 1), 0), buf173, buf177,
buf178, 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, buf208, reinterpret_tensor(buf209, (4, 32),
(32, 1), 0), reinterpret_tensor(buf212, (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, buf242, reinterpret_tensor(buf243, (4, 32),
(32, 1), 0), reinterpret_tensor(buf246, (4, 32), (32, 1), 0),
buf247, buf251, buf252, buf253, reinterpret_tensor(buf254, (4, 32),
(32, 1), 0), reinterpret_tensor(buf257, (4, 32), (32, 1), 0),
buf258, buf262, buf263, buf264, reinterpret_tensor(buf265, (4, 32),
(32, 1), 0), reinterpret_tensor(buf268, (4, 32), (32, 1), 0),
buf269, buf273, buf274, buf276, reinterpret_tensor(buf277, (4, 32),
(32, 1), 0), reinterpret_tensor(buf280, (4, 32), (32, 1), 0),
buf281, buf285, buf286, buf287, reinterpret_tensor(buf288, (4, 32),
(32, 1), 0), reinterpret_tensor(buf291, (4, 32), (32, 1), 0),
buf292, buf296, buf297, buf298, reinterpret_tensor(buf299, (4, 32),
(32, 1), 0), reinterpret_tensor(buf302, (4, 32), (32, 1), 0),
buf303, buf307, buf308, buf310, reinterpret_tensor(buf311, (4, 32),
(32, 1), 0), reinterpret_tensor(buf314, (4, 32), (32, 1), 0),
buf315, buf319, buf320, buf325, buf326, buf327, reinterpret_tensor(
buf328, (4, 32), (32, 1), 0), reinterpret_tensor(buf331, (4, 32), (
32, 1), 0), buf332, buf336, buf337, buf338, reinterpret_tensor(
buf339, (4, 32), (32, 1), 0), reinterpret_tensor(buf342, (4, 32), (
32, 1), 0), buf343, buf347, buf348, buf350, reinterpret_tensor(
buf351, (4, 32), (32, 1), 0), reinterpret_tensor(buf354, (4, 32), (
32, 1), 0), buf355, buf359, buf360, buf361, reinterpret_tensor(
buf362, (4, 32), (32, 1), 0), reinterpret_tensor(buf365, (4, 32), (
32, 1), 0), buf366, buf370, buf371, buf372, reinterpret_tensor(
buf373, (4, 32), (32, 1), 0), reinterpret_tensor(buf376, (4, 32), (
32, 1), 0), buf377, buf381, buf382, 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, buf418, reinterpret_tensor(
buf419, (4, 32), (32, 1), 0), reinterpret_tensor(buf422, (4, 32), (
32, 1), 0), buf423, buf427, buf428, buf429, reinterpret_tensor(
buf430, (4, 32), (32, 1), 0), reinterpret_tensor(buf433, (4, 32), (
32, 1), 0), buf434, buf438, buf439, buf440, reinterpret_tensor(
buf441, (4, 32), (32, 1), 0), reinterpret_tensor(buf444, (4, 32), (
32, 1), 0), buf445, buf449, buf450, buf452, reinterpret_tensor(
buf453, (4, 32), (32, 1), 0), reinterpret_tensor(buf456, (4, 32), (
32, 1), 0), buf457, buf461, buf462, buf467, buf468, buf469,
reinterpret_tensor(buf470, (4, 32), (32, 1), 0), reinterpret_tensor
(buf473, (4, 32), (32, 1), 0), buf474, buf478, buf479, buf480,
reinterpret_tensor(buf481, (4, 32), (32, 1), 0), reinterpret_tensor
(buf484, (4, 32), (32, 1), 0), buf485, buf489, buf490, buf492,
reinterpret_tensor(buf493, (4, 32), (32, 1), 0), reinterpret_tensor
(buf496, (4, 32), (32, 1), 0), buf497, buf501, buf502, buf503,
reinterpret_tensor(buf504, (4, 32), (32, 1), 0), reinterpret_tensor
(buf507, (4, 32), (32, 1), 0), buf508, buf512, buf513, buf514,
reinterpret_tensor(buf515, (4, 32), (32, 1), 0), reinterpret_tensor
(buf518, (4, 32), (32, 1), 0), buf519, buf523, buf524, buf526,
reinterpret_tensor(buf527, (4, 32), (32, 1), 0), reinterpret_tensor
(buf530, (4, 32), (32, 1), 0), buf531, buf535, buf536, buf537,
reinterpret_tensor(buf538, (4, 32), (32, 1), 0), reinterpret_tensor
(buf541, (4, 32), (32, 1), 0), buf542, buf546, buf547, buf548,
reinterpret_tensor(buf549, (4, 32), (32, 1), 0), reinterpret_tensor
(buf552, (4, 32), (32, 1), 0), buf553, buf557, buf558, buf560,
reinterpret_tensor(buf561, (4, 32), (32, 1), 0), reinterpret_tensor
(buf564, (4, 32), (32, 1), 0), buf565, buf569, buf570, buf571,
reinterpret_tensor(buf572, (4, 32), (32, 1), 0), reinterpret_tensor
(buf575, (4, 32), (32, 1), 0), buf576, buf580, buf581, buf582,
reinterpret_tensor(buf583, (4, 32), (32, 1), 0), reinterpret_tensor
(buf586, (4, 32), (32, 1), 0), buf587, buf591, buf592, buf594,
buf595, buf598, buf599)
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 conv1x1(cin, cout, stride=1, bias=False):
return StdConv2d(cin, cout, kernel_size=1, stride=stride, padding=0,
bias=bias)
def tf2th(conv_weights):
"""Possibly convert HWIO to OIHW."""
if conv_weights.ndim == 4:
conv_weights = conv_weights.transpose([3, 2, 0, 1])
return torch.from_numpy(conv_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-10)
return F.conv2d(x, w, self.bias, self.stride, self.padding, self.
dilation, self.groups)
class PreActBottleneck(nn.Module):
"""Pre-activation (v2) bottleneck block.
Follows the implementation of "Identity Mappings in Deep Residual Networks":
https://github.com/KaimingHe/resnet-1k-layers/blob/master/resnet-pre-act.lua
Except it puts the stride on 3x3 conv when available.
"""
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, cin)
self.conv1 = conv1x1(cin, cmid)
self.gn2 = nn.GroupNorm(32, cmid)
self.conv2 = conv3x3(cmid, cmid, stride)
self.gn3 = nn.GroupNorm(32, cmid)
self.conv3 = conv1x1(cmid, cout)
self.relu = nn.ReLU(inplace=True)
if stride != 1 or cin != cout:
self.downsample = conv1x1(cin, cout, stride)
def forward(self, x):
out = self.relu(self.gn1(x))
residual = x
if hasattr(self, 'downsample'):
residual = self.downsample(out)
out = self.conv1(out)
out = self.conv2(self.relu(self.gn2(out)))
out = self.conv3(self.relu(self.gn3(out)))
return out + residual
def load_from(self, weights, prefix=''):
convname = 'standardized_conv2d'
with torch.no_grad():
self.conv1.weight.copy_(tf2th(weights[
f'{prefix}a/{convname}/kernel']))
self.conv2.weight.copy_(tf2th(weights[
f'{prefix}b/{convname}/kernel']))
self.conv3.weight.copy_(tf2th(weights[
f'{prefix}c/{convname}/kernel']))
self.gn1.weight.copy_(tf2th(weights[f'{prefix}a/group_norm/gamma'])
)
self.gn2.weight.copy_(tf2th(weights[f'{prefix}b/group_norm/gamma'])
)
self.gn3.weight.copy_(tf2th(weights[f'{prefix}c/group_norm/gamma'])
)
self.gn1.bias.copy_(tf2th(weights[f'{prefix}a/group_norm/beta']))
self.gn2.bias.copy_(tf2th(weights[f'{prefix}b/group_norm/beta']))
self.gn3.bias.copy_(tf2th(weights[f'{prefix}c/group_norm/beta']))
if hasattr(self, 'downsample'):
w = weights[f'{prefix}a/proj/{convname}/kernel']
self.downsample.weight.copy_(tf2th(w))
class ResNetV2New(nn.Module):
"""Implementation of Pre-activation (v2) ResNet mode."""
def __init__(self, block_units, width_factor, head_size=21843,
zero_head=False):
super().__init__()
wf = width_factor
self.root = nn.Sequential(OrderedDict([('conv', StdConv2d(3, 64 *
wf, kernel_size=7, stride=2, padding=3, bias=False)), ('pad',
nn.ConstantPad2d(1, 0)), ('pool', nn.MaxPool2d(kernel_size=3,
stride=2, padding=0))]))
self.body = nn.Sequential(OrderedDict([('block1', nn.Sequential(
OrderedDict([('unit01', PreActBottleneck(cin=64 * wf, cout=256 *
wf, cmid=64 * wf))] + [(f'unit{i:02d}', PreActBottleneck(cin=
256 * wf, cout=256 * wf, cmid=64 * wf)) for i in range(2,
block_units[0] + 1)]))), ('block2', nn.Sequential(OrderedDict([
('unit01', PreActBottleneck(cin=256 * wf, cout=512 * wf, cmid=
128 * wf, stride=2))] + [(f'unit{i:02d}', PreActBottleneck(cin=
512 * wf, cout=512 * wf, cmid=128 * wf)) for i in range(2,
block_units[1] + 1)]))), ('block3', nn.Sequential(OrderedDict([
('unit01', PreActBottleneck(cin=512 * wf, cout=1024 * wf, cmid=
256 * wf, stride=2))] + [(f'unit{i:02d}', PreActBottleneck(cin=
1024 * wf, cout=1024 * wf, cmid=256 * wf)) for i in range(2,
block_units[2] + 1)]))), ('block4', nn.Sequential(OrderedDict([
('unit01', PreActBottleneck(cin=1024 * wf, cout=2048 * wf, cmid
=512 * wf, stride=2))] + [(f'unit{i:02d}', PreActBottleneck(cin
=2048 * wf, cout=2048 * wf, cmid=512 * wf)) for i in range(2,
block_units[3] + 1)])))]))
self.zero_head = zero_head
self.head = nn.Sequential(OrderedDict([('gn', nn.GroupNorm(32, 2048 *
wf)), ('relu', nn.ReLU(inplace=True)), ('avg', nn.
AdaptiveAvgPool2d(output_size=1)), ('conv', nn.Conv2d(2048 * wf,
head_size, kernel_size=1, bias=True))]))
def load_from(self, weights, prefix='resnet/'):
with torch.no_grad():
self.root.conv.weight.copy_(tf2th(weights[
f'{prefix}root_block/standardized_conv2d/kernel']))
self.head.gn.weight.copy_(tf2th(weights[
f'{prefix}group_norm/gamma']))
self.head.gn.bias.copy_(tf2th(weights[f'{prefix}group_norm/beta']))
if self.zero_head:
nn.init.zeros_(self.head.conv.weight)
nn.init.zeros_(self.head.conv.bias)
else:
self.head.conv.weight.copy_(tf2th(weights[
f'{prefix}head/conv2d/kernel']))
self.head.conv.bias.copy_(tf2th(weights[
f'{prefix}head/conv2d/bias']))
for bname, block in self.body.named_children():
for uname, unit in block.named_children():
unit.load_from(weights, prefix=f'{prefix}{bname}/{uname}/')
def forward(self, input_0):
primals_1 = self.root.conv.weight
primals_3 = self.body.block1.unit01.gn1.weight
primals_4 = self.body.block1.unit01.gn1.bias
primals_6 = self.body.block1.unit01.conv1.weight
primals_7 = self.body.block1.unit01.gn2.weight
primals_8 = self.body.block1.unit01.gn2.bias
primals_9 = self.body.block1.unit01.conv2.weight
primals_10 = self.body.block1.unit01.gn3.weight
primals_11 = self.body.block1.unit01.gn3.bias
primals_5 = self.body.block1.unit01.conv3.weight
primals_12 = self.body.block1.unit01.downsample.weight
primals_13 = self.body.block1.unit02.gn1.weight
primals_14 = self.body.block1.unit02.gn1.bias
primals_15 = self.body.block1.unit02.conv1.weight
primals_16 = self.body.block1.unit02.gn2.weight
primals_17 = self.body.block1.unit02.gn2.bias
primals_18 = self.body.block1.unit02.conv2.weight
primals_19 = self.body.block1.unit02.gn3.weight
primals_20 = self.body.block1.unit02.gn3.bias
primals_21 = self.body.block1.unit02.conv3.weight
primals_22 = self.body.block1.unit03.gn1.weight
primals_23 = self.body.block1.unit03.gn1.bias
primals_24 = self.body.block1.unit03.conv1.weight
primals_25 = self.body.block1.unit03.gn2.weight
primals_26 = self.body.block1.unit03.gn2.bias
primals_27 = self.body.block1.unit03.conv2.weight
primals_28 = self.body.block1.unit03.gn3.weight
primals_29 = self.body.block1.unit03.gn3.bias
primals_30 = self.body.block1.unit03.conv3.weight
primals_31 = self.body.block1.unit04.gn1.weight
primals_32 = self.body.block1.unit04.gn1.bias
primals_33 = self.body.block1.unit04.conv1.weight
primals_34 = self.body.block1.unit04.gn2.weight
primals_35 = self.body.block1.unit04.gn2.bias
primals_36 = self.body.block1.unit04.conv2.weight
primals_37 = self.body.block1.unit04.gn3.weight
primals_38 = self.body.block1.unit04.gn3.bias
primals_39 = self.body.block1.unit04.conv3.weight
primals_40 = self.body.block2.unit01.gn1.weight
primals_41 = self.body.block2.unit01.gn1.bias
primals_43 = self.body.block2.unit01.conv1.weight
primals_44 = self.body.block2.unit01.gn2.weight
primals_45 = self.body.block2.unit01.gn2.bias
primals_46 = self.body.block2.unit01.conv2.weight
primals_47 = self.body.block2.unit01.gn3.weight
primals_48 = self.body.block2.unit01.gn3.bias
primals_49 = self.body.block2.unit01.conv3.weight
primals_42 = self.body.block2.unit01.downsample.weight
primals_50 = self.body.block2.unit02.gn1.weight
primals_51 = self.body.block2.unit02.gn1.bias
primals_52 = self.body.block2.unit02.conv1.weight
primals_53 = self.body.block2.unit02.gn2.weight
primals_54 = self.body.block2.unit02.gn2.bias
primals_55 = self.body.block2.unit02.conv2.weight
primals_56 = self.body.block2.unit02.gn3.weight
primals_57 = self.body.block2.unit02.gn3.bias
primals_58 = self.body.block2.unit02.conv3.weight
primals_59 = self.body.block2.unit03.gn1.weight
primals_60 = self.body.block2.unit03.gn1.bias
primals_61 = self.body.block2.unit03.conv1.weight
primals_62 = self.body.block2.unit03.gn2.weight
primals_63 = self.body.block2.unit03.gn2.bias
primals_64 = self.body.block2.unit03.conv2.weight
primals_65 = self.body.block2.unit03.gn3.weight
primals_66 = self.body.block2.unit03.gn3.bias
primals_67 = self.body.block2.unit03.conv3.weight
primals_68 = self.body.block2.unit04.gn1.weight
primals_69 = self.body.block2.unit04.gn1.bias
primals_70 = self.body.block2.unit04.conv1.weight
primals_71 = self.body.block2.unit04.gn2.weight
primals_72 = self.body.block2.unit04.gn2.bias
primals_73 = self.body.block2.unit04.conv2.weight
primals_74 = self.body.block2.unit04.gn3.weight
primals_75 = self.body.block2.unit04.gn3.bias
primals_76 = self.body.block2.unit04.conv3.weight
primals_77 = self.body.block3.unit01.gn1.weight
primals_78 = self.body.block3.unit01.gn1.bias
primals_80 = self.body.block3.unit01.conv1.weight
primals_81 = self.body.block3.unit01.gn2.weight
primals_82 = self.body.block3.unit01.gn2.bias
primals_83 = self.body.block3.unit01.conv2.weight
primals_84 = self.body.block3.unit01.gn3.weight
primals_85 = self.body.block3.unit01.gn3.bias
primals_86 = self.body.block3.unit01.conv3.weight
primals_79 = self.body.block3.unit01.downsample.weight
primals_87 = self.body.block3.unit02.gn1.weight
primals_88 = self.body.block3.unit02.gn1.bias
primals_89 = self.body.block3.unit02.conv1.weight
primals_90 = self.body.block3.unit02.gn2.weight
primals_91 = self.body.block3.unit02.gn2.bias
primals_92 = self.body.block3.unit02.conv2.weight
primals_93 = self.body.block3.unit02.gn3.weight
primals_94 = self.body.block3.unit02.gn3.bias
primals_95 = self.body.block3.unit02.conv3.weight
primals_96 = self.body.block3.unit03.gn1.weight
primals_97 = self.body.block3.unit03.gn1.bias
primals_98 = self.body.block3.unit03.conv1.weight
primals_99 = self.body.block3.unit03.gn2.weight
primals_100 = self.body.block3.unit03.gn2.bias
primals_101 = self.body.block3.unit03.conv2.weight
primals_102 = self.body.block3.unit03.gn3.weight
primals_103 = self.body.block3.unit03.gn3.bias
primals_104 = self.body.block3.unit03.conv3.weight
primals_105 = self.body.block3.unit04.gn1.weight
primals_106 = self.body.block3.unit04.gn1.bias
primals_107 = self.body.block3.unit04.conv1.weight
primals_108 = self.body.block3.unit04.gn2.weight
primals_109 = self.body.block3.unit04.gn2.bias
primals_110 = self.body.block3.unit04.conv2.weight
primals_111 = self.body.block3.unit04.gn3.weight
primals_112 = self.body.block3.unit04.gn3.bias
primals_113 = self.body.block3.unit04.conv3.weight
primals_114 = self.body.block4.unit01.gn1.weight
primals_115 = self.body.block4.unit01.gn1.bias
primals_117 = self.body.block4.unit01.conv1.weight
primals_118 = self.body.block4.unit01.gn2.weight
primals_119 = self.body.block4.unit01.gn2.bias
primals_120 = self.body.block4.unit01.conv2.weight
primals_121 = self.body.block4.unit01.gn3.weight
primals_122 = self.body.block4.unit01.gn3.bias
primals_123 = self.body.block4.unit01.conv3.weight
primals_116 = self.body.block4.unit01.downsample.weight
primals_124 = self.body.block4.unit02.gn1.weight
primals_125 = self.body.block4.unit02.gn1.bias
primals_126 = self.body.block4.unit02.conv1.weight
primals_127 = self.body.block4.unit02.gn2.weight
primals_128 = self.body.block4.unit02.gn2.bias
primals_129 = self.body.block4.unit02.conv2.weight
primals_130 = self.body.block4.unit02.gn3.weight
primals_131 = self.body.block4.unit02.gn3.bias
primals_132 = self.body.block4.unit02.conv3.weight
primals_133 = self.body.block4.unit03.gn1.weight
primals_134 = self.body.block4.unit03.gn1.bias
primals_135 = self.body.block4.unit03.conv1.weight
primals_136 = self.body.block4.unit03.gn2.weight
primals_137 = self.body.block4.unit03.gn2.bias
primals_138 = self.body.block4.unit03.conv2.weight
primals_139 = self.body.block4.unit03.gn3.weight
primals_140 = self.body.block4.unit03.gn3.bias
primals_141 = self.body.block4.unit03.conv3.weight
primals_142 = self.body.block4.unit04.gn1.weight
primals_143 = self.body.block4.unit04.gn1.bias
primals_144 = self.body.block4.unit04.conv1.weight
primals_145 = self.body.block4.unit04.gn2.weight
primals_146 = self.body.block4.unit04.gn2.bias
primals_147 = self.body.block4.unit04.conv2.weight
primals_148 = self.body.block4.unit04.gn3.weight
primals_149 = self.body.block4.unit04.gn3.bias
primals_150 = self.body.block4.unit04.conv3.weight
primals_151 = self.head.gn.weight
primals_152 = self.head.gn.bias
primals_153 = self.head.conv.weight
primals_154 = self.head.conv.bias
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, primals_122, primals_123, primals_124,
primals_125, primals_126, primals_127, primals_128, primals_129,
primals_130, primals_131, primals_132, primals_133, primals_134,
primals_135, primals_136, primals_137, primals_138, primals_139,
primals_140, primals_141, primals_142, primals_143, primals_144,
primals_145, primals_146, primals_147, primals_148, primals_149,
primals_150, primals_151, primals_152, primals_153, primals_154])
return output[0]
|
RicJM/weighted_c2d
|
ResNetV2
| false
| 15,389
|
[
"MIT"
] | 49
|
38053869b77c1544349c53ba6f3c1325254aa413
|
https://github.com/RicJM/weighted_c2d/tree/38053869b77c1544349c53ba6f3c1325254aa413
|
Capsule
|
from _paritybench_helpers import _mock_config
import torch
import torch.nn as nn
class Capsule(nn.Module):
def __init__(self, cfg):
super(Capsule, self).__init__()
self.input_dim_capsule = cfg.input_dim_capsule
self.dim_capsule = cfg.dim_capsule
self.num_capsule = cfg.num_capsule
self.batch_size = cfg.batch_size
self.share_weights = cfg.share_weights
self.num_iterations = cfg.num_iterations
if self.share_weights:
W = torch.zeros(1, self.input_dim_capsule, self.num_capsule *
self.dim_capsule)
else:
W = torch.zeros(self.batch_size, self.input_dim_capsule, self.
num_capsule * self.dim_capsule)
W = nn.init.xavier_normal_(W)
self.W = nn.Parameter(W)
def forward(self, x):
"""
x: [B, L, H] # 从 CNN / RNN 得到的结果
L 作为 input_num_capsules, H 作为 input_dim_capsule
"""
B, I, _ = x.size()
O, F = self.num_capsule, self.dim_capsule
u = torch.matmul(x, self.W)
u = u.view(B, I, O, F).transpose(1, 2)
b = torch.zeros_like(u[:, :, :, 0])
for i in range(self.num_iterations):
c = torch.softmax(b, dim=1)
v = torch.einsum('boi,boif->bof', [c, u])
v = self.squash(v)
b = torch.einsum('bof,boif->boi', [v, u])
return v
@staticmethod
def squash(x: 'torch.Tensor'):
x_norm = x.norm(p=2, dim=-1, keepdim=True)
mag = x_norm ** 2
out = x / x_norm * mag / (1 + mag)
return out
def get_inputs():
return [torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'cfg': _mock_config(input_dim_capsule=4, dim_capsule=4,
num_capsule=4, batch_size=4, share_weights=4, num_iterations=4)}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused__softmax_zeros_like_0(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 = 0.0
tmp1 = tl_math.exp(tmp0)
tmp2 = tmp1 + tmp1
tmp3 = tmp2 + tmp1
tmp4 = tmp3 + tmp1
tmp5 = tmp1 / tmp4
tl.store(out_ptr0 + x0, tmp5, xmask)
@triton.jit
def triton_poi_fused_clone_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4 % 4
x2 = xindex // 16 % 4
x3 = xindex // 64
x4 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), xmask)
tl.store(out_ptr0 + x4, tmp0, xmask)
@triton.jit
def triton_poi_fused_add_div_linalg_vector_norm_mul_pow_2(in_ptr0, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = tmp0 / tmp12
tmp14 = tmp12 * tmp12
tmp15 = tmp13 * tmp14
tmp16 = 1.0
tmp17 = tmp14 + tmp16
tmp18 = tmp15 / tmp17
tl.store(out_ptr0 + x2, tmp18, xmask)
@triton.jit
def triton_poi_fused_clone_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 64
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 16
y1 = yindex // 16
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 16 * x2 + 64 * y1), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)
@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
x3 = xindex
x0 = xindex % 4
x2 = xindex // 16
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x3, tmp9, xmask)
@triton.jit
def triton_poi_fused__softmax_5(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 4
x2 = xindex // 16
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = 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 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (1, 4, 16), (64, 16, 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), (16, 1), 0), out=buf0)
del primals_2
buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__softmax_zeros_like_0[grid(64)](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)](buf0, buf2, 256, XBLOCK=256,
num_warps=4, num_stages=1)
buf3 = empty_strided_cuda((16, 1, 4), (4, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf1, (16, 1, 4), (4, 0, 1),
0), reinterpret_tensor(buf2, (16, 4, 4), (16, 4, 1), 0), out=buf3)
buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_div_linalg_vector_norm_mul_pow_2[grid(64)](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_clone_3[grid(64, 4)](buf0, buf5, 64, 4, XBLOCK=4,
YBLOCK=32, num_warps=4, num_stages=1)
del buf0
buf6 = empty_strided_cuda((16, 1, 4), (4, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf4, (16, 1, 4), (4, 4, 1),
0), reinterpret_tensor(buf5, (16, 4, 4), (16, 4, 1), 0), out=buf6)
buf7 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_4[grid(64)](buf6, buf7, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf8 = reinterpret_tensor(buf6, (4, 4, 4), (16, 4, 1), 0)
del buf6
triton_poi_fused__softmax_5[grid(64)](buf7, buf8, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf9 = reinterpret_tensor(buf7, (16, 1, 4), (4, 4, 1), 0)
del buf7
extern_kernels.bmm(reinterpret_tensor(buf8, (16, 1, 4), (4, 4, 1),
0), reinterpret_tensor(buf2, (16, 4, 4), (16, 4, 1), 0), out=buf9)
buf10 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_div_linalg_vector_norm_mul_pow_2[grid(64)](buf9,
buf10, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf11 = empty_strided_cuda((16, 1, 4), (4, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf10, (16, 1, 4), (4, 4, 1),
0), reinterpret_tensor(buf5, (16, 4, 4), (16, 4, 1), 0), out=buf11)
buf12 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_4[grid(64)](buf11, buf12, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf13 = reinterpret_tensor(buf11, (4, 4, 4), (16, 4, 1), 0)
del buf11
triton_poi_fused__softmax_5[grid(64)](buf12, buf13, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf14 = reinterpret_tensor(buf12, (16, 1, 4), (4, 4, 1), 0)
del buf12
extern_kernels.bmm(reinterpret_tensor(buf13, (16, 1, 4), (4, 4, 1),
0), reinterpret_tensor(buf2, (16, 4, 4), (16, 4, 1), 0), out=buf14)
buf15 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_div_linalg_vector_norm_mul_pow_2[grid(64)](buf14,
buf15, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf16 = empty_strided_cuda((16, 1, 4), (4, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf15, (16, 1, 4), (4, 4, 1),
0), reinterpret_tensor(buf5, (16, 4, 4), (16, 4, 1), 0), out=buf16)
buf17 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_4[grid(64)](buf16, buf17, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf18 = reinterpret_tensor(buf16, (4, 4, 4), (16, 4, 1), 0)
del buf16
triton_poi_fused__softmax_5[grid(64)](buf17, buf18, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf19 = reinterpret_tensor(buf17, (16, 1, 4), (4, 4, 1), 0)
del buf17
extern_kernels.bmm(reinterpret_tensor(buf18, (16, 1, 4), (4, 4, 1),
0), reinterpret_tensor(buf2, (16, 4, 4), (16, 4, 1), 0), out=buf19)
buf20 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_div_linalg_vector_norm_mul_pow_2[grid(64)](buf19,
buf20, 64, XBLOCK=64, num_warps=1, num_stages=1)
return (buf20, buf3, buf4, buf8, buf9, buf10, buf13, buf14, buf15,
buf18, buf19, reinterpret_tensor(buf2, (16, 4, 4), (16, 1, 4), 0),
reinterpret_tensor(buf5, (16, 4, 4), (16, 1, 4), 0),
reinterpret_tensor(buf1, (16, 4, 1), (4, 1, 4), 0),
reinterpret_tensor(primals_1, (4, 16), (1, 4), 0))
class CapsuleNew(nn.Module):
def __init__(self, cfg):
super(CapsuleNew, self).__init__()
self.input_dim_capsule = cfg.input_dim_capsule
self.dim_capsule = cfg.dim_capsule
self.num_capsule = cfg.num_capsule
self.batch_size = cfg.batch_size
self.share_weights = cfg.share_weights
self.num_iterations = cfg.num_iterations
if self.share_weights:
W = torch.zeros(1, self.input_dim_capsule, self.num_capsule *
self.dim_capsule)
else:
W = torch.zeros(self.batch_size, self.input_dim_capsule, self.
num_capsule * self.dim_capsule)
W = nn.init.xavier_normal_(W)
self.W = nn.Parameter(W)
@staticmethod
def squash(x: 'torch.Tensor'):
x_norm = x.norm(p=2, dim=-1, keepdim=True)
mag = x_norm ** 2
out = x / x_norm * mag / (1 + mag)
return out
def forward(self, input_0):
primals_2 = self.W
primals_1 = input_0
output = call([primals_1, primals_2])
return output[0]
|
fmc123653/DeepKE
|
Capsule
| false
| 15,390
|
[
"MIT"
] | 676
|
4d30e51368681c7cb73e2ecacf9b922b441cbe99
|
https://github.com/fmc123653/DeepKE/tree/4d30e51368681c7cb73e2ecacf9b922b441cbe99
|
BalancedLoss
|
import torch
from torch import nn
import torch.nn.functional as F
class BalancedLoss(nn.Module):
def __init__(self, neg_weight=1.0):
super(BalancedLoss, self).__init__()
self.neg_weight = neg_weight
def forward(self, input, target):
pos_mask = target == 0
neg_mask = target == 1
pos_num = pos_mask.sum().float()
neg_num = neg_mask.sum().float()
weight = torch.zeros(target.size(), dtype=torch.float32, device=
target.device)
weight[pos_mask] = 1 / pos_num
weight[neg_mask] = 1 / neg_num * self.neg_weight
weight /= weight.sum()
return F.binary_cross_entropy_with_logits(input, target.float(),
weight, reduction='sum')
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused__to_copy_binary_cross_entropy_with_logits_div_eq_index_put_mul_reciprocal_sum_zeros_0(
in_out_ptr1, 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)
tmp27 = tl.load(in_ptr1 + r0, None)
tmp1 = 0.0
tmp2 = tmp0 == tmp1
tmp3 = tmp2.to(tl.int64)
tmp4 = tl.broadcast_to(tmp3, [RBLOCK])
tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0))
tmp7 = 1.0
tmp8 = tmp0 == tmp7
tmp9 = tmp8.to(tl.int64)
tmp10 = tl.broadcast_to(tmp9, [RBLOCK])
tmp12 = triton_helpers.promote_to_tensor(tl.sum(tmp10, 0))
tmp13 = tmp6.to(tl.float32)
tmp14 = tl.full([1], 1, tl.int32)
tmp15 = tmp14 / tmp13
tmp16 = tmp15 * tmp7
tmp17 = tl.where(tmp2, tmp16, tmp1)
tmp18 = tmp12.to(tl.float32)
tmp19 = tmp14 / tmp18
tmp20 = tmp19 * tmp7
tmp21 = tmp20 * tmp7
tmp22 = tl.where(tmp8, tmp21, tmp17)
tmp23 = tl.broadcast_to(tmp22, [RBLOCK])
tmp25 = triton_helpers.promote_to_tensor(tl.sum(tmp23, 0))
tmp26 = tmp7 - tmp0
tmp28 = tmp26 * tmp27
tmp29 = triton_helpers.minimum(tmp1, tmp27)
tmp30 = tl_math.abs(tmp27)
tmp31 = -tmp30
tmp32 = tl_math.exp(tmp31)
tmp33 = libdevice.log1p(tmp32)
tmp34 = tmp29 - tmp33
tmp35 = tmp28 - tmp34
tmp36 = tmp22 / tmp25
tmp37 = tmp35 * tmp36
tmp38 = tl.broadcast_to(tmp37, [RBLOCK])
tmp40 = triton_helpers.promote_to_tensor(tl.sum(tmp38, 0))
tl.store(in_out_ptr1 + tl.full([1], 0, tl.int32), tmp40, 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)
buf4 = empty_strided_cuda((), (), torch.float32)
buf5 = buf4
del buf4
get_raw_stream(0)
triton_per_fused__to_copy_binary_cross_entropy_with_logits_div_eq_index_put_mul_reciprocal_sum_zeros_0[
grid(1)](buf5, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
return buf5,
class BalancedLossNew(nn.Module):
def __init__(self, neg_weight=1.0):
super(BalancedLossNew, self).__init__()
self.neg_weight = neg_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]
|
gabrielsluz/vince
|
BalancedLoss
| false
| 15,391
|
[
"Apache-2.0"
] | 61
|
f4e17a2cf70c080a7e01e46d15537e33224c869b
|
https://github.com/gabrielsluz/vince/tree/f4e17a2cf70c080a7e01e46d15537e33224c869b
|
GAE
|
import torch
import numpy as np
import torch.nn as nn
import torch.nn.functional as F
class GAE(nn.Module):
def __init__(self, num_inputs, num_outputs):
super(GAE, self).__init__()
self.num_inputs = num_inputs
self.num_outputs = num_outputs
self.fc = nn.Linear(num_inputs, 128)
self.fc_actor = nn.Linear(128, num_outputs)
self.fc_critic = nn.Linear(128, 1)
for m in self.modules():
if isinstance(m, nn.Linear):
nn.init.xavier_uniform(m.weight)
def forward(self, input):
x = F.relu(self.fc(input))
policy = F.softmax(self.fc_actor(x))
value = self.fc_critic(x)
return policy, value
@classmethod
def get_gae(self, values, rewards, masks):
returns = torch.zeros_like(rewards)
advantages = torch.zeros_like(rewards)
running_return = 0
previous_value = 0
running_advantage = 0
for t in reversed(range(len(rewards))):
running_return = rewards[t] + gamma * running_return * masks[t]
running_tderror = rewards[t] + gamma * previous_value * masks[t
] - values.data[t]
running_advantage = (running_tderror + gamma * lambda_gae *
running_advantage * masks[t])
returns[t] = running_return
previous_value = values.data[t]
advantages[t] = running_advantage
return returns, advantages
@classmethod
def train_model(cls, net, transitions, optimizer):
states, actions, rewards, masks = (transitions.state, transitions.
action, transitions.reward, transitions.mask)
states = torch.stack(states)
actions = torch.stack(actions)
rewards = torch.Tensor(rewards)
masks = torch.Tensor(masks)
policies, values = net(states)
policies = policies.view(-1, net.num_outputs)
values = values.view(-1)
returns, advantages = net.get_gae(values.view(-1).detach(), rewards,
masks)
log_policies = (torch.log(policies) * actions.detach()).sum(dim=1)
actor_loss = -(log_policies * advantages).sum()
critic_loss = (returns.detach() - values).pow(2).sum()
entropy = (torch.log(policies) * policies).sum(1).sum()
loss = (actor_loss + ciritic_coefficient * critic_loss -
entropy_coefficient * entropy)
optimizer.zero_grad()
loss.backward()
optimizer.step()
return loss
def get_action(self, input):
policy, _ = self.forward(input)
policy = policy[0].data.numpy()
action = np.random.choice(self.num_outputs, 1, p=policy)[0]
return action
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'num_inputs': 4, 'num_outputs': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import numpy as np
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x2 = xindex
x0 = xindex % 128
tmp0 = tl.load(in_out_ptr0 + x2, None)
tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x2, tmp4, None)
tl.store(out_ptr0 + x2, tmp6, None)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x3, tmp9, xmask)
@triton.jit
def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x3, tmp8, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7) = args
args.clear()
assert_size_stride(primals_1, (128, 4), (4, 1))
assert_size_stride(primals_2, (128,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4, 128), (128, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (1, 128), (128, 1))
assert_size_stride(primals_7, (1,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 128), (128, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 128), (1, 4), 0), out=buf0)
del primals_1
buf1 = reinterpret_tensor(buf0, (4, 4, 4, 128), (2048, 512, 128, 1), 0)
del buf0
buf7 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1),
torch.bool)
get_raw_stream(0)
triton_poi_fused_relu_threshold_backward_0[grid(8192)](buf1,
primals_2, buf7, 8192, XBLOCK=256, num_warps=4, num_stages=1)
del primals_2
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 128),
(128, 1), 0), reinterpret_tensor(primals_4, (128, 4), (1, 128),
0), alpha=1, beta=1, out=buf2)
del primals_5
buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__softmax_1[grid(256)](buf2, buf3, 256, XBLOCK=256,
num_warps=4, num_stages=1)
buf4 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf2
triton_poi_fused__softmax_2[grid(256)](buf3, buf4, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del buf3
buf6 = empty_strided_cuda((64, 1), (1, 1), torch.float32)
extern_kernels.addmm(primals_7, reinterpret_tensor(buf1, (64, 128),
(128, 1), 0), reinterpret_tensor(primals_6, (128, 1), (1, 128),
0), alpha=1, beta=1, out=buf6)
del primals_7
return buf4, reinterpret_tensor(buf6, (4, 4, 4, 1), (16, 4, 1, 1), 0
), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), reinterpret_tensor(buf1, (64, 128), (128, 1), 0
), buf4, primals_6, primals_4, buf7
class GAENew(nn.Module):
def __init__(self, num_inputs, num_outputs):
super(GAENew, self).__init__()
self.num_inputs = num_inputs
self.num_outputs = num_outputs
self.fc = nn.Linear(num_inputs, 128)
self.fc_actor = nn.Linear(128, num_outputs)
self.fc_critic = nn.Linear(128, 1)
for m in self.modules():
if isinstance(m, nn.Linear):
nn.init.xavier_uniform(m.weight)
@classmethod
def get_gae(self, values, rewards, masks):
returns = torch.zeros_like(rewards)
advantages = torch.zeros_like(rewards)
running_return = 0
previous_value = 0
running_advantage = 0
for t in reversed(range(len(rewards))):
running_return = rewards[t] + gamma * running_return * masks[t]
running_tderror = rewards[t] + gamma * previous_value * masks[t
] - values.data[t]
running_advantage = (running_tderror + gamma * lambda_gae *
running_advantage * masks[t])
returns[t] = running_return
previous_value = values.data[t]
advantages[t] = running_advantage
return returns, advantages
@classmethod
def train_model(cls, net, transitions, optimizer):
states, actions, rewards, masks = (transitions.state, transitions.
action, transitions.reward, transitions.mask)
states = torch.stack(states)
actions = torch.stack(actions)
rewards = torch.Tensor(rewards)
masks = torch.Tensor(masks)
policies, values = net(states)
policies = policies.view(-1, net.num_outputs)
values = values.view(-1)
returns, advantages = net.get_gae(values.view(-1).detach(), rewards,
masks)
log_policies = (torch.log(policies) * actions.detach()).sum(dim=1)
actor_loss = -(log_policies * advantages).sum()
critic_loss = (returns.detach() - values).pow(2).sum()
entropy = (torch.log(policies) * policies).sum(1).sum()
loss = (actor_loss + ciritic_coefficient * critic_loss -
entropy_coefficient * entropy)
optimizer.zero_grad()
loss.backward()
optimizer.step()
return loss
def get_action(self, input):
policy, _ = self.forward(input)
policy = policy[0].data.numpy()
action = np.random.choice(self.num_outputs, 1, p=policy)[0]
return action
def forward(self, input_0):
primals_1 = self.fc.weight
primals_2 = self.fc.bias
primals_4 = self.fc_actor.weight
primals_5 = self.fc_actor.bias
primals_6 = self.fc_critic.weight
primals_7 = self.fc_critic.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7])
return output[0], output[1]
|
g6ling/Pytorch-Cartpole
|
GAE
| false
| 15,392
|
[
"MIT"
] | 116
|
ecb7b622cfefe825ac95388cceb6752413d90a2a
|
https://github.com/g6ling/Pytorch-Cartpole/tree/ecb7b622cfefe825ac95388cceb6752413d90a2a
|
TemperatureHolder
|
import torch
from torch import nn
class TemperatureHolder(nn.Module):
"""Module that holds a temperature as a learnable value.
Args:
initial_log_temperature (float): Initial value of log(temperature).
"""
def __init__(self, initial_log_temperature=0):
super().__init__()
self.log_temperature = nn.Parameter(torch.tensor(
initial_log_temperature, dtype=torch.float32))
def forward(self):
"""Return a temperature as a torch.Tensor."""
return torch.exp(self.log_temperature)
def get_inputs():
return []
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import math as tl_math
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_exp_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
tmp0 = tl.load(in_ptr0 + 0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
tmp2 = tl_math.exp(tmp1)
tl.store(out_ptr0 + tl.full([XBLOCK], 0, tl.int32), tmp2, None)
def call(args):
primals_1, = args
args.clear()
assert_size_stride(primals_1, (), ())
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((), (), torch.float32)
get_raw_stream(0)
triton_poi_fused_exp_0[grid(1)](primals_1, buf0, 1, XBLOCK=1,
num_warps=1, num_stages=1)
del primals_1
return buf0, buf0
class TemperatureHolderNew(nn.Module):
"""Module that holds a temperature as a learnable value.
Args:
initial_log_temperature (float): Initial value of log(temperature).
"""
def __init__(self, initial_log_temperature=0):
super().__init__()
self.log_temperature = nn.Parameter(torch.tensor(
initial_log_temperature, dtype=torch.float32))
def forward(self):
primals_1 = self.log_temperature
output = call([primals_1])
return output[0]
|
g-votte/pfrl
|
TemperatureHolder
| false
| 15,393
|
[
"MIT"
] | 824
|
4c30c1d73f0941a2b649b62937eec346bb55a95e
|
https://github.com/g-votte/pfrl/tree/4c30c1d73f0941a2b649b62937eec346bb55a95e
|
ConvCompress
|
import torch
from torch import nn
class ConvCompress(nn.Module):
def __init__(self, dim, ratio=4):
super().__init__()
self.conv = nn.Conv1d(dim, dim, ratio, stride=ratio)
def forward(self, mem):
mem = mem.transpose(1, 2)
compressed_mem = self.conv(mem)
return compressed_mem.transpose(1, 2)
def get_inputs():
return [torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'dim': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_convolution_0(in_ptr0, out_ptr0, ynumel, xnumel,
YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 4
y1 = yindex // 4
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_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 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_3, (4,), (1,))
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_convolution_0[grid(16, 4)](primals_1, buf0, 16, 4,
XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1)
buf1 = extern_kernels.convolution(buf0, primals_2, stride=(4,),
padding=(0,), dilation=(1,), transposed=False, output_padding=(
0,), groups=1, bias=None)
assert_size_stride(buf1, (4, 4, 1), (4, 1, 1))
del buf0
buf2 = buf1
del buf1
triton_poi_fused_convolution_1[grid(16)](buf2, primals_3, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del primals_3
return reinterpret_tensor(buf2, (4, 1, 4), (4, 1, 1), 0
), primals_2, reinterpret_tensor(primals_1, (4, 4, 4), (16, 1, 4), 0)
class ConvCompressNew(nn.Module):
def __init__(self, dim, ratio=4):
super().__init__()
self.conv = nn.Conv1d(dim, dim, ratio, stride=ratio)
def forward(self, input_0):
primals_1 = self.conv.weight
primals_3 = self.conv.bias
primals_2 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
fwka92/compressive-transformer-pytorch
|
ConvCompress
| false
| 15,394
|
[
"MIT"
] | 108
|
e51faba52a8c1ec6a8b966e5b912e6ecc3840f57
|
https://github.com/fwka92/compressive-transformer-pytorch/tree/e51faba52a8c1ec6a8b966e5b912e6ecc3840f57
|
ImageToTensor
|
import torch
import numpy as np
import torch.optim
import torch.nn as nn
import torch.nn.utils
import torch.autograd
class BaseMetric:
""" Base class for all the metrics """
def __init__(self, name):
self.name = name
def calculate(self, batch_info):
""" Calculate value of a metric based on supplied data """
raise NotImplementedError
def reset(self):
""" Reset value of a metric """
raise NotImplementedError
def value(self):
""" Return current value for the metric """
raise NotImplementedError
def write_state_dict(self, training_info: 'TrainingInfo',
hidden_state_dict: 'dict') ->None:
""" Potentially store some metric state to the checkpoint """
pass
def load_state_dict(self, training_info: 'TrainingInfo',
hidden_state_dict: 'dict') ->None:
""" Potentially load some metric state from the checkpoint """
pass
class AveragingMetric(BaseMetric):
""" Base class for metrics that simply calculate the average over the epoch """
def __init__(self, name):
super().__init__(name)
self.storage = []
def calculate(self, batch_info):
""" Calculate value of a metric """
value = self._value_function(batch_info)
self.storage.append(value)
def _value_function(self, batch_info):
raise NotImplementedError
def reset(self):
""" Reset value of a metric """
self.storage = []
def value(self):
""" Return current value for the metric """
return float(np.mean(self.storage))
class Loss(AveragingMetric):
""" Just a loss function """
def __init__(self):
super().__init__('loss')
def _value_function(self, batch_info):
""" Just forward a value of the loss"""
return batch_info['loss'].item()
class Model(nn.Module):
""" Class representing full neural network model """
def metrics(self) ->list:
""" Set of metrics for this model """
return [Loss()]
def train(self, mode=True):
"""
Sets the module in training mode.
This has any effect only on certain modules. See documentations of
particular modules for details of their behaviors in training/evaluation
mode, if they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
etc.
Returns:
Module: self
"""
super().train(mode)
if mode:
mu.apply_leaf(self, mu.set_train_mode)
return self
def summary(self, input_size=None, hashsummary=False):
""" Print a model summary """
if input_size is None:
None
None
sum(p.numel() for p in self.model.parameters())
None
None
else:
summary(self, input_size)
if hashsummary:
for idx, hashvalue in enumerate(self.hashsummary()):
None
def hashsummary(self):
""" Print a model summary - checksums of each layer parameters """
children = list(self.children())
result = []
for child in children:
result.extend(hashlib.sha256(x.detach().cpu().numpy().tobytes()
).hexdigest() for x in child.parameters())
return result
def get_layer_groups(self):
""" Return layers grouped """
return [self]
def reset_weights(self):
""" Call proper initializers for the weights """
pass
@property
def is_recurrent(self) ->bool:
""" If the network is recurrent and needs to be fed state as well as the observations """
return False
class BackboneModel(Model):
""" Model that serves as a backbone network to connect your heads to """
class ImageToTensor(BackboneModel):
"""
Convert simple image to tensor.
Flip channels to a [C, W, H] order and potentially convert 8-bit color values to floats
"""
def __init__(self):
super().__init__()
def reset_weights(self):
pass
def forward(self, image):
result = image.permute(0, 3, 1, 2).contiguous()
if result.dtype == torch.uint8:
result = result.type(torch.float) / 255.0
else:
result = result.type(torch.float)
return result
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 numpy as np
import torch.optim
import torch.nn as nn
import torch.nn.utils
import torch.autograd
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_clone_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 16
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 4
y1 = yindex // 4
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 64 * y1), xmask & ymask)
tl.store(out_ptr0 + (x2 + 16 * y3), tmp0, xmask & ymask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(16, 16)](arg0_1, buf0, 16, 16, XBLOCK
=16, YBLOCK=16, num_warps=4, num_stages=1)
del arg0_1
return buf0,
class BaseMetric:
""" Base class for all the metrics """
def __init__(self, name):
self.name = name
def calculate(self, batch_info):
""" Calculate value of a metric based on supplied data """
raise NotImplementedError
def reset(self):
""" Reset value of a metric """
raise NotImplementedError
def value(self):
""" Return current value for the metric """
raise NotImplementedError
def write_state_dict(self, training_info: 'TrainingInfo',
hidden_state_dict: 'dict') ->None:
""" Potentially store some metric state to the checkpoint """
pass
def load_state_dict(self, training_info: 'TrainingInfo',
hidden_state_dict: 'dict') ->None:
""" Potentially load some metric state from the checkpoint """
pass
class AveragingMetric(BaseMetric):
""" Base class for metrics that simply calculate the average over the epoch """
def __init__(self, name):
super().__init__(name)
self.storage = []
def calculate(self, batch_info):
""" Calculate value of a metric """
value = self._value_function(batch_info)
self.storage.append(value)
def _value_function(self, batch_info):
raise NotImplementedError
def reset(self):
""" Reset value of a metric """
self.storage = []
def value(self):
""" Return current value for the metric """
return float(np.mean(self.storage))
class Loss(AveragingMetric):
""" Just a loss function """
def __init__(self):
super().__init__('loss')
def _value_function(self, batch_info):
""" Just forward a value of the loss"""
return batch_info['loss'].item()
class Model(nn.Module):
""" Class representing full neural network model """
def metrics(self) ->list:
""" Set of metrics for this model """
return [Loss()]
def train(self, mode=True):
"""
Sets the module in training mode.
This has any effect only on certain modules. See documentations of
particular modules for details of their behaviors in training/evaluation
mode, if they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
etc.
Returns:
Module: self
"""
super().train(mode)
if mode:
mu.apply_leaf(self, mu.set_train_mode)
return self
def summary(self, input_size=None, hashsummary=False):
""" Print a model summary """
if input_size is None:
None
None
sum(p.numel() for p in self.model.parameters())
None
None
else:
summary(self, input_size)
if hashsummary:
for idx, hashvalue in enumerate(self.hashsummary()):
None
def hashsummary(self):
""" Print a model summary - checksums of each layer parameters """
children = list(self.children())
result = []
for child in children:
result.extend(hashlib.sha256(x.detach().cpu().numpy().tobytes()
).hexdigest() for x in child.parameters())
return result
def get_layer_groups(self):
""" Return layers grouped """
return [self]
def reset_weights(self):
""" Call proper initializers for the weights """
pass
@property
def is_recurrent(self) ->bool:
""" If the network is recurrent and needs to be fed state as well as the observations """
return False
class BackboneModel(Model):
""" Model that serves as a backbone network to connect your heads to """
class ImageToTensorNew(BackboneModel):
"""
Convert simple image to tensor.
Flip channels to a [C, W, H] order and potentially convert 8-bit color values to floats
"""
def __init__(self):
super().__init__()
def reset_weights(self):
pass
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
galatolofederico/vel
|
ImageToTensor
| false
| 15,395
|
[
"MIT"
] | 273
|
0473648cffb3f34fb784d12dbb25844ab58ffc3c
|
https://github.com/galatolofederico/vel/tree/0473648cffb3f34fb784d12dbb25844ab58ffc3c
|
PreNormTransformerDecoderLayer
|
import torch
import torch.nn as nn
class PreNormTransformerDecoderLayer(nn.TransformerDecoderLayer):
"""
A variant of :class:`torch.nn.TransformerDecoderLayer` where layer
normalization is included inside the residual branch, and performed before
self-attention and feedforward layers.
Refer documentation of :class:`torch.nn.TransformerDecoderLayer` for more
details on the API.
"""
def forward(self, tgt, memory, tgt_mask=None, memory_mask=None,
tgt_key_padding_mask=None, memory_key_padding_mask=None):
tgt2 = self.norm1(tgt)
tgt2, _ = self.self_attn(tgt2, tgt2, tgt2, attn_mask=tgt_mask,
key_padding_mask=tgt_key_padding_mask)
tgt = tgt + self.dropout1(tgt2)
tgt2 = self.norm2(tgt)
tgt2, _ = self.multihead_attn(tgt2, memory, memory, attn_mask=
memory_mask, key_padding_mask=memory_key_padding_mask)
tgt = tgt + self.dropout2(tgt2)
tgt2 = self.norm3(tgt)
tgt2 = self.linear2(self.dropout(self.activation(self.linear1(tgt2))))
tgt = tgt + self.dropout3(tgt2)
return tgt
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4])]
def get_init_inputs():
return [[], {'d_model': 4, 'nhead': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_native_layer_norm_0(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 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_add_8(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)
@triton.jit
def triton_poi_fused_relu_9(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x2 = xindex
x0 = xindex % 2048
tmp0 = tl.load(in_out_ptr0 + x2, None)
tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x2, tmp4, None)
@triton.jit
def triton_poi_fused_add_10(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK:
tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_out_ptr0 + x2, xmask)
tmp2 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp4 = tmp0 + tmp3
tl.store(in_out_ptr0 + x2, tmp4, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
primals_13, primals_14, primals_15, primals_16, primals_17,
primals_18, primals_19, primals_20) = args
args.clear()
assert_size_stride(primals_1, (4,), (1,))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4), (4, 1))
assert_size_stride(primals_4, (12, 4), (4, 1))
assert_size_stride(primals_5, (12,), (1,))
assert_size_stride(primals_6, (4, 4), (4, 1))
assert_size_stride(primals_7, (4,), (1,))
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, (12, 4), (4, 1))
assert_size_stride(primals_12, (12,), (1,))
assert_size_stride(primals_13, (4, 4), (4, 1))
assert_size_stride(primals_14, (4,), (1,))
assert_size_stride(primals_15, (4,), (1,))
assert_size_stride(primals_16, (4,), (1,))
assert_size_stride(primals_17, (2048, 4), (4, 1))
assert_size_stride(primals_18, (2048,), (1,))
assert_size_stride(primals_19, (4, 2048), (2048, 1))
assert_size_stride(primals_20, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
buf1 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
get_raw_stream(0)
triton_poi_fused_native_layer_norm_0[grid(4)](primals_3, buf0, buf1,
4, XBLOCK=4, num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused_native_layer_norm_1[grid(16)](primals_3, buf0,
buf1, primals_1, primals_2, buf2, 16, XBLOCK=16, num_warps=1,
num_stages=1)
del primals_1
del primals_2
buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf2, reinterpret_tensor(primals_4, (4, 4), (1, 4
), 0), out=buf3)
buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(reinterpret_tensor(primals_5, (4,), (1,), 4),
buf2, reinterpret_tensor(primals_4, (4, 4), (1, 4), 16), alpha=
1, beta=1, out=buf4)
buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(reinterpret_tensor(primals_5, (4,), (1,), 8),
buf2, reinterpret_tensor(primals_4, (4, 4), (1, 4), 32), alpha=
1, beta=1, out=buf5)
buf6 = reinterpret_tensor(buf3, (4, 4, 1), (1, 4, 16), 0)
del buf3
triton_poi_fused_mul_2[grid(16)](buf6, primals_5, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del primals_5
buf7 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf6, reinterpret_tensor(buf4, (4, 1, 4), (1, 1,
4), 0), out=buf7)
buf8 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_3[grid(64)](buf7, buf8, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf9 = buf7
del buf7
triton_poi_fused__softmax_4[grid(64)](buf8, buf9, 64, XBLOCK=64,
num_warps=1, num_stages=1)
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_3, 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_3, buf12,
buf13, buf14, primals_8, primals_9, buf15, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del primals_9
buf16 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf15, reinterpret_tensor(primals_11, (4, 4), (1,
4), 0), out=buf16)
buf17 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(reinterpret_tensor(primals_12, (4,), (1,), 4),
primals_10, reinterpret_tensor(primals_11, (4, 4), (1, 4), 16),
alpha=1, beta=1, out=buf17)
buf18 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(reinterpret_tensor(primals_12, (4,), (1,), 8),
primals_10, reinterpret_tensor(primals_11, (4, 4), (1, 4), 32),
alpha=1, beta=1, out=buf18)
buf19 = reinterpret_tensor(buf16, (4, 4, 1), (1, 4, 16), 0)
del buf16
triton_poi_fused_mul_2[grid(16)](buf19, primals_12, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del primals_12
buf20 = buf8
del buf8
extern_kernels.bmm(buf19, reinterpret_tensor(buf17, (4, 1, 4), (1,
1, 4), 0), out=buf20)
buf21 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_3[grid(64)](buf20, buf21, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf22 = buf20
del buf20
triton_poi_fused__softmax_4[grid(64)](buf21, buf22, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del buf21
buf23 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32)
extern_kernels.bmm(buf22, reinterpret_tensor(buf18, (4, 4, 1), (1,
4, 1), 0), out=buf23)
buf24 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32)
triton_poi_fused_clone_5[grid(4, 4)](buf23, buf24, 4, 4, XBLOCK=4,
YBLOCK=4, num_warps=1, num_stages=1)
buf25 = reinterpret_tensor(buf23, (4, 4), (4, 1), 0)
del buf23
extern_kernels.mm(reinterpret_tensor(buf24, (4, 4), (4, 1), 0),
reinterpret_tensor(primals_13, (4, 4), (1, 4), 0), out=buf25)
buf26 = buf25
del buf25
triton_poi_fused_add_8[grid(16)](buf26, primals_3, buf12,
primals_14, 16, XBLOCK=16, num_warps=1, num_stages=1)
del primals_14
buf27 = buf14
del buf14
buf28 = buf13
del buf13
triton_poi_fused_native_layer_norm_0[grid(4)](buf26, buf27, buf28,
4, XBLOCK=4, num_warps=1, num_stages=1)
buf29 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused_native_layer_norm_1[grid(16)](buf26, buf27, buf28,
primals_15, primals_16, buf29, 16, XBLOCK=16, num_warps=1,
num_stages=1)
del buf27
del buf28
del primals_16
buf30 = empty_strided_cuda((4, 2048), (2048, 1), torch.float32)
extern_kernels.mm(buf29, reinterpret_tensor(primals_17, (4, 2048),
(1, 4), 0), out=buf30)
buf31 = buf30
del buf30
triton_poi_fused_relu_9[grid(8192)](buf31, primals_18, 8192, XBLOCK
=128, num_warps=4, num_stages=1)
del primals_18
buf32 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf31, reinterpret_tensor(primals_19, (2048, 4),
(1, 2048), 0), out=buf32)
buf33 = buf32
del buf32
triton_poi_fused_add_10[grid(16)](buf33, buf26, primals_20, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del primals_20
return (buf33, primals_3, primals_8, primals_15, buf2, buf9,
reinterpret_tensor(buf11, (4, 4), (4, 1), 0), buf12, buf15,
primals_10, buf22, reinterpret_tensor(buf24, (4, 4), (4, 1), 0),
buf26, buf29, buf31, primals_19, primals_17, primals_13,
reinterpret_tensor(buf18, (4, 1, 4), (1, 1, 4), 0),
reinterpret_tensor(buf19, (4, 1, 4), (1, 1, 4), 0),
reinterpret_tensor(buf17, (4, 4, 1), (1, 4, 1), 0),
reinterpret_tensor(primals_11, (4, 4), (4, 1), 0), primals_6,
reinterpret_tensor(buf5, (4, 1, 4), (1, 1, 4), 0),
reinterpret_tensor(buf6, (4, 1, 4), (1, 1, 4), 0),
reinterpret_tensor(buf4, (4, 4, 1), (1, 4, 1), 0),
reinterpret_tensor(primals_4, (4, 4), (4, 1), 32),
reinterpret_tensor(primals_4, (4, 4), (4, 1), 16),
reinterpret_tensor(primals_4, (4, 4), (4, 1), 0))
class PreNormTransformerDecoderLayerNew(nn.TransformerDecoderLayer):
"""
A variant of :class:`torch.nn.TransformerDecoderLayer` where layer
normalization is included inside the residual branch, and performed before
self-attention and feedforward layers.
Refer documentation of :class:`torch.nn.TransformerDecoderLayer` for more
details on the API.
"""
def forward(self, input_0, input_1):
primals_4 = self.self_attn.in_proj_weight
primals_5 = self.self_attn.in_proj_bias
primals_3 = self.self_attn.out_proj.weight
primals_1 = self.self_attn.out_proj.bias
primals_11 = self.multihead_attn.in_proj_weight
primals_12 = self.multihead_attn.in_proj_bias
primals_6 = self.multihead_attn.out_proj.weight
primals_2 = self.multihead_attn.out_proj.bias
primals_17 = self.linear1.weight
primals_18 = self.linear1.bias
primals_19 = self.linear2.weight
primals_7 = self.linear2.bias
primals_8 = self.norm1.weight
primals_9 = self.norm1.bias
primals_14 = self.norm2.weight
primals_15 = self.norm2.bias
primals_16 = self.norm3.weight
primals_20 = self.norm3.bias
primals_10 = input_0
primals_13 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11, primals_12, primals_13, primals_14,
primals_15, primals_16, primals_17, primals_18, primals_19,
primals_20])
return output[0]
|
funnyzhou/REFERS
|
PreNormTransformerDecoderLayer
| false
| 15,396
|
[
"MIT"
] | 46
|
392eddf13cbf3c3a7dc0bf8bfffd108ca4a65a19
|
https://github.com/funnyzhou/REFERS/tree/392eddf13cbf3c3a7dc0bf8bfffd108ca4a65a19
|
CausalConv1d
|
import torch
from torch import nn
class CausalConv1d(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size=2, dilation=2):
super(CausalConv1d, self).__init__()
self.padding = dilation
self.causal_conv = nn.Conv1d(in_channels, out_channels, kernel_size,
padding=self.padding, dilation=dilation)
def forward(self, minibatch):
return self.causal_conv(minibatch)[:, :, :-self.padding]
def get_inputs():
return [torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'out_channels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
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 = 96
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 6 % 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), (8, 2, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4), (16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,),
padding=(2,), dilation=(2,), transposed=False, output_padding=(
0,), groups=1, bias=None)
assert_size_stride(buf0, (4, 4, 6), (24, 6, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(96)](buf1, primals_2, 96,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_2
return reinterpret_tensor(buf1, (4, 4, 4), (24, 6, 1), 0
), primals_1, primals_3
class CausalConv1dNew(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size=2, dilation=2):
super(CausalConv1dNew, self).__init__()
self.padding = dilation
self.causal_conv = nn.Conv1d(in_channels, out_channels, kernel_size,
padding=self.padding, dilation=dilation)
def forward(self, input_0):
primals_1 = self.causal_conv.weight
primals_2 = self.causal_conv.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
gaotianyu1350/new_fewrel_bertpair
|
CausalConv1d
| false
| 15,397
|
[
"MIT"
] | 180
|
27184050d476fc93576948fb26680d508a2824bb
|
https://github.com/gaotianyu1350/new_fewrel_bertpair/tree/27184050d476fc93576948fb26680d508a2824bb
|
OneHotEncode
|
import torch
import torch.optim
import torch.nn as nn
import torch.nn.utils
import torch.autograd
def one_hot_encoding(input_tensor, num_labels):
""" One-hot encode labels from input """
xview = input_tensor.view(-1, 1)
onehot = torch.zeros(xview.size(0), num_labels, device=input_tensor.
device, dtype=torch.float)
onehot.scatter_(1, xview, 1)
return onehot.view(list(input_tensor.shape) + [-1])
class OneHotEncode(nn.Module):
""" One-hot encoding layer """
def __init__(self, num_classes):
super().__init__()
self.num_classes = num_classes
def forward(self, x):
return one_hot_encoding(x, self.num_classes)
def get_inputs():
return [torch.ones([4], dtype=torch.int64)]
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
import torch.optim
import torch.nn as nn
import torch.nn.utils
import torch.autograd
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_scatter_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
x1 = xindex // 4
x0 = xindex % 4
x2 = 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(out_ptr0 + x2, tmp5, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_scatter_0[grid(16)](arg0_1, buf0, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del arg0_1
return buf0,
def one_hot_encoding(input_tensor, num_labels):
""" One-hot encode labels from input """
xview = input_tensor.view(-1, 1)
onehot = torch.zeros(xview.size(0), num_labels, device=input_tensor.
device, dtype=torch.float)
onehot.scatter_(1, xview, 1)
return onehot.view(list(input_tensor.shape) + [-1])
class OneHotEncodeNew(nn.Module):
""" One-hot encoding layer """
def __init__(self, num_classes):
super().__init__()
self.num_classes = num_classes
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
galatolofederico/vel
|
OneHotEncode
| false
| 15,399
|
[
"MIT"
] | 273
|
0473648cffb3f34fb784d12dbb25844ab58ffc3c
|
https://github.com/galatolofederico/vel/tree/0473648cffb3f34fb784d12dbb25844ab58ffc3c
|
TimeBlock
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class TimeBlock(nn.Module):
"""
Neural network block that applies a temporal convolution to each node of
a graph in isolation.
"""
def __init__(self, in_channels, out_channels, kernel_size=3):
"""
:param in_channels: Number of input features at each node in each time
step.
:param out_channels: Desired number of output channels at each node in
each time step.
:param kernel_size: Size of the 1D temporal kernel.
"""
super(TimeBlock, self).__init__()
self.conv1 = nn.Conv2d(in_channels, out_channels, (1, kernel_size))
self.conv2 = nn.Conv2d(in_channels, out_channels, (1, kernel_size))
self.conv3 = nn.Conv2d(in_channels, out_channels, (1, kernel_size))
def forward(self, X):
"""
:param X: Input data of shape (batch_size, num_nodes, num_timesteps,
num_features=in_channels)
:return: Output data of shape (batch_size, num_nodes,
num_timesteps_out, num_features_out=out_channels)
"""
X = X.permute(0, 3, 1, 2)
temp = self.conv1(X) + torch.sigmoid(self.conv2(X))
out = F.relu(temp + self.conv3(X))
out = out.permute(0, 2, 3, 1)
return out
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'out_channels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_convolution_0(in_ptr0, out_ptr0, ynumel, xnumel,
YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 3
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 4
y1 = yindex // 4
tmp0 = tl.load(in_ptr0 + (x2 + 3 * y3), xmask & ymask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (y0 + 4 * x2 + 12 * y1), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_add_convolution_relu_sigmoid_threshold_backward_1(
in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_out_ptr1 + x2, xmask)
tmp4 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr2 + x2, xmask)
tmp9 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp5 = tmp3 + tmp4
tmp6 = tl.sigmoid(tmp2)
tmp7 = tmp5 + tmp6
tmp10 = tmp8 + tmp9
tmp11 = tmp7 + tmp10
tmp12 = tl.full([1], 0, tl.int32)
tmp13 = triton_helpers.maximum(tmp12, tmp11)
tmp14 = 0.0
tmp15 = tmp13 <= tmp14
tl.store(in_out_ptr0 + x2, tmp2, xmask)
tl.store(in_out_ptr1 + x2, tmp13, xmask)
tl.store(out_ptr0 + x2, tmp15, 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, 1, 3), (12, 3, 3, 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,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 1, 3), (12, 1, 12, 4), torch.float32)
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(16, 3)](primals_2, buf0, 16, 3,
XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1)
buf1 = extern_kernels.convolution(reinterpret_tensor(primals_1, (4,
4, 4, 4), (64, 1, 16, 4), 0), buf0, 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, 2), (32, 1, 8, 4))
buf2 = buf0
del buf0
triton_poi_fused_convolution_0[grid(16, 3)](primals_4, buf2, 16, 3,
XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1)
buf3 = extern_kernels.convolution(reinterpret_tensor(primals_1, (4,
4, 4, 4), (64, 1, 16, 4), 0), buf2, 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, 2), (32, 1, 8, 4))
buf5 = buf2
del buf2
triton_poi_fused_convolution_0[grid(16, 3)](primals_6, buf5, 16, 3,
XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1)
buf6 = extern_kernels.convolution(reinterpret_tensor(primals_1, (4,
4, 4, 4), (64, 1, 16, 4), 0), buf5, stride=(1, 1), padding=(0,
0), dilation=(1, 1), transposed=False, output_padding=(0, 0),
groups=1, bias=None)
assert_size_stride(buf6, (4, 4, 4, 2), (32, 1, 8, 4))
del buf5
buf4 = buf3
del buf3
buf7 = buf1
del buf1
buf8 = empty_strided_cuda((4, 4, 4, 2), (32, 1, 8, 4), torch.bool)
triton_poi_fused_add_convolution_relu_sigmoid_threshold_backward_1[grid
(128)](buf4, buf7, primals_5, primals_3, buf6, primals_7, buf8,
128, XBLOCK=128, num_warps=4, num_stages=1)
del buf6
del primals_3
del primals_5
del primals_7
return reinterpret_tensor(buf7, (4, 4, 2, 4), (32, 8, 4, 1), 0
), primals_2, primals_4, primals_6, reinterpret_tensor(primals_1, (
4, 4, 4, 4), (64, 1, 16, 4), 0), buf4, buf8
class TimeBlockNew(nn.Module):
"""
Neural network block that applies a temporal convolution to each node of
a graph in isolation.
"""
def __init__(self, in_channels, out_channels, kernel_size=3):
"""
:param in_channels: Number of input features at each node in each time
step.
:param out_channels: Desired number of output channels at each node in
each time step.
:param kernel_size: Size of the 1D temporal kernel.
"""
super(TimeBlockNew, self).__init__()
self.conv1 = nn.Conv2d(in_channels, out_channels, (1, kernel_size))
self.conv2 = nn.Conv2d(in_channels, out_channels, (1, kernel_size))
self.conv3 = nn.Conv2d(in_channels, out_channels, (1, kernel_size))
def forward(self, input_0):
primals_2 = self.conv1.weight
primals_3 = self.conv1.bias
primals_4 = self.conv2.weight
primals_5 = self.conv2.bias
primals_6 = self.conv3.weight
primals_7 = self.conv3.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7])
return output[0]
|
garygsw/STGCN-PyTorch
|
TimeBlock
| false
| 15,400
|
[
"MIT"
] | 220
|
83ae49e566c779444efd21fc03cce54a765ee9f7
|
https://github.com/garygsw/STGCN-PyTorch/tree/83ae49e566c779444efd21fc03cce54a765ee9f7
|
DenseBlock
|
import torch
from torch import nn
from torch.nn import functional as F
class CausalConv1d(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size=2, dilation=2):
super(CausalConv1d, self).__init__()
self.padding = dilation
self.causal_conv = nn.Conv1d(in_channels, out_channels, kernel_size,
padding=self.padding, dilation=dilation)
def forward(self, minibatch):
return self.causal_conv(minibatch)[:, :, :-self.padding]
class DenseBlock(nn.Module):
def __init__(self, in_channels, filters, dilation=2):
super(DenseBlock, self).__init__()
self.causal_conv1 = CausalConv1d(in_channels, filters, dilation=
dilation)
self.causal_conv2 = CausalConv1d(in_channels, filters, dilation=
dilation)
def forward(self, minibatch):
tanh = F.tanh(self.causal_conv1(minibatch))
sig = F.sigmoid(self.causal_conv2(minibatch))
out = torch.cat([minibatch, tanh * sig], dim=1)
return out
def get_inputs():
return [torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'filters': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.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_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 96
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 6 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, xmask)
@triton.jit
def triton_poi_fused_cat_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 4 % 8
x0 = xindex % 4
x2 = xindex // 32
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 4 * x1 + 16 * x2), tmp4 & xmask, other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 8, tl.int64)
tmp9 = tl.load(in_ptr1 + (x0 + 6 * (-4 + x1) + 24 * x2), tmp6 & xmask,
other=0.0)
tmp10 = libdevice.tanh(tmp9)
tmp11 = tl.load(in_ptr2 + (x0 + 6 * (-4 + x1) + 24 * x2), tmp6 & xmask,
other=0.0)
tmp12 = tl.sigmoid(tmp11)
tmp13 = tmp10 * tmp12
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)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 2), (8, 2, 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, 2), (8, 2, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,),
padding=(2,), dilation=(2,), transposed=False, output_padding=(
0,), groups=1, bias=None)
assert_size_stride(buf0, (4, 4, 6), (24, 6, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(96)](buf1, primals_2, 96,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_2
buf2 = extern_kernels.convolution(primals_3, primals_4, stride=(1,),
padding=(2,), dilation=(2,), transposed=False, output_padding=(
0,), groups=1, bias=None)
assert_size_stride(buf2, (4, 4, 6), (24, 6, 1))
buf3 = buf2
del buf2
triton_poi_fused_convolution_0[grid(96)](buf3, primals_5, 96,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_5
buf4 = empty_strided_cuda((4, 8, 4), (32, 4, 1), torch.float32)
triton_poi_fused_cat_1[grid(128)](primals_3, buf1, buf3, buf4, 128,
XBLOCK=128, num_warps=4, num_stages=1)
return buf4, primals_1, primals_3, primals_4, buf1, buf3
class CausalConv1d(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size=2, dilation=2):
super(CausalConv1d, self).__init__()
self.padding = dilation
self.causal_conv = nn.Conv1d(in_channels, out_channels, kernel_size,
padding=self.padding, dilation=dilation)
def forward(self, minibatch):
return self.causal_conv(minibatch)[:, :, :-self.padding]
class DenseBlockNew(nn.Module):
def __init__(self, in_channels, filters, dilation=2):
super(DenseBlockNew, self).__init__()
self.causal_conv1 = CausalConv1d(in_channels, filters, dilation=
dilation)
self.causal_conv2 = CausalConv1d(in_channels, filters, dilation=
dilation)
def forward(self, input_0):
primals_1 = self.causal_conv1.causal_conv.weight
primals_2 = self.causal_conv1.causal_conv.bias
primals_4 = self.causal_conv2.causal_conv.weight
primals_5 = self.causal_conv2.causal_conv.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
gaotianyu1350/new_fewrel_bertpair
|
DenseBlock
| false
| 15,401
|
[
"MIT"
] | 180
|
27184050d476fc93576948fb26680d508a2824bb
|
https://github.com/gaotianyu1350/new_fewrel_bertpair/tree/27184050d476fc93576948fb26680d508a2824bb
|
DiagGaussianActionHead
|
import torch
import numpy as np
import torch.optim
import torch.nn as nn
import torch.nn.init as init
import torch.nn.utils
import torch.autograd
class DiagGaussianActionHead(nn.Module):
"""
Action head where actions are normally distibuted uncorrelated variables with specific means and variances.
Means are calculated directly from the network while standard deviation are a parameter of this module
"""
LOG2PI = np.log(2.0 * np.pi)
def __init__(self, input_dim, num_dimensions):
super().__init__()
self.input_dim = input_dim
self.num_dimensions = num_dimensions
self.linear_layer = nn.Linear(input_dim, num_dimensions)
self.log_std = nn.Parameter(torch.zeros(1, num_dimensions))
def forward(self, input_data):
means = self.linear_layer(input_data)
log_std_tile = self.log_std.repeat(means.size(0), 1)
return torch.stack([means, log_std_tile], dim=-1)
def sample(self, params, argmax_sampling=False):
""" Sample from a probability space of all actions """
means = params[:, :, 0]
log_std = params[:, :, 1]
if argmax_sampling:
return means
else:
return torch.randn_like(means) * torch.exp(log_std) + means
def logprob(self, action_sample, pd_params):
""" Log-likelihood """
means = pd_params[:, :, 0]
log_std = pd_params[:, :, 1]
std = torch.exp(log_std)
z_score = (action_sample - means) / std
return -(0.5 * (z_score ** 2 + self.LOG2PI).sum(dim=-1) + log_std.
sum(dim=-1))
def reset_weights(self):
init.orthogonal_(self.linear_layer.weight, gain=0.01)
init.constant_(self.linear_layer.bias, 0.0)
def entropy(self, params):
"""
Categorical distribution entropy calculation - sum probs * log(probs).
In case of diagonal gaussian distribution - 1/2 log(2 pi e sigma^2)
"""
log_std = params[:, :, 1]
return (log_std + 0.5 * (self.LOG2PI + 1)).sum(dim=-1)
def kl_divergence(self, params_q, params_p):
"""
Categorical distribution KL divergence calculation
KL(Q || P) = sum Q_i log (Q_i / P_i)
Formula is:
log(sigma_p) - log(sigma_q) + (sigma_q^2 + (mu_q - mu_p)^2))/(2 * sigma_p^2)
"""
means_q = params_q[:, :, 0]
log_std_q = params_q[:, :, 1]
means_p = params_p[:, :, 0]
log_std_p = params_p[:, :, 1]
std_q = torch.exp(log_std_q)
std_p = torch.exp(log_std_p)
kl_div = log_std_p - log_std_q + (std_q ** 2 + (means_q - means_p) ** 2
) / (2.0 * std_p ** 2) - 0.5
return kl_div.sum(dim=-1)
def get_inputs():
return [torch.rand([4, 4])]
def get_init_inputs():
return [[], {'input_dim': 4, 'num_dimensions': 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.optim
import torch.nn as nn
import torch.nn.init as init
import torch.nn.utils
import torch.autograd
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_stack_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 32
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 2
x3 = xindex // 2
x1 = xindex // 2 % 4
x4 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 1, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + x3, tmp4 & xmask, eviction_policy='evict_last',
other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 2, tl.int64)
tmp9 = tl.load(in_ptr1 + x1, tmp6 & xmask, eviction_policy='evict_last',
other=0.0)
tmp10 = tl.where(tmp4, tmp5, tmp9)
tl.store(out_ptr0 + x4, tmp10, 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,), (1,))
assert_size_stride(primals_3, (4, 4), (4, 1))
assert_size_stride(primals_4, (1, 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.addmm(primals_2, primals_3, reinterpret_tensor(
primals_1, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf0)
del primals_1
del primals_2
buf1 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_stack_0[grid(32)](buf0, primals_4, buf1, 32,
XBLOCK=32, num_warps=1, num_stages=1)
del buf0
del primals_4
return buf1, primals_3
class DiagGaussianActionHeadNew(nn.Module):
"""
Action head where actions are normally distibuted uncorrelated variables with specific means and variances.
Means are calculated directly from the network while standard deviation are a parameter of this module
"""
LOG2PI = np.log(2.0 * np.pi)
def __init__(self, input_dim, num_dimensions):
super().__init__()
self.input_dim = input_dim
self.num_dimensions = num_dimensions
self.linear_layer = nn.Linear(input_dim, num_dimensions)
self.log_std = nn.Parameter(torch.zeros(1, num_dimensions))
def sample(self, params, argmax_sampling=False):
""" Sample from a probability space of all actions """
means = params[:, :, 0]
log_std = params[:, :, 1]
if argmax_sampling:
return means
else:
return torch.randn_like(means) * torch.exp(log_std) + means
def logprob(self, action_sample, pd_params):
""" Log-likelihood """
means = pd_params[:, :, 0]
log_std = pd_params[:, :, 1]
std = torch.exp(log_std)
z_score = (action_sample - means) / std
return -(0.5 * (z_score ** 2 + self.LOG2PI).sum(dim=-1) + log_std.
sum(dim=-1))
def reset_weights(self):
init.orthogonal_(self.linear_layer.weight, gain=0.01)
init.constant_(self.linear_layer.bias, 0.0)
def entropy(self, params):
"""
Categorical distribution entropy calculation - sum probs * log(probs).
In case of diagonal gaussian distribution - 1/2 log(2 pi e sigma^2)
"""
log_std = params[:, :, 1]
return (log_std + 0.5 * (self.LOG2PI + 1)).sum(dim=-1)
def kl_divergence(self, params_q, params_p):
"""
Categorical distribution KL divergence calculation
KL(Q || P) = sum Q_i log (Q_i / P_i)
Formula is:
log(sigma_p) - log(sigma_q) + (sigma_q^2 + (mu_q - mu_p)^2))/(2 * sigma_p^2)
"""
means_q = params_q[:, :, 0]
log_std_q = params_q[:, :, 1]
means_p = params_p[:, :, 0]
log_std_p = params_p[:, :, 1]
std_q = torch.exp(log_std_q)
std_p = torch.exp(log_std_p)
kl_div = log_std_p - log_std_q + (std_q ** 2 + (means_q - means_p) ** 2
) / (2.0 * std_p ** 2) - 0.5
return kl_div.sum(dim=-1)
def forward(self, input_0):
primals_4 = self.log_std
primals_1 = self.linear_layer.weight
primals_2 = self.linear_layer.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
galatolofederico/vel
|
DiagGaussianActionHead
| false
| 15,402
|
[
"MIT"
] | 273
|
0473648cffb3f34fb784d12dbb25844ab58ffc3c
|
https://github.com/galatolofederico/vel/tree/0473648cffb3f34fb784d12dbb25844ab58ffc3c
|
DotAttention
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class DotAttention(nn.Module):
def __init__(self, dropout=0.0):
super(DotAttention, self).__init__()
self.dropout = dropout
def forward(self, Q, K, V, mask_out=None, head_mask=None):
"""
一般输入信息 X 时,假设 K = V = X
att_weight = softmax( score_func(q, k) )
att = sum( att_weight * v )
:param Q: [..., L, H]
:param K: [..., S, H]
:param V: [..., S, H]
:param mask_out: [..., 1, S]
:return:
"""
H = Q.size(-1)
scale = float(H) ** 0.5
attention_weight = torch.matmul(Q, K.transpose(-1, -2)) / scale
if mask_out is not None:
while mask_out.dim() != Q.dim():
mask_out = mask_out.unsqueeze(1)
attention_weight.masked_fill_(mask_out, -100000000.0)
attention_weight = F.softmax(attention_weight, dim=-1)
attention_weight = F.dropout(attention_weight, self.dropout)
if head_mask is not None:
attention_weight = attention_weight * head_mask
attention_out = torch.matmul(attention_weight, V)
return attention_out, attention_weight
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
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp3 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last'
)
tmp1 = 1.0
tmp2 = tmp0 * tmp1
tmp4 = tmp3 * tmp1
tmp6 = tmp5 * tmp1
tmp7 = triton_helpers.maximum(tmp4, tmp6)
tmp9 = tmp8 * tmp1
tmp10 = triton_helpers.maximum(tmp7, tmp9)
tmp12 = tmp11 * tmp1
tmp13 = triton_helpers.maximum(tmp10, tmp12)
tmp14 = tmp2 - tmp13
tmp15 = 0.5
tmp16 = tmp14 * tmp15
tmp17 = tl_math.exp(tmp16)
tl.store(out_ptr0 + x2, tmp17, xmask)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
def call(args):
arg0_1, arg1_1, arg2_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(arg0_1, (16, 4, 4), (16, 4, 1
), 0), reinterpret_tensor(arg1_1, (16, 4, 4), (16, 1, 4), 0),
out=buf0)
del arg0_1
del arg1_1
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__softmax_0[grid(256)](buf0, buf1, 256, XBLOCK=256,
num_warps=4, num_stages=1)
buf2 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf0
triton_poi_fused__softmax_1[grid(256)](buf1, buf2, 256, XBLOCK=256,
num_warps=4, num_stages=1)
buf3 = reinterpret_tensor(buf1, (16, 4, 4), (16, 4, 1), 0)
del buf1
extern_kernels.bmm(reinterpret_tensor(buf2, (16, 4, 4), (16, 4, 1),
0), reinterpret_tensor(arg2_1, (16, 4, 4), (16, 4, 1), 0), out=buf3
)
del arg2_1
return reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0), buf2
class DotAttentionNew(nn.Module):
def __init__(self, dropout=0.0):
super(DotAttentionNew, self).__init__()
self.dropout = dropout
def forward(self, input_0, input_1, input_2):
arg0_1 = input_0
arg1_1 = input_1
arg2_1 = input_2
output = call([arg0_1, arg1_1, arg2_1])
return output[0], output[1]
|
fmc123653/DeepKE
|
DotAttention
| false
| 15,403
|
[
"MIT"
] | 676
|
4d30e51368681c7cb73e2ecacf9b922b441cbe99
|
https://github.com/fmc123653/DeepKE/tree/4d30e51368681c7cb73e2ecacf9b922b441cbe99
|
CosSim
|
import torch
import torch.nn as nn
class CosSim(nn.Module):
def __init__(self, nfeat, nclass, codebook=None, learn_cent=True):
super(CosSim, self).__init__()
self.nfeat = nfeat
self.nclass = nclass
self.learn_cent = learn_cent
if codebook is None:
codebook = torch.randn(nclass, nfeat)
self.centroids = nn.Parameter(codebook.clone())
if not learn_cent:
self.centroids.requires_grad_(False)
def forward(self, x):
norms = torch.norm(x, p=2, dim=-1, keepdim=True)
nfeat = torch.div(x, norms)
norms_c = torch.norm(self.centroids, p=2, dim=-1, keepdim=True)
ncenters = torch.div(self.centroids, norms_c)
logits = torch.matmul(nfeat, torch.transpose(ncenters, 0, 1))
return logits
def extra_repr(self) ->str:
return 'in_features={}, n_class={}, learn_centroid={}'.format(self.
nfeat, self.nclass, self.learn_cent)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'nfeat': 4, 'nclass': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_div_linalg_vector_norm_0(in_ptr0, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = tmp0 / tmp12
tl.store(out_ptr0 + x2, tmp13, xmask)
@triton.jit
def triton_poi_fused_div_linalg_vector_norm_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')
tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = tmp0 / tmp12
tl.store(out_ptr0 + x2, tmp13, xmask)
def call(args):
primals_1, primals_2 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_div_linalg_vector_norm_0[grid(256)](primals_1,
buf0, 256, XBLOCK=256, num_warps=4, num_stages=1)
del primals_1
buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused_div_linalg_vector_norm_1[grid(16)](primals_2, buf1,
16, XBLOCK=16, num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf0, (64, 4), (4, 1), 0),
reinterpret_tensor(buf1, (4, 4), (1, 4), 0), out=buf2)
del buf1
return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0
), primals_2, reinterpret_tensor(buf0, (64, 4), (4, 1), 0)
class CosSimNew(nn.Module):
def __init__(self, nfeat, nclass, codebook=None, learn_cent=True):
super(CosSimNew, self).__init__()
self.nfeat = nfeat
self.nclass = nclass
self.learn_cent = learn_cent
if codebook is None:
codebook = torch.randn(nclass, nfeat)
self.centroids = nn.Parameter(codebook.clone())
if not learn_cent:
self.centroids.requires_grad_(False)
def extra_repr(self) ->str:
return 'in_features={}, n_class={}, learn_centroid={}'.format(self.
nfeat, self.nclass, self.learn_cent)
def forward(self, input_0):
primals_2 = self.centroids
primals_1 = input_0
output = call([primals_1, primals_2])
return output[0]
|
gajrajgchouhan/orthohash
|
CosSim
| false
| 15,404
|
[
"BSD-3-Clause"
] | 51
|
4e04cfe1dd32e21ba004e308d5a1ce9c8578ea2b
|
https://github.com/gajrajgchouhan/orthohash/tree/4e04cfe1dd32e21ba004e308d5a1ce9c8578ea2b
|
PrecomputedNorm
|
import torch
import torch.nn as nn
class PrecomputedNorm(nn.Module):
"""Normalization using Pre-computed Mean/Std.
Args:
stats: Precomputed (mean, std).
axis: Axis setting used to calculate mean/variance.
"""
def __init__(self, stats, axis=[1, 2]):
super().__init__()
self.axis = axis
self.mean, self.std = stats
def forward(self, X: 'torch.Tensor') ->torch.Tensor:
return (X - self.mean) / self.std
def __repr__(self):
format_string = (self.__class__.__name__ +
f'(mean={self.mean}, std={self.std}, axis={self.axis})')
return format_string
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'stats': [4, 4]}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
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_sub_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 4.0
tmp2 = tmp0 - tmp1
tmp3 = 0.25
tmp4 = tmp2 * tmp3
tl.store(out_ptr0 + x0, tmp4, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_div_sub_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128,
num_warps=4, num_stages=1)
del arg0_1
return buf0,
class PrecomputedNormNew(nn.Module):
"""Normalization using Pre-computed Mean/Std.
Args:
stats: Precomputed (mean, std).
axis: Axis setting used to calculate mean/variance.
"""
def __init__(self, stats, axis=[1, 2]):
super().__init__()
self.axis = axis
self.mean, self.std = stats
def __repr__(self):
format_string = (self.__class__.__name__ +
f'(mean={self.mean}, std={self.std}, axis={self.axis})')
return format_string
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
gcambara/s3prl
|
PrecomputedNorm
| false
| 15,405
|
[
"MIT"
] | 856
|
33284ebde3a903ed8604d6dae85669d0174ae1d3
|
https://github.com/gcambara/s3prl/tree/33284ebde3a903ed8604d6dae85669d0174ae1d3
|
PGenLayer
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class PGenLayer(nn.Module):
def __init__(self, emb_dim, hidden_size, enc_dim):
super(PGenLayer, self).__init__()
self.emb_dim = emb_dim
self.hidden_size = hidden_size
self.enc_dim = enc_dim
self.lin = nn.Linear(self.emb_dim + self.hidden_size + self.enc_dim, 1)
def forward(self, emb, hid, enc):
"""
param: emb (batch_size, emb_dim)
hid (batch_size, hid_dim)
enc (batch_size, enc_dim)
"""
input = torch.cat((emb, hid, enc), 1)
return F.sigmoid(self.lin(input))
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4]), torch.rand([4, 4])]
def get_init_inputs():
return [[], {'emb_dim': 4, 'hidden_size': 4, 'enc_dim': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_cat_0(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 % 12
x1 = xindex // 12
x2 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tmp0 >= tmp3
tmp7 = tl.full([1], 8, tl.int64)
tmp8 = tmp0 < tmp7
tmp9 = tmp6 & tmp8
tmp10 = tl.load(in_ptr1 + (4 * x1 + (-4 + x0)), tmp9 & xmask,
eviction_policy='evict_last', other=0.0)
tmp11 = tmp0 >= tmp7
tl.full([1], 12, tl.int64)
tmp14 = tl.load(in_ptr2 + (4 * x1 + (-8 + x0)), 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 + x2, tmp16, xmask)
@triton.jit
def triton_poi_fused_sigmoid_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + 0)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
tmp3 = tmp0 + tmp2
tmp4 = tl.sigmoid(tmp3)
tl.store(in_out_ptr0 + x0, tmp4, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 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, (1, 12), (12, 1))
assert_size_stride(primals_5, (1,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 12), (12, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(48)](primals_1, primals_2, primals_3,
buf0, 48, XBLOCK=64, num_warps=1, num_stages=1)
del primals_1
del primals_2
del primals_3
buf1 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
extern_kernels.mm(buf0, reinterpret_tensor(primals_4, (12, 1), (1,
12), 0), out=buf1)
del primals_4
buf2 = buf1
del buf1
triton_poi_fused_sigmoid_1[grid(4)](buf2, primals_5, 4, XBLOCK=4,
num_warps=1, num_stages=1)
del primals_5
return buf2, buf0, buf2
class PGenLayerNew(nn.Module):
def __init__(self, emb_dim, hidden_size, enc_dim):
super(PGenLayerNew, self).__init__()
self.emb_dim = emb_dim
self.hidden_size = hidden_size
self.enc_dim = enc_dim
self.lin = nn.Linear(self.emb_dim + self.hidden_size + self.enc_dim, 1)
def forward(self, input_0, input_1, input_2):
primals_4 = self.lin.weight
primals_5 = self.lin.bias
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]
|
gau820827/AI-writer_Data2Doc
|
PGenLayer
| false
| 15,406
|
[
"Apache-2.0"
] | 77
|
6be0ee6238158a47aa0fdfa8a34df2a47714835a
|
https://github.com/gau820827/AI-writer_Data2Doc/tree/6be0ee6238158a47aa0fdfa8a34df2a47714835a
|
AMSoftmaxLoss
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class AMSoftmaxLoss(nn.Module):
def __init__(self, hidden_dim, speaker_num, s=30.0, m=0.4, **kwargs):
"""
AM Softmax Loss
"""
super(AMSoftmaxLoss, self).__init__()
self.s = s
self.m = m
self.speaker_num = speaker_num
self.W = torch.nn.Parameter(torch.randn(hidden_dim, speaker_num),
requires_grad=True)
nn.init.xavier_normal_(self.W, gain=1)
def forward(self, x_BxH, labels_B):
"""
x shape: (B, H)
labels shape: (B)
"""
assert len(x_BxH) == len(labels_B)
assert torch.min(labels_B) >= 0
assert torch.max(labels_B) < self.speaker_num
W = F.normalize(self.W, dim=0)
x_BxH = F.normalize(x_BxH, dim=1)
wf = torch.mm(x_BxH, W)
numerator = self.s * (torch.diagonal(wf.transpose(0, 1)[labels_B]) -
self.m)
excl = torch.cat([torch.cat((wf[i, :y], wf[i, y + 1:])).unsqueeze(0
) for i, y in enumerate(labels_B)], dim=0)
denominator = torch.exp(numerator) + torch.sum(torch.exp(self.s *
excl), dim=1)
L = numerator - torch.log(denominator)
return -torch.mean(L)
def get_inputs():
return [torch.rand([4, 4]), torch.ones([4], dtype=torch.int64)]
def get_init_inputs():
return [[], {'hidden_dim': 4, 'speaker_num': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_div_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = 1e-12
tmp14 = triton_helpers.maximum(tmp12, tmp13)
tmp15 = tmp0 / tmp14
tl.store(out_ptr0 + x2, tmp15, xmask)
@triton.jit
def triton_poi_fused_div_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (4 + x0), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (8 + x0), xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr0 + (12 + x0), xmask, eviction_policy='evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = 1e-12
tmp14 = triton_helpers.maximum(tmp12, tmp13)
tmp15 = tmp0 / tmp14
tl.store(out_ptr0 + x2, tmp15, xmask)
@triton.jit
def triton_poi_fused_mul_sub_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = tl.full([XBLOCK], 4, tl.int32)
tmp2 = tmp0 + tmp1
tmp3 = tmp0 < 0
tmp4 = tl.where(tmp3, tmp2, tmp0)
tl.device_assert((0 <= tmp4) & (tmp4 < 4) | ~xmask,
'index out of bounds: 0 <= tmp4 < 4')
tmp6 = tl.load(in_ptr1 + (tmp4 + 4 * x0), xmask, eviction_policy=
'evict_last')
tmp7 = 0.4
tmp8 = tmp6 - tmp7
tmp9 = 30.0
tmp10 = tmp8 * tmp9
tl.store(out_ptr0 + x0, tmp10, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_div_0[grid(16)](primals_1, buf0, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del primals_1
buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused_div_1[grid(16)](primals_3, buf1, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf0, buf1, out=buf2)
del buf1
buf3 = empty_strided_cuda((4,), (1,), torch.float32)
triton_poi_fused_mul_sub_2[grid(4)](primals_2, buf2, buf3, 4,
XBLOCK=4, num_warps=1, num_stages=1)
return buf3, buf2, primals_2, primals_3, reinterpret_tensor(buf0, (4, 4
), (1, 4), 0)
class AMSoftmaxLossNew(nn.Module):
def __init__(self, hidden_dim, speaker_num, s=30.0, m=0.4, **kwargs):
"""
AM Softmax Loss
"""
super(AMSoftmaxLossNew, self).__init__()
self.s = s
self.m = m
self.speaker_num = speaker_num
self.W = torch.nn.Parameter(torch.randn(hidden_dim, speaker_num),
requires_grad=True)
nn.init.xavier_normal_(self.W, gain=1)
def forward(self, input_0, input_1):
primals_1 = self.W
primals_3 = input_0
primals_2 = input_1
output = call([primals_1, primals_2, primals_3])
return output[0]
|
gcambara/s3prl
|
AMSoftmaxLoss
| false
| 15,407
|
[
"MIT"
] | 856
|
33284ebde3a903ed8604d6dae85669d0174ae1d3
|
https://github.com/gcambara/s3prl/tree/33284ebde3a903ed8604d6dae85669d0174ae1d3
|
TransformerDecoderBlock
|
import math
import torch
import torch.nn as nn
class AddAndNorm(nn.Module):
def __init__(self, d_model):
super(AddAndNorm, self).__init__()
self.layer_norm = nn.LayerNorm(d_model)
def forward(self, x, residual):
return self.layer_norm(x + residual)
class ScaledDotProductAttention(nn.Module):
def __init__(self, d_head):
super(ScaledDotProductAttention, self).__init__()
self.d_head = d_head
self.attention_dropout = nn.Dropout(p=0.1)
def forward(self, q, k, v, mask=None):
attention_weights = torch.matmul(q, k.transpose(-2, -1))
scaled_attention_weights = attention_weights / math.sqrt(self.d_head)
if mask is not None:
scaled_attention_weights = scaled_attention_weights.masked_fill(
mask == 0, float('-inf'))
scaled_attention_weights = nn.functional.softmax(
scaled_attention_weights, dim=-1)
scaled_attention_weights = self.attention_dropout(
scaled_attention_weights)
weighted_v = torch.matmul(scaled_attention_weights, v)
return weighted_v
class MultiHeadAttention(nn.Module):
def __init__(self, d_model, n_heads):
super(MultiHeadAttention, self).__init__()
self.n_heads = n_heads
assert d_model % n_heads == 0
self.d_head = d_model // n_heads
self.dot_product_attention_layer = ScaledDotProductAttention(self.
d_head)
self.W_0 = nn.Linear(d_model, d_model)
def _split_into_heads(self, q, k, v):
q = q.view(q.size(0), q.size(1), self.n_heads, self.d_head)
k = k.view(k.size(0), k.size(1), self.n_heads, self.d_head)
v = v.view(v.size(0), v.size(1), self.n_heads, self.d_head)
q = q.transpose(1, 2)
k = k.transpose(1, 2)
v = v.transpose(1, 2)
return q, k, v
def _concatenate_heads(self, attention_output):
attention_output = attention_output.transpose(1, 2).contiguous()
attention_output = attention_output.view(attention_output.size(0),
attention_output.size(1), -1)
return attention_output
def forward(self, q, k, v, mask=None):
q, k, v = self._split_into_heads(q, k, v)
attention_output = self.dot_product_attention_layer(q, k, v, mask)
attention_output = self._concatenate_heads(attention_output)
attention_output = self.W_0(attention_output)
return attention_output
class PositionWiseFeedForwardNet(nn.Module):
def __init__(self, d_model, d_ff):
super(PositionWiseFeedForwardNet, self).__init__()
self.w_1 = nn.Linear(d_model, d_ff)
self.w_2 = nn.Linear(d_ff, d_model)
self.dropout = nn.Dropout(0.1)
def forward(self, x):
return self.w_2(self.dropout(torch.relu(self.w_1(x))))
class TransformerDecoderBlock(nn.Module):
def __init__(self, d_model, n_heads, d_ff, dropout_proba):
super(TransformerDecoderBlock, self).__init__()
self.W_q_1 = nn.Linear(d_model, d_model)
self.W_k_1 = nn.Linear(d_model, d_model)
self.W_v_1 = nn.Linear(d_model, d_model)
self.mha_layer_1 = MultiHeadAttention(d_model, n_heads)
self.dropout_layer_1 = nn.Dropout(dropout_proba)
self.add_and_norm_1 = AddAndNorm(d_model)
self.W_q_2 = nn.Linear(d_model, d_model)
self.W_k_2 = nn.Linear(d_model, d_model)
self.W_v_2 = nn.Linear(d_model, d_model)
self.mha_layer_2 = MultiHeadAttention(d_model, n_heads)
self.dropout_layer_2 = nn.Dropout(dropout_proba)
self.add_and_norm_2 = AddAndNorm(d_model)
self.ffn_layer = PositionWiseFeedForwardNet(d_model, d_ff)
self.dropout_layer_3 = nn.Dropout(dropout_proba)
self.add_and_norm_3 = AddAndNorm(d_model)
def forward(self, x, encoder_output, src_mask, trg_mask):
q_1 = self.W_q_1(x)
k_1 = self.W_k_1(x)
v_1 = self.W_v_1(x)
mha_layer_1_out = self.mha_layer_1(q_1, k_1, v_1, trg_mask)
mha_layer_1_out = self.dropout_layer_1(mha_layer_1_out)
mha_layer_1_out = self.add_and_norm_1(mha_layer_1_out, x)
q_2 = self.W_q_2(mha_layer_1_out)
k_2 = self.W_k_2(encoder_output)
v_2 = self.W_v_2(encoder_output)
mha_layer_2_out = self.mha_layer_2(q_2, k_2, v_2, src_mask)
mha_layer_2_out = self.dropout_layer_2(mha_layer_2_out)
mha_layer_2_out = self.add_and_norm_2(mha_layer_2_out, mha_layer_1_out)
ffn_out = self.ffn_layer(mha_layer_2_out)
ffn_out = self.dropout_layer_3(ffn_out)
ffn_out = self.add_and_norm_3(ffn_out, mha_layer_2_out)
return ffn_out
def get_inputs():
return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4]), torch.rand([4, 4,
4]), torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'d_model': 4, 'n_heads': 4, 'd_ff': 4, 'dropout_proba': 0.5}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
import math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_clone_0(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel,
YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 4
y1 = yindex // 4
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + (x2 + 4 * y3), tmp2, xmask & ymask)
@triton.jit
def triton_poi_fused_eq_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 = 0.0
tmp2 = tmp0 == tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused__softmax_div_masked_fill_2(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 % 16
x2 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last').to(tl
.int1)
tmp1 = tl.load(in_ptr1 + 4 * x2, xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
).to(tl.int1)
tmp7 = tl.load(in_ptr1 + (1 + 4 * x2), xmask, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
).to(tl.int1)
tmp12 = tl.load(in_ptr1 + (2 + 4 * x2), xmask, eviction_policy='evict_last'
)
tmp16 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
).to(tl.int1)
tmp17 = tl.load(in_ptr1 + (3 + 4 * x2), xmask, eviction_policy='evict_last'
)
tmp2 = 1.0
tmp3 = tmp1 * tmp2
tmp4 = float('-inf')
tmp5 = tl.where(tmp0, tmp4, tmp3)
tmp8 = tmp7 * tmp2
tmp9 = tl.where(tmp6, tmp4, tmp8)
tmp10 = triton_helpers.maximum(tmp5, tmp9)
tmp13 = tmp12 * tmp2
tmp14 = tl.where(tmp11, tmp4, tmp13)
tmp15 = triton_helpers.maximum(tmp10, tmp14)
tmp18 = tmp17 * tmp2
tmp19 = tl.where(tmp16, tmp4, tmp18)
tmp20 = triton_helpers.maximum(tmp15, tmp19)
tmp21 = tmp5 - tmp20
tmp22 = tl_math.exp(tmp21)
tmp23 = tmp9 - tmp20
tmp24 = tl_math.exp(tmp23)
tmp25 = tmp22 + tmp24
tmp26 = tmp14 - tmp20
tmp27 = tl_math.exp(tmp26)
tmp28 = tmp25 + tmp27
tmp29 = tmp19 - tmp20
tmp30 = tl_math.exp(tmp29)
tmp31 = tmp28 + tmp30
tl.store(out_ptr0 + x2, tmp20, xmask)
tl.store(out_ptr1 + x2, tmp31, xmask)
@triton.jit
def triton_poi_fused__softmax_div_masked_fill_3(in_out_ptr0, in_ptr0,
in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex % 64
x4 = xindex
x5 = xindex // 4
tmp0 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last').to(tl
.int1)
tmp1 = tl.load(in_out_ptr0 + x4, xmask)
tmp6 = tl.load(in_ptr1 + x5, xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr2 + x5, xmask, eviction_policy='evict_last')
tmp2 = 1.0
tmp3 = tmp1 * tmp2
tmp4 = float('-inf')
tmp5 = tl.where(tmp0, tmp4, tmp3)
tmp7 = tmp5 - tmp6
tmp8 = tl_math.exp(tmp7)
tmp10 = tmp8 / tmp9
tl.store(in_out_ptr0 + x4, tmp10, xmask)
@triton.jit
def triton_poi_fused_clone_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 4
y1 = yindex // 4
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_add_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_add_7(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
tl.store(in_out_ptr0 + x2, tmp4, xmask)
@triton.jit
def triton_poi_fused_native_layer_norm_8(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_9(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_relu_threshold_backward_10(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)
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, 1))
assert_size_stride(primals_7, (4,), (1,))
assert_size_stride(primals_8, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_9, (4, 4), (4, 1))
assert_size_stride(primals_10, (4,), (1,))
assert_size_stride(primals_11, (4,), (1,))
assert_size_stride(primals_12, (4,), (1,))
assert_size_stride(primals_13, (4, 4), (4, 1))
assert_size_stride(primals_14, (4,), (1,))
assert_size_stride(primals_15, (4, 4), (4, 1))
assert_size_stride(primals_16, (4,), (1,))
assert_size_stride(primals_17, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_18, (4, 4), (4, 1))
assert_size_stride(primals_19, (4,), (1,))
assert_size_stride(primals_20, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_21, (4, 4), (4, 1))
assert_size_stride(primals_22, (4,), (1,))
assert_size_stride(primals_23, (4,), (1,))
assert_size_stride(primals_24, (4,), (1,))
assert_size_stride(primals_25, (4, 4), (4, 1))
assert_size_stride(primals_26, (4,), (1,))
assert_size_stride(primals_27, (4, 4), (4, 1))
assert_size_stride(primals_28, (4,), (1,))
assert_size_stride(primals_29, (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_3, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1)
del primals_4
buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_3, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), out=buf2)
del primals_6
buf3 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(16, 4)](buf0, primals_2, buf3, 16, 4,
XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1)
del primals_2
buf4 = reinterpret_tensor(buf0, (4, 4, 1, 4), (16, 4, 4, 1), 0)
del buf0
triton_poi_fused_clone_0[grid(16, 4)](buf1, primals_5, buf4, 16, 4,
XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1)
del primals_5
buf5 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf3, (16, 4, 1), (4, 1, 0),
0), reinterpret_tensor(buf4, (16, 1, 4), (4, 0, 1), 0), out=buf5)
buf6 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
triton_poi_fused_eq_1[grid(64)](primals_8, buf6, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del primals_8
buf7 = reinterpret_tensor(buf1, (4, 4, 4, 1), (16, 4, 1, 64), 0)
del buf1
buf8 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
triton_poi_fused__softmax_div_masked_fill_2[grid(64)](buf6, buf5,
buf7, buf8, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf9 = reinterpret_tensor(buf5, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf5
triton_poi_fused__softmax_div_masked_fill_3[grid(256)](buf9, buf6,
buf7, buf8, 256, XBLOCK=128, num_warps=4, num_stages=1)
buf10 = reinterpret_tensor(buf8, (4, 4, 4, 1), (16, 4, 1, 1), 0)
del buf8
triton_poi_fused_clone_0[grid(16, 4)](buf2, primals_7, buf10, 16, 4,
XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1)
del primals_7
buf11 = reinterpret_tensor(buf2, (16, 4, 1), (4, 1, 1), 0)
del buf2
extern_kernels.bmm(reinterpret_tensor(buf9, (16, 4, 4), (16, 4, 1),
0), reinterpret_tensor(buf10, (16, 4, 1), (4, 1, 0), 0), out=buf11)
buf12 = reinterpret_tensor(buf7, (4, 4, 4, 1), (16, 4, 1, 1), 0)
del buf7
triton_poi_fused_clone_4[grid(16, 4)](buf11, buf12, 16, 4, XBLOCK=4,
YBLOCK=16, num_warps=1, num_stages=1)
buf13 = reinterpret_tensor(buf11, (16, 4), (4, 1), 0)
del buf11
extern_kernels.addmm(primals_10, reinterpret_tensor(buf12, (16, 4),
(4, 1), 0), reinterpret_tensor(primals_9, (4, 4), (1, 4), 0),
alpha=1, beta=1, out=buf13)
del primals_10
buf14 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
buf15 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
triton_poi_fused_add_native_layer_norm_5[grid(16)](buf13, primals_3,
buf14, buf15, 16, XBLOCK=16, num_warps=1, num_stages=1)
buf16 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_native_layer_norm_6[grid(64)](buf13, primals_3,
buf14, buf15, primals_11, primals_12, buf16, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del primals_12
buf17 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf16, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_13, (4, 4), (1, 4), 0), out=buf17)
buf18 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_17, (16, 4), (4, 1), 0
), reinterpret_tensor(primals_15, (4, 4), (1, 4), 0), out=buf18)
del primals_15
buf19 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_17, (16, 4), (4, 1), 0
), reinterpret_tensor(primals_18, (4, 4), (1, 4), 0), out=buf19)
del primals_18
buf20 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32)
triton_poi_fused_clone_0[grid(16, 4)](buf17, primals_14, buf20, 16,
4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1)
del primals_14
buf21 = reinterpret_tensor(buf17, (4, 4, 1, 4), (16, 4, 4, 1), 0)
del buf17
triton_poi_fused_clone_0[grid(16, 4)](buf18, primals_16, buf21, 16,
4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1)
del primals_16
buf22 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf20, (16, 4, 1), (4, 1, 0),
0), reinterpret_tensor(buf21, (16, 1, 4), (4, 0, 1), 0), out=buf22)
buf23 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
triton_poi_fused_eq_1[grid(64)](primals_20, buf23, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del primals_20
buf24 = reinterpret_tensor(buf18, (4, 4, 4, 1), (16, 4, 1, 64), 0)
del buf18
buf25 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
triton_poi_fused__softmax_div_masked_fill_2[grid(64)](buf23, buf22,
buf24, buf25, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf26 = reinterpret_tensor(buf22, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf22
triton_poi_fused__softmax_div_masked_fill_3[grid(256)](buf26, buf23,
buf24, buf25, 256, XBLOCK=128, num_warps=4, num_stages=1)
buf27 = reinterpret_tensor(buf25, (4, 4, 4, 1), (16, 4, 1, 1), 0)
del buf25
triton_poi_fused_clone_0[grid(16, 4)](buf19, primals_19, buf27, 16,
4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1)
del primals_19
buf28 = reinterpret_tensor(buf19, (16, 4, 1), (4, 1, 1), 0)
del buf19
extern_kernels.bmm(reinterpret_tensor(buf26, (16, 4, 4), (16, 4, 1),
0), reinterpret_tensor(buf27, (16, 4, 1), (4, 1, 0), 0), out=buf28)
buf29 = reinterpret_tensor(buf24, (4, 4, 4, 1), (16, 4, 1, 1), 0)
del buf24
triton_poi_fused_clone_4[grid(16, 4)](buf28, buf29, 16, 4, XBLOCK=4,
YBLOCK=16, num_warps=1, num_stages=1)
buf30 = reinterpret_tensor(buf28, (16, 4), (4, 1), 0)
del buf28
extern_kernels.mm(reinterpret_tensor(buf29, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_21, (4, 4), (1, 4), 0), out=buf30)
buf31 = reinterpret_tensor(buf30, (4, 4, 4), (16, 4, 1), 0)
del buf30
triton_poi_fused_add_7[grid(64)](buf31, primals_22, buf16, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del primals_22
buf32 = buf15
del buf15
buf33 = buf14
del buf14
triton_poi_fused_native_layer_norm_8[grid(16)](buf31, buf32, buf33,
16, XBLOCK=16, num_warps=1, num_stages=1)
buf34 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_native_layer_norm_9[grid(64)](buf31, buf32, buf33,
primals_23, primals_24, buf34, 64, XBLOCK=64, num_warps=1,
num_stages=1)
del primals_24
buf35 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf34, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_25, (4, 4), (1, 4), 0), out=buf35)
buf36 = reinterpret_tensor(buf35, (4, 4, 4), (16, 4, 1), 0)
del buf35
buf42 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_10[grid(64)](buf36,
primals_26, buf42, 64, XBLOCK=64, num_warps=1, num_stages=1)
del primals_26
buf37 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf36, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_27, (4, 4), (1, 4), 0), out=buf37)
buf38 = reinterpret_tensor(buf37, (4, 4, 4), (16, 4, 1), 0)
del buf37
triton_poi_fused_add_7[grid(64)](buf38, primals_28, buf34, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del primals_28
buf39 = buf33
del buf33
buf40 = buf32
del buf32
triton_poi_fused_native_layer_norm_8[grid(16)](buf38, buf39, buf40,
16, XBLOCK=16, num_warps=1, num_stages=1)
buf41 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_native_layer_norm_9[grid(64)](buf38, buf39, buf40,
primals_29, primals_30, buf41, 64, XBLOCK=64, num_warps=1,
num_stages=1)
del buf39
del buf40
del primals_30
return (buf41, primals_3, primals_11, primals_23, primals_29, buf6,
buf9, reinterpret_tensor(buf12, (16, 4), (4, 1), 0), buf13,
reinterpret_tensor(buf16, (16, 4), (4, 1), 0), reinterpret_tensor(
primals_17, (16, 4), (4, 1), 0), buf23, buf26, reinterpret_tensor(
buf29, (16, 4), (4, 1), 0), buf31, reinterpret_tensor(buf34, (16, 4
), (4, 1), 0), reinterpret_tensor(buf36, (16, 4), (4, 1), 0), buf38,
primals_27, buf42, primals_25, primals_21, reinterpret_tensor(buf27,
(16, 1, 4), (4, 1, 1), 0), reinterpret_tensor(buf20, (16, 1, 4), (4,
1, 1), 0), reinterpret_tensor(buf21, (16, 4, 1), (4, 1, 4), 0),
primals_13, primals_9, reinterpret_tensor(buf10, (16, 1, 4), (4, 1,
1), 0), reinterpret_tensor(buf3, (16, 1, 4), (4, 1, 1), 0),
reinterpret_tensor(buf4, (16, 4, 1), (4, 1, 4), 0))
class AddAndNorm(nn.Module):
def __init__(self, d_model):
super(AddAndNorm, self).__init__()
self.layer_norm = nn.LayerNorm(d_model)
def forward(self, x, residual):
return self.layer_norm(x + residual)
class ScaledDotProductAttention(nn.Module):
def __init__(self, d_head):
super(ScaledDotProductAttention, self).__init__()
self.d_head = d_head
self.attention_dropout = nn.Dropout(p=0.1)
def forward(self, q, k, v, mask=None):
attention_weights = torch.matmul(q, k.transpose(-2, -1))
scaled_attention_weights = attention_weights / math.sqrt(self.d_head)
if mask is not None:
scaled_attention_weights = scaled_attention_weights.masked_fill(
mask == 0, float('-inf'))
scaled_attention_weights = nn.functional.softmax(
scaled_attention_weights, dim=-1)
scaled_attention_weights = self.attention_dropout(
scaled_attention_weights)
weighted_v = torch.matmul(scaled_attention_weights, v)
return weighted_v
class MultiHeadAttention(nn.Module):
def __init__(self, d_model, n_heads):
super(MultiHeadAttention, self).__init__()
self.n_heads = n_heads
assert d_model % n_heads == 0
self.d_head = d_model // n_heads
self.dot_product_attention_layer = ScaledDotProductAttention(self.
d_head)
self.W_0 = nn.Linear(d_model, d_model)
def _split_into_heads(self, q, k, v):
q = q.view(q.size(0), q.size(1), self.n_heads, self.d_head)
k = k.view(k.size(0), k.size(1), self.n_heads, self.d_head)
v = v.view(v.size(0), v.size(1), self.n_heads, self.d_head)
q = q.transpose(1, 2)
k = k.transpose(1, 2)
v = v.transpose(1, 2)
return q, k, v
def _concatenate_heads(self, attention_output):
attention_output = attention_output.transpose(1, 2).contiguous()
attention_output = attention_output.view(attention_output.size(0),
attention_output.size(1), -1)
return attention_output
def forward(self, q, k, v, mask=None):
q, k, v = self._split_into_heads(q, k, v)
attention_output = self.dot_product_attention_layer(q, k, v, mask)
attention_output = self._concatenate_heads(attention_output)
attention_output = self.W_0(attention_output)
return attention_output
class PositionWiseFeedForwardNet(nn.Module):
def __init__(self, d_model, d_ff):
super(PositionWiseFeedForwardNet, self).__init__()
self.w_1 = nn.Linear(d_model, d_ff)
self.w_2 = nn.Linear(d_ff, d_model)
self.dropout = nn.Dropout(0.1)
def forward(self, x):
return self.w_2(self.dropout(torch.relu(self.w_1(x))))
class TransformerDecoderBlockNew(nn.Module):
def __init__(self, d_model, n_heads, d_ff, dropout_proba):
super(TransformerDecoderBlockNew, self).__init__()
self.W_q_1 = nn.Linear(d_model, d_model)
self.W_k_1 = nn.Linear(d_model, d_model)
self.W_v_1 = nn.Linear(d_model, d_model)
self.mha_layer_1 = MultiHeadAttention(d_model, n_heads)
self.dropout_layer_1 = nn.Dropout(dropout_proba)
self.add_and_norm_1 = AddAndNorm(d_model)
self.W_q_2 = nn.Linear(d_model, d_model)
self.W_k_2 = nn.Linear(d_model, d_model)
self.W_v_2 = nn.Linear(d_model, d_model)
self.mha_layer_2 = MultiHeadAttention(d_model, n_heads)
self.dropout_layer_2 = nn.Dropout(dropout_proba)
self.add_and_norm_2 = AddAndNorm(d_model)
self.ffn_layer = PositionWiseFeedForwardNet(d_model, d_ff)
self.dropout_layer_3 = nn.Dropout(dropout_proba)
self.add_and_norm_3 = AddAndNorm(d_model)
def forward(self, input_0, input_1, input_2, input_3):
primals_1 = self.W_q_1.weight
primals_2 = self.W_q_1.bias
primals_4 = self.W_k_1.weight
primals_5 = self.W_k_1.bias
primals_6 = self.W_v_1.weight
primals_7 = self.W_v_1.bias
primals_9 = self.mha_layer_1.W_0.weight
primals_10 = self.mha_layer_1.W_0.bias
primals_11 = self.add_and_norm_1.layer_norm.weight
primals_12 = self.add_and_norm_1.layer_norm.bias
primals_13 = self.W_q_2.weight
primals_14 = self.W_q_2.bias
primals_15 = self.W_k_2.weight
primals_16 = self.W_k_2.bias
primals_18 = self.W_v_2.weight
primals_19 = self.W_v_2.bias
primals_21 = self.mha_layer_2.W_0.weight
primals_22 = self.mha_layer_2.W_0.bias
primals_23 = self.add_and_norm_2.layer_norm.weight
primals_24 = self.add_and_norm_2.layer_norm.bias
primals_25 = self.ffn_layer.w_1.weight
primals_26 = self.ffn_layer.w_1.bias
primals_27 = self.ffn_layer.w_2.weight
primals_28 = self.ffn_layer.w_2.bias
primals_29 = self.add_and_norm_3.layer_norm.weight
primals_30 = self.add_and_norm_3.layer_norm.bias
primals_3 = input_0
primals_8 = input_1
primals_17 = input_2
primals_20 = input_3
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11, primals_12, primals_13, primals_14,
primals_15, primals_16, primals_17, primals_18, primals_19,
primals_20, primals_21, primals_22, primals_23, primals_24,
primals_25, primals_26, primals_27, primals_28, primals_29,
primals_30])
return output[0]
|
francismontalbo/attention-is-all-you-need-paper
|
TransformerDecoderBlock
| false
| 15,408
|
[
"MIT"
] | 167
|
21ba3e48917da0c6808126d183bece6a9969cfd2
|
https://github.com/francismontalbo/attention-is-all-you-need-paper/tree/21ba3e48917da0c6808126d183bece6a9969cfd2
|
TransformerEncoderBlock
|
import math
import torch
import torch.nn as nn
class AddAndNorm(nn.Module):
def __init__(self, d_model):
super(AddAndNorm, self).__init__()
self.layer_norm = nn.LayerNorm(d_model)
def forward(self, x, residual):
return self.layer_norm(x + residual)
class ScaledDotProductAttention(nn.Module):
def __init__(self, d_head):
super(ScaledDotProductAttention, self).__init__()
self.d_head = d_head
self.attention_dropout = nn.Dropout(p=0.1)
def forward(self, q, k, v, mask=None):
attention_weights = torch.matmul(q, k.transpose(-2, -1))
scaled_attention_weights = attention_weights / math.sqrt(self.d_head)
if mask is not None:
scaled_attention_weights = scaled_attention_weights.masked_fill(
mask == 0, float('-inf'))
scaled_attention_weights = nn.functional.softmax(
scaled_attention_weights, dim=-1)
scaled_attention_weights = self.attention_dropout(
scaled_attention_weights)
weighted_v = torch.matmul(scaled_attention_weights, v)
return weighted_v
class MultiHeadAttention(nn.Module):
def __init__(self, d_model, n_heads):
super(MultiHeadAttention, self).__init__()
self.n_heads = n_heads
assert d_model % n_heads == 0
self.d_head = d_model // n_heads
self.dot_product_attention_layer = ScaledDotProductAttention(self.
d_head)
self.W_0 = nn.Linear(d_model, d_model)
def _split_into_heads(self, q, k, v):
q = q.view(q.size(0), q.size(1), self.n_heads, self.d_head)
k = k.view(k.size(0), k.size(1), self.n_heads, self.d_head)
v = v.view(v.size(0), v.size(1), self.n_heads, self.d_head)
q = q.transpose(1, 2)
k = k.transpose(1, 2)
v = v.transpose(1, 2)
return q, k, v
def _concatenate_heads(self, attention_output):
attention_output = attention_output.transpose(1, 2).contiguous()
attention_output = attention_output.view(attention_output.size(0),
attention_output.size(1), -1)
return attention_output
def forward(self, q, k, v, mask=None):
q, k, v = self._split_into_heads(q, k, v)
attention_output = self.dot_product_attention_layer(q, k, v, mask)
attention_output = self._concatenate_heads(attention_output)
attention_output = self.W_0(attention_output)
return attention_output
class PositionWiseFeedForwardNet(nn.Module):
def __init__(self, d_model, d_ff):
super(PositionWiseFeedForwardNet, self).__init__()
self.w_1 = nn.Linear(d_model, d_ff)
self.w_2 = nn.Linear(d_ff, d_model)
self.dropout = nn.Dropout(0.1)
def forward(self, x):
return self.w_2(self.dropout(torch.relu(self.w_1(x))))
class TransformerEncoderBlock(nn.Module):
def __init__(self, d_model, n_heads, d_ff, dropout_proba):
super(TransformerEncoderBlock, self).__init__()
self.W_q = nn.Linear(d_model, d_model)
self.W_k = nn.Linear(d_model, d_model)
self.W_v = nn.Linear(d_model, d_model)
self.mha_layer = MultiHeadAttention(d_model, n_heads)
self.dropout_layer_1 = nn.Dropout(dropout_proba)
self.add_and_norm_layer_1 = AddAndNorm(d_model)
self.ffn_layer = PositionWiseFeedForwardNet(d_model, d_ff)
self.dropout_layer_2 = nn.Dropout(dropout_proba)
self.add_and_norm_layer_2 = AddAndNorm(d_model)
def forward(self, x, mask):
q = self.W_q(x)
k = self.W_k(x)
v = self.W_v(x)
mha_out = self.mha_layer(q, k, v, mask)
mha_out = self.dropout_layer_1(mha_out)
mha_out = self.add_and_norm_layer_1(x, mha_out)
ffn_out = self.ffn_layer(mha_out)
ffn_out = self.dropout_layer_2(ffn_out)
ffn_out = self.add_and_norm_layer_2(mha_out, ffn_out)
return ffn_out
def get_inputs():
return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'d_model': 4, 'n_heads': 4, 'd_ff': 4, 'dropout_proba': 0.5}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
import math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_clone_0(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel,
YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 4
y1 = yindex // 4
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + (x2 + 4 * y3), tmp2, xmask & ymask)
@triton.jit
def triton_poi_fused_eq_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 = 0.0
tmp2 = tmp0 == tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused__softmax_div_masked_fill_2(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 % 16
x2 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last').to(tl
.int1)
tmp1 = tl.load(in_ptr1 + 4 * x2, xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
).to(tl.int1)
tmp7 = tl.load(in_ptr1 + (1 + 4 * x2), xmask, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
).to(tl.int1)
tmp12 = tl.load(in_ptr1 + (2 + 4 * x2), xmask, eviction_policy='evict_last'
)
tmp16 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
).to(tl.int1)
tmp17 = tl.load(in_ptr1 + (3 + 4 * x2), xmask, eviction_policy='evict_last'
)
tmp2 = 1.0
tmp3 = tmp1 * tmp2
tmp4 = float('-inf')
tmp5 = tl.where(tmp0, tmp4, tmp3)
tmp8 = tmp7 * tmp2
tmp9 = tl.where(tmp6, tmp4, tmp8)
tmp10 = triton_helpers.maximum(tmp5, tmp9)
tmp13 = tmp12 * tmp2
tmp14 = tl.where(tmp11, tmp4, tmp13)
tmp15 = triton_helpers.maximum(tmp10, tmp14)
tmp18 = tmp17 * tmp2
tmp19 = tl.where(tmp16, tmp4, tmp18)
tmp20 = triton_helpers.maximum(tmp15, tmp19)
tmp21 = tmp5 - tmp20
tmp22 = tl_math.exp(tmp21)
tmp23 = tmp9 - tmp20
tmp24 = tl_math.exp(tmp23)
tmp25 = tmp22 + tmp24
tmp26 = tmp14 - tmp20
tmp27 = tl_math.exp(tmp26)
tmp28 = tmp25 + tmp27
tmp29 = tmp19 - tmp20
tmp30 = tl_math.exp(tmp29)
tmp31 = tmp28 + tmp30
tl.store(out_ptr0 + x2, tmp20, xmask)
tl.store(out_ptr1 + x2, tmp31, xmask)
@triton.jit
def triton_poi_fused__softmax_div_masked_fill_3(in_out_ptr0, in_ptr0,
in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex % 64
x4 = xindex
x5 = xindex // 4
tmp0 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last').to(tl
.int1)
tmp1 = tl.load(in_out_ptr0 + x4, xmask)
tmp6 = tl.load(in_ptr1 + x5, xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr2 + x5, xmask, eviction_policy='evict_last')
tmp2 = 1.0
tmp3 = tmp1 * tmp2
tmp4 = float('-inf')
tmp5 = tl.where(tmp0, tmp4, tmp3)
tmp7 = tmp5 - tmp6
tmp8 = tl_math.exp(tmp7)
tmp10 = tmp8 / tmp9
tl.store(in_out_ptr0 + x4, tmp10, xmask)
@triton.jit
def triton_poi_fused_clone_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 4
y1 = yindex // 4
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_add_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_relu_threshold_backward_7(in_out_ptr0, in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 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_8(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_9(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_10(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, primals_14, primals_15, primals_16, primals_17, primals_18
) = 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, 1))
assert_size_stride(primals_7, (4,), (1,))
assert_size_stride(primals_8, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_9, (4, 4), (4, 1))
assert_size_stride(primals_10, (4,), (1,))
assert_size_stride(primals_11, (4,), (1,))
assert_size_stride(primals_12, (4,), (1,))
assert_size_stride(primals_13, (4, 4), (4, 1))
assert_size_stride(primals_14, (4,), (1,))
assert_size_stride(primals_15, (4, 4), (4, 1))
assert_size_stride(primals_16, (4,), (1,))
assert_size_stride(primals_17, (4,), (1,))
assert_size_stride(primals_18, (4,), (1,))
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_3, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1)
del primals_4
buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_3, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), out=buf2)
del primals_6
buf3 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(16, 4)](buf0, primals_2, buf3, 16, 4,
XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1)
del primals_2
buf4 = reinterpret_tensor(buf0, (4, 4, 1, 4), (16, 4, 4, 1), 0)
del buf0
triton_poi_fused_clone_0[grid(16, 4)](buf1, primals_5, buf4, 16, 4,
XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1)
del primals_5
buf5 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf3, (16, 4, 1), (4, 1, 0),
0), reinterpret_tensor(buf4, (16, 1, 4), (4, 0, 1), 0), out=buf5)
buf6 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
triton_poi_fused_eq_1[grid(64)](primals_8, buf6, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del primals_8
buf7 = reinterpret_tensor(buf1, (4, 4, 4, 1), (16, 4, 1, 64), 0)
del buf1
buf8 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
triton_poi_fused__softmax_div_masked_fill_2[grid(64)](buf6, buf5,
buf7, buf8, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf9 = reinterpret_tensor(buf5, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf5
triton_poi_fused__softmax_div_masked_fill_3[grid(256)](buf9, buf6,
buf7, buf8, 256, XBLOCK=128, num_warps=4, num_stages=1)
buf10 = reinterpret_tensor(buf8, (4, 4, 4, 1), (16, 4, 1, 1), 0)
del buf8
triton_poi_fused_clone_0[grid(16, 4)](buf2, primals_7, buf10, 16, 4,
XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1)
del primals_7
buf11 = reinterpret_tensor(buf2, (16, 4, 1), (4, 1, 1), 0)
del buf2
extern_kernels.bmm(reinterpret_tensor(buf9, (16, 4, 4), (16, 4, 1),
0), reinterpret_tensor(buf10, (16, 4, 1), (4, 1, 0), 0), out=buf11)
buf12 = reinterpret_tensor(buf7, (4, 4, 4, 1), (16, 4, 1, 1), 0)
del buf7
triton_poi_fused_clone_4[grid(16, 4)](buf11, buf12, 16, 4, XBLOCK=4,
YBLOCK=16, num_warps=1, num_stages=1)
buf13 = reinterpret_tensor(buf11, (16, 4), (4, 1), 0)
del buf11
extern_kernels.addmm(primals_10, reinterpret_tensor(buf12, (16, 4),
(4, 1), 0), reinterpret_tensor(primals_9, (4, 4), (1, 4), 0),
alpha=1, beta=1, out=buf13)
del primals_10
buf14 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
buf15 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
triton_poi_fused_add_native_layer_norm_5[grid(16)](primals_3, buf13,
buf14, buf15, 16, XBLOCK=16, num_warps=1, num_stages=1)
buf16 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_native_layer_norm_6[grid(64)](primals_3, buf13,
buf14, buf15, primals_11, primals_12, buf16, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del primals_12
buf17 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf16, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_13, (4, 4), (1, 4), 0), out=buf17)
buf18 = reinterpret_tensor(buf17, (4, 4, 4), (16, 4, 1), 0)
del buf17
buf24 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_7[grid(64)](buf18,
primals_14, buf24, 64, XBLOCK=64, num_warps=1, num_stages=1)
del primals_14
buf19 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf18, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_15, (4, 4), (1, 4), 0), out=buf19)
buf20 = reinterpret_tensor(buf19, (4, 4, 4), (16, 4, 1), 0)
del buf19
triton_poi_fused_add_8[grid(64)](buf20, buf16, primals_16, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del primals_16
buf21 = buf15
del buf15
buf22 = buf14
del buf14
triton_poi_fused_native_layer_norm_9[grid(16)](buf20, buf21, buf22,
16, XBLOCK=16, num_warps=1, num_stages=1)
buf23 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_native_layer_norm_10[grid(64)](buf20, buf21, buf22,
primals_17, primals_18, buf23, 64, XBLOCK=64, num_warps=1,
num_stages=1)
del buf21
del buf22
del primals_18
return (buf23, primals_3, primals_11, primals_17, buf6, buf9,
reinterpret_tensor(buf12, (16, 4), (4, 1), 0), buf13,
reinterpret_tensor(buf16, (16, 4), (4, 1), 0), reinterpret_tensor(
buf18, (16, 4), (4, 1), 0), buf20, primals_15, buf24, primals_13,
primals_9, reinterpret_tensor(buf10, (16, 1, 4), (4, 1, 1), 0),
reinterpret_tensor(buf3, (16, 1, 4), (4, 1, 1), 0),
reinterpret_tensor(buf4, (16, 4, 1), (4, 1, 4), 0))
class AddAndNorm(nn.Module):
def __init__(self, d_model):
super(AddAndNorm, self).__init__()
self.layer_norm = nn.LayerNorm(d_model)
def forward(self, x, residual):
return self.layer_norm(x + residual)
class ScaledDotProductAttention(nn.Module):
def __init__(self, d_head):
super(ScaledDotProductAttention, self).__init__()
self.d_head = d_head
self.attention_dropout = nn.Dropout(p=0.1)
def forward(self, q, k, v, mask=None):
attention_weights = torch.matmul(q, k.transpose(-2, -1))
scaled_attention_weights = attention_weights / math.sqrt(self.d_head)
if mask is not None:
scaled_attention_weights = scaled_attention_weights.masked_fill(
mask == 0, float('-inf'))
scaled_attention_weights = nn.functional.softmax(
scaled_attention_weights, dim=-1)
scaled_attention_weights = self.attention_dropout(
scaled_attention_weights)
weighted_v = torch.matmul(scaled_attention_weights, v)
return weighted_v
class MultiHeadAttention(nn.Module):
def __init__(self, d_model, n_heads):
super(MultiHeadAttention, self).__init__()
self.n_heads = n_heads
assert d_model % n_heads == 0
self.d_head = d_model // n_heads
self.dot_product_attention_layer = ScaledDotProductAttention(self.
d_head)
self.W_0 = nn.Linear(d_model, d_model)
def _split_into_heads(self, q, k, v):
q = q.view(q.size(0), q.size(1), self.n_heads, self.d_head)
k = k.view(k.size(0), k.size(1), self.n_heads, self.d_head)
v = v.view(v.size(0), v.size(1), self.n_heads, self.d_head)
q = q.transpose(1, 2)
k = k.transpose(1, 2)
v = v.transpose(1, 2)
return q, k, v
def _concatenate_heads(self, attention_output):
attention_output = attention_output.transpose(1, 2).contiguous()
attention_output = attention_output.view(attention_output.size(0),
attention_output.size(1), -1)
return attention_output
def forward(self, q, k, v, mask=None):
q, k, v = self._split_into_heads(q, k, v)
attention_output = self.dot_product_attention_layer(q, k, v, mask)
attention_output = self._concatenate_heads(attention_output)
attention_output = self.W_0(attention_output)
return attention_output
class PositionWiseFeedForwardNet(nn.Module):
def __init__(self, d_model, d_ff):
super(PositionWiseFeedForwardNet, self).__init__()
self.w_1 = nn.Linear(d_model, d_ff)
self.w_2 = nn.Linear(d_ff, d_model)
self.dropout = nn.Dropout(0.1)
def forward(self, x):
return self.w_2(self.dropout(torch.relu(self.w_1(x))))
class TransformerEncoderBlockNew(nn.Module):
def __init__(self, d_model, n_heads, d_ff, dropout_proba):
super(TransformerEncoderBlockNew, self).__init__()
self.W_q = nn.Linear(d_model, d_model)
self.W_k = nn.Linear(d_model, d_model)
self.W_v = nn.Linear(d_model, d_model)
self.mha_layer = MultiHeadAttention(d_model, n_heads)
self.dropout_layer_1 = nn.Dropout(dropout_proba)
self.add_and_norm_layer_1 = AddAndNorm(d_model)
self.ffn_layer = PositionWiseFeedForwardNet(d_model, d_ff)
self.dropout_layer_2 = nn.Dropout(dropout_proba)
self.add_and_norm_layer_2 = AddAndNorm(d_model)
def forward(self, input_0, input_1):
primals_1 = self.W_q.weight
primals_2 = self.W_q.bias
primals_4 = self.W_k.weight
primals_5 = self.W_k.bias
primals_6 = self.W_v.weight
primals_7 = self.W_v.bias
primals_9 = self.mha_layer.W_0.weight
primals_10 = self.mha_layer.W_0.bias
primals_11 = self.add_and_norm_layer_1.layer_norm.weight
primals_12 = self.add_and_norm_layer_1.layer_norm.bias
primals_13 = self.ffn_layer.w_1.weight
primals_14 = self.ffn_layer.w_1.bias
primals_15 = self.ffn_layer.w_2.weight
primals_16 = self.ffn_layer.w_2.bias
primals_17 = self.add_and_norm_layer_2.layer_norm.weight
primals_18 = self.add_and_norm_layer_2.layer_norm.bias
primals_3 = input_0
primals_8 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11, primals_12, primals_13, primals_14,
primals_15, primals_16, primals_17, primals_18])
return output[0]
|
francismontalbo/attention-is-all-you-need-paper
|
TransformerEncoderBlock
| false
| 15,409
|
[
"MIT"
] | 167
|
21ba3e48917da0c6808126d183bece6a9969cfd2
|
https://github.com/francismontalbo/attention-is-all-you-need-paper/tree/21ba3e48917da0c6808126d183bece6a9969cfd2
|
Attn
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class Attn(nn.Module):
""" The score function for the attention mechanism.
We define the score function as the general function from Luong et al.
Where score(s_{i}, h_{j}) = s_{i} * W * h_{j}
"""
def __init__(self, hidden_size):
super(Attn, self).__init__()
self.hidden_size = hidden_size
self.attn = nn.Linear(self.hidden_size, self.hidden_size)
def forward(self, hidden, encoder_outputs):
_batch_size, seq_len, _hidden_size = encoder_outputs.size()
hidden = hidden.unsqueeze(1)
hiddens = hidden.repeat(1, seq_len, 1)
attn_energies = self.score(hiddens, encoder_outputs)
return F.softmax(attn_energies, dim=1).unsqueeze(1)
def score(self, hidden, encoder_outputs):
energy = self.attn(encoder_outputs)
hidden = hidden.unsqueeze(2)
energy = energy.unsqueeze(3)
energy = torch.matmul(hidden, energy)
return energy.squeeze(3).squeeze(2)
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'hidden_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import 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_repeat_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 % 4
x2 = xindex // 16
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2), xmask, eviction_policy='evict_last'
)
tl.store(out_ptr0 + x3, tmp0, xmask)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x2, tmp9, xmask)
@triton.jit
def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4, 4), (4, 1))
assert_size_stride(primals_4, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_4, reinterpret_tensor(primals_1, (16,
4), (4, 1), 0), reinterpret_tensor(primals_3, (4, 4), (1, 4), 0
), alpha=1, beta=1, out=buf0)
del primals_3
del primals_4
buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_repeat_0[grid(64)](primals_2, buf1, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del primals_2
buf2 = empty_strided_cuda((16, 1, 1), (1, 1, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf1, (16, 1, 4), (4, 0, 1),
0), reinterpret_tensor(buf0, (16, 4, 1), (4, 1, 1), 0), out=buf2)
del buf0
buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused__softmax_1[grid(16)](buf2, buf3, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf4 = reinterpret_tensor(buf2, (4, 4), (4, 1), 0)
del buf2
triton_poi_fused__softmax_2[grid(16)](buf3, buf4, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del buf3
return reinterpret_tensor(buf4, (4, 1, 4), (4, 4, 1), 0
), reinterpret_tensor(primals_1, (16, 4), (4, 1), 0
), buf4, reinterpret_tensor(buf1, (16, 4, 1), (4, 1, 4), 0)
class AttnNew(nn.Module):
""" The score function for the attention mechanism.
We define the score function as the general function from Luong et al.
Where score(s_{i}, h_{j}) = s_{i} * W * h_{j}
"""
def __init__(self, hidden_size):
super(AttnNew, self).__init__()
self.hidden_size = hidden_size
self.attn = nn.Linear(self.hidden_size, self.hidden_size)
def score(self, hidden, encoder_outputs):
energy = self.attn(encoder_outputs)
hidden = hidden.unsqueeze(2)
energy = energy.unsqueeze(3)
energy = torch.matmul(hidden, energy)
return energy.squeeze(3).squeeze(2)
def forward(self, input_0, input_1):
primals_2 = self.attn.weight
primals_4 = self.attn.bias
primals_3 = input_0
primals_1 = input_1
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
gau820827/AI-writer_Data2Doc
|
Attn
| false
| 15,410
|
[
"Apache-2.0"
] | 77
|
6be0ee6238158a47aa0fdfa8a34df2a47714835a
|
https://github.com/gau820827/AI-writer_Data2Doc/tree/6be0ee6238158a47aa0fdfa8a34df2a47714835a
|
AP
|
import torch
import torch.nn as nn
class AttentivePooling(nn.Module):
"""
Implementation of Attentive Pooling
"""
def __init__(self, input_dim, **kwargs):
super(AttentivePooling, self).__init__()
self.W_a = nn.Linear(input_dim, input_dim)
self.W = nn.Linear(input_dim, 1)
self.act_fn = nn.ReLU()
self.softmax = nn.functional.softmax
def forward(self, batch_rep, att_mask):
"""
input:
batch_rep : size (B, T, H), B: batch size, T: sequence length, H: Hidden dimension
attention_weight:
att_w : size (B, T, 1)
return:
utter_rep: size (B, H)
"""
att_logits = self.W(self.act_fn(self.W_a(batch_rep))).squeeze(-1)
att_logits = att_mask + att_logits
att_w = self.softmax(att_logits, dim=-1).unsqueeze(-1)
utter_rep = torch.sum(batch_rep * att_w, dim=1)
return utter_rep, att_w
class AP(nn.Module):
""" Attentive Pooling module incoporate attention mask"""
def __init__(self, out_dim, input_dim):
super(AP, self).__init__()
self.linear = nn.Linear(input_dim, out_dim)
self.sap_layer = AttentivePooling(out_dim)
self.act_fn = nn.ReLU()
def forward(self, feature_BxTxH, att_mask_BxT):
"""
Arguments
feature_BxTxH - [BxTxH] Acoustic feature with shape
att_mask_BxT - [BxT] Attention Mask logits
"""
feature_BxTxH = self.linear(feature_BxTxH)
sap_vec, _ = self.sap_layer(feature_BxTxH, att_mask_BxT)
return sap_vec
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'out_dim': 4, '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_relu_threshold_backward_0(in_out_ptr0, in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x2, tmp4, xmask)
tl.store(out_ptr0 + x2, tmp6, xmask)
@triton.jit
def triton_poi_fused__softmax_add_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
x2 = xindex
x0 = xindex % 16
tmp0 = tl.load(in_ptr0 + 4 * x2, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (1 + 4 * x2), 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 * x2), 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 * x2), 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 = 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
tl.store(out_ptr0 + x2, tmp14, xmask)
tl.store(out_ptr1 + x2, tmp25, xmask)
@triton.jit
def triton_poi_fused_mul_sum_2(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 % 64
x3 = xindex // 64
x5 = xindex // 4 % 16
x2 = xindex // 16 % 4
x7 = xindex
tmp0 = tl.load(in_ptr0 + x4, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + (x5 + 64 * x3), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr2 + x5, xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr3 + (x2 + 16 * x3), xmask, eviction_policy=
'evict_last')
tmp7 = tl.load(in_ptr4 + (x2 + 16 * x3), xmask, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr0 + (64 + x4), xmask, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr1 + (16 + x5 + 64 * x3), xmask, eviction_policy=
'evict_last')
tmp12 = tl.load(in_ptr2 + (16 + x5), xmask, eviction_policy='evict_last')
tmp14 = tl.load(in_ptr3 + (4 + x2 + 16 * x3), xmask, eviction_policy=
'evict_last')
tmp17 = tl.load(in_ptr4 + (4 + x2 + 16 * x3), xmask, eviction_policy=
'evict_last')
tmp21 = tl.load(in_ptr0 + (128 + x4), xmask, eviction_policy='evict_last')
tmp22 = tl.load(in_ptr1 + (32 + x5 + 64 * x3), xmask, eviction_policy=
'evict_last')
tmp23 = tl.load(in_ptr2 + (32 + x5), xmask, eviction_policy='evict_last')
tmp25 = tl.load(in_ptr3 + (8 + x2 + 16 * x3), xmask, eviction_policy=
'evict_last')
tmp28 = tl.load(in_ptr4 + (8 + x2 + 16 * x3), xmask, eviction_policy=
'evict_last')
tmp32 = tl.load(in_ptr0 + (192 + x4), xmask, eviction_policy='evict_last')
tmp33 = tl.load(in_ptr1 + (48 + x5 + 64 * x3), xmask, eviction_policy=
'evict_last')
tmp34 = tl.load(in_ptr2 + (48 + x5), xmask, eviction_policy='evict_last')
tmp36 = tl.load(in_ptr3 + (12 + x2 + 16 * x3), xmask, eviction_policy=
'evict_last')
tmp39 = tl.load(in_ptr4 + (12 + x2 + 16 * x3), xmask, eviction_policy=
'evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 - tmp4
tmp6 = tl_math.exp(tmp5)
tmp8 = tmp6 / tmp7
tmp9 = tmp0 * tmp8
tmp13 = tmp11 + tmp12
tmp15 = tmp13 - tmp14
tmp16 = tl_math.exp(tmp15)
tmp18 = tmp16 / tmp17
tmp19 = tmp10 * tmp18
tmp20 = tmp9 + tmp19
tmp24 = tmp22 + tmp23
tmp26 = tmp24 - tmp25
tmp27 = tl_math.exp(tmp26)
tmp29 = tmp27 / tmp28
tmp30 = tmp21 * tmp29
tmp31 = tmp20 + tmp30
tmp35 = tmp33 + tmp34
tmp37 = tmp35 - tmp36
tmp38 = tl_math.exp(tmp37)
tmp40 = tmp38 / tmp39
tmp41 = tmp32 * tmp40
tmp42 = tmp31 + tmp41
tl.store(out_ptr0 + x7, tmp42, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8) = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (1, 4), (4, 1))
assert_size_stride(primals_7, (1,), (1,))
assert_size_stride(primals_8, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64,
4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0
), alpha=1, beta=1, out=buf0)
del primals_1
del primals_2
buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(buf0, reinterpret_tensor(primals_4, (4, 4), (1, 4
), 0), out=buf1)
buf2 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf1
buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
get_raw_stream(0)
triton_poi_fused_relu_threshold_backward_0[grid(256)](buf2,
primals_5, buf8, 256, XBLOCK=256, num_warps=4, num_stages=1)
del primals_5
buf4 = empty_strided_cuda((64, 1), (1, 1), torch.float32)
extern_kernels.addmm(primals_7, reinterpret_tensor(buf2, (64, 4), (
4, 1), 0), reinterpret_tensor(primals_6, (4, 1), (1, 4), 0),
alpha=1, beta=1, out=buf4)
del primals_7
buf5 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
buf6 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
triton_poi_fused__softmax_add_1[grid(64)](primals_8, buf4, 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_mul_sum_2[grid(256)](buf0, primals_8, buf4, buf5,
buf6, buf7, 256, XBLOCK=128, num_warps=4, num_stages=1)
del buf5
del buf6
return buf7, primals_8, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), buf0, reinterpret_tensor(buf2, (64, 4), (4, 1), 0
), buf4, primals_6, buf8, primals_4
class AttentivePooling(nn.Module):
"""
Implementation of Attentive Pooling
"""
def __init__(self, input_dim, **kwargs):
super(AttentivePooling, self).__init__()
self.W_a = nn.Linear(input_dim, input_dim)
self.W = nn.Linear(input_dim, 1)
self.act_fn = nn.ReLU()
self.softmax = nn.functional.softmax
def forward(self, batch_rep, att_mask):
"""
input:
batch_rep : size (B, T, H), B: batch size, T: sequence length, H: Hidden dimension
attention_weight:
att_w : size (B, T, 1)
return:
utter_rep: size (B, H)
"""
att_logits = self.W(self.act_fn(self.W_a(batch_rep))).squeeze(-1)
att_logits = att_mask + att_logits
att_w = self.softmax(att_logits, dim=-1).unsqueeze(-1)
utter_rep = torch.sum(batch_rep * att_w, dim=1)
return utter_rep, att_w
class APNew(nn.Module):
""" Attentive Pooling module incoporate attention mask"""
def __init__(self, out_dim, input_dim):
super(APNew, self).__init__()
self.linear = nn.Linear(input_dim, out_dim)
self.sap_layer = AttentivePooling(out_dim)
self.act_fn = nn.ReLU()
def forward(self, input_0, input_1):
primals_1 = self.linear.weight
primals_2 = self.linear.bias
primals_4 = self.sap_layer.W_a.weight
primals_5 = self.sap_layer.W_a.bias
primals_6 = self.sap_layer.W.weight
primals_7 = self.sap_layer.W.bias
primals_3 = input_0
primals_8 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8])
return output[0]
|
gcambara/s3prl
|
AP
| false
| 15,411
|
[
"MIT"
] | 856
|
33284ebde3a903ed8604d6dae85669d0174ae1d3
|
https://github.com/gcambara/s3prl/tree/33284ebde3a903ed8604d6dae85669d0174ae1d3
|
AttentivePoolingModule
|
import torch
import torch.nn as nn
class AttentivePoolingModule(nn.Module):
"""
Implementation of Attentive Pooling
"""
def __init__(self, input_dim, activation='ReLU', **kwargs):
super(AttentivePoolingModule, self).__init__()
self.W_a = nn.Linear(input_dim, input_dim)
self.W = nn.Linear(input_dim, 1)
self.act_fn = getattr(nn, activation)()
self.softmax = nn.functional.softmax
def forward(self, batch_rep, att_mask):
"""
input:
batch_rep : size (B, T, H), B: batch size, T: sequence length, H: Hidden dimension
attention_weight:
att_w : size (B, T, 1)
return:
utter_rep: size (B, H)
"""
att_logits = self.W(self.act_fn(self.W_a(batch_rep))).squeeze(-1)
att_logits = att_mask + att_logits
att_w = self.softmax(att_logits, dim=-1).unsqueeze(-1)
utter_rep = torch.sum(batch_rep * att_w, dim=1)
return utter_rep, att_w
def get_inputs():
return [torch.rand([4, 4, 4, 4]), 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_relu_threshold_backward_0(in_out_ptr0, in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x2, tmp4, xmask)
tl.store(out_ptr0 + x2, tmp6, xmask)
@triton.jit
def triton_poi_fused__softmax_add_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 16
tmp0 = tl.load(in_ptr0 + 4 * x2, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr2 + 0)
tmp3 = tl.broadcast_to(tmp2, [XBLOCK])
tmp6 = tl.load(in_ptr0 + (1 + 4 * x2), xmask, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr0 + (2 + 4 * x2), xmask, eviction_policy='evict_last'
)
tmp12 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp16 = tl.load(in_ptr0 + (3 + 4 * x2), xmask, eviction_policy='evict_last'
)
tmp17 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp4 = tmp1 + tmp3
tmp5 = tmp0 + tmp4
tmp8 = tmp7 + tmp3
tmp9 = tmp6 + tmp8
tmp10 = triton_helpers.maximum(tmp5, tmp9)
tmp13 = tmp12 + tmp3
tmp14 = tmp11 + tmp13
tmp15 = triton_helpers.maximum(tmp10, tmp14)
tmp18 = tmp17 + tmp3
tmp19 = tmp16 + tmp18
tmp20 = triton_helpers.maximum(tmp15, tmp19)
tmp21 = tmp5 - tmp20
tmp22 = tl_math.exp(tmp21)
tmp23 = tmp9 - tmp20
tmp24 = tl_math.exp(tmp23)
tmp25 = tmp22 + tmp24
tmp26 = tmp14 - tmp20
tmp27 = tl_math.exp(tmp26)
tmp28 = tmp25 + tmp27
tmp29 = tmp19 - tmp20
tmp30 = tl_math.exp(tmp29)
tmp31 = tmp28 + tmp30
tl.store(out_ptr0 + x2, tmp20, xmask)
tl.store(out_ptr1 + x2, tmp31, xmask)
@triton.jit
def triton_poi_fused__softmax_add_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x4 = xindex % 64
x5 = xindex // 4
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + x4, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr2 + 0)
tmp3 = tl.broadcast_to(tmp2, [XBLOCK])
tmp6 = tl.load(in_ptr3 + x5, xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr4 + x5, xmask, eviction_policy='evict_last')
tmp4 = tmp1 + tmp3
tmp5 = tmp0 + tmp4
tmp7 = tmp5 - tmp6
tmp8 = tl_math.exp(tmp7)
tmp10 = tmp8 / tmp9
tl.store(out_ptr0 + x3, tmp10, xmask)
@triton.jit
def triton_poi_fused_mul_sum_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex % 64
x1 = xindex // 4 % 16
x2 = xindex // 64
x4 = xindex
tmp0 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + (x1 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (64 + x3), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr1 + (16 + x1 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp7 = tl.load(in_ptr0 + (128 + x3), xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr1 + (32 + x1 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp11 = tl.load(in_ptr0 + (192 + x3), xmask, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr1 + (48 + x1 + 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
tl.store(out_ptr0 + x4, tmp14, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (1, 4), (4, 1))
assert_size_stride(primals_5, (1,), (1,))
assert_size_stride(primals_6, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0)
del primals_1
buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf0
buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
get_raw_stream(0)
triton_poi_fused_relu_threshold_backward_0[grid(256)](buf1,
primals_2, buf7, 256, XBLOCK=256, num_warps=4, num_stages=1)
del primals_2
buf2 = empty_strided_cuda((64, 1), (1, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf1, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_4, (4, 1), (1, 4), 0), out=buf2)
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__softmax_add_1[grid(64)](primals_6, buf2,
primals_5, buf3, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__softmax_add_2[grid(256)](primals_6, buf2,
primals_5, buf3, buf4, buf5, 256, XBLOCK=256, num_warps=4,
num_stages=1)
del buf2
del buf3
del buf4
del primals_5
del primals_6
buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_mul_sum_3[grid(256)](primals_3, buf5, buf6, 256,
XBLOCK=256, num_warps=4, num_stages=1)
return buf6, reinterpret_tensor(buf5, (4, 4, 4, 4, 1), (64, 16, 4, 1, 1), 0
), primals_3, reinterpret_tensor(buf1, (64, 4), (4, 1), 0
), buf5, primals_4, buf7
class AttentivePoolingModuleNew(nn.Module):
"""
Implementation of Attentive Pooling
"""
def __init__(self, input_dim, activation='ReLU', **kwargs):
super(AttentivePoolingModuleNew, self).__init__()
self.W_a = nn.Linear(input_dim, input_dim)
self.W = nn.Linear(input_dim, 1)
self.act_fn = getattr(nn, activation)()
self.softmax = nn.functional.softmax
def forward(self, input_0, input_1):
primals_1 = self.W_a.weight
primals_2 = self.W_a.bias
primals_4 = self.W.weight
primals_5 = self.W.bias
primals_3 = input_0
primals_6 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6])
return output[0], output[1]
|
gcambara/s3prl
|
AttentivePoolingModule
| false
| 15,412
|
[
"MIT"
] | 856
|
33284ebde3a903ed8604d6dae85669d0174ae1d3
|
https://github.com/gcambara/s3prl/tree/33284ebde3a903ed8604d6dae85669d0174ae1d3
|
ASP
|
import torch
import torch.nn as nn
class AttentivePooling(nn.Module):
"""
Implementation of Attentive Pooling
"""
def __init__(self, input_dim, **kwargs):
super(AttentivePooling, self).__init__()
self.W_a = nn.Linear(input_dim, input_dim)
self.W = nn.Linear(input_dim, 1)
self.act_fn = nn.ReLU()
self.softmax = nn.functional.softmax
def forward(self, batch_rep, att_mask):
"""
input:
batch_rep : size (B, T, H), B: batch size, T: sequence length, H: Hidden dimension
attention_weight:
att_w : size (B, T, 1)
return:
utter_rep: size (B, H)
"""
att_logits = self.W(self.act_fn(self.W_a(batch_rep))).squeeze(-1)
att_logits = att_mask + att_logits
att_w = self.softmax(att_logits, dim=-1).unsqueeze(-1)
utter_rep = torch.sum(batch_rep * att_w, dim=1)
return utter_rep, att_w
class ASP(nn.Module):
""" Attentive Statistic Pooling module incoporate attention mask"""
def __init__(self, out_dim, input_dim):
super(ASP, self).__init__()
self.linear = nn.Linear(input_dim, out_dim)
self.ap_layer = AttentivePooling(out_dim)
def forward(self, feature_BxTxH, att_mask_BxT):
"""
Arguments
feature_BxTxH - [BxTxH] Acoustic feature with shape
att_mask_BxT - [BxT] Attention Mask logits
"""
feature_BxTxH = self.linear(feature_BxTxH)
sap_vec, att_w = self.ap_layer(feature_BxTxH, att_mask_BxT)
variance = torch.sqrt(torch.sum(att_w * feature_BxTxH *
feature_BxTxH, dim=1) - sap_vec ** 2 + 1e-08)
statistic_pooling = torch.cat([sap_vec, variance], dim=-1)
return statistic_pooling
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'out_dim': 4, '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 libdevice, math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x2, tmp4, xmask)
tl.store(out_ptr0 + x2, tmp6, xmask)
@triton.jit
def triton_poi_fused__softmax_add_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
x2 = xindex
x0 = xindex % 16
tmp0 = tl.load(in_ptr0 + 4 * x2, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (1 + 4 * x2), 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 * x2), 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 * x2), 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 = 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
tl.store(out_ptr0 + x2, tmp14, xmask)
tl.store(out_ptr1 + x2, tmp25, xmask)
@triton.jit
def triton_poi_fused_mul_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x4 = xindex // 4
x5 = xindex // 4 % 64
x7 = xindex // 16
x8 = xindex % 256
x9 = xindex
tmp0 = tl.load(in_ptr0 + x4, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + x5, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + x7, xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr3 + x7, xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr4 + x8, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp4 = tmp2 - tmp3
tmp5 = tl_math.exp(tmp4)
tmp7 = tmp5 / tmp6
tmp9 = tmp7 * tmp8
tl.store(out_ptr0 + x9, tmp9, xmask)
@triton.jit
def triton_poi_fused_add_mul_pow_sqrt_sub_sum_3(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, in_ptr4, in_ptr5, out_ptr0, out_ptr2, out_ptr3, out_ptr4,
xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x6 = xindex % 64
x3 = xindex // 64
x4 = xindex // 4 % 16
x2 = xindex // 16 % 4
x0 = xindex % 4
x5 = xindex // 4
x8 = xindex
tmp0 = tl.load(in_ptr0 + x6, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + (x4 + 64 * x3), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr2 + x4, xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr3 + (x2 + 16 * x3), xmask, eviction_policy=
'evict_last')
tmp7 = tl.load(in_ptr4 + (x2 + 16 * x3), xmask, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr0 + (64 + x6), xmask, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr1 + (16 + x4 + 64 * x3), xmask, eviction_policy=
'evict_last')
tmp12 = tl.load(in_ptr2 + (16 + x4), xmask, eviction_policy='evict_last')
tmp14 = tl.load(in_ptr3 + (4 + x2 + 16 * x3), xmask, eviction_policy=
'evict_last')
tmp17 = tl.load(in_ptr4 + (4 + x2 + 16 * x3), xmask, eviction_policy=
'evict_last')
tmp21 = tl.load(in_ptr0 + (128 + x6), xmask, eviction_policy='evict_last')
tmp22 = tl.load(in_ptr1 + (32 + x4 + 64 * x3), xmask, eviction_policy=
'evict_last')
tmp23 = tl.load(in_ptr2 + (32 + x4), xmask, eviction_policy='evict_last')
tmp25 = tl.load(in_ptr3 + (8 + x2 + 16 * x3), xmask, eviction_policy=
'evict_last')
tmp28 = tl.load(in_ptr4 + (8 + x2 + 16 * x3), xmask, eviction_policy=
'evict_last')
tmp32 = tl.load(in_ptr0 + (192 + x6), xmask, eviction_policy='evict_last')
tmp33 = tl.load(in_ptr1 + (48 + x4 + 64 * x3), xmask, eviction_policy=
'evict_last')
tmp34 = tl.load(in_ptr2 + (48 + x4), xmask, eviction_policy='evict_last')
tmp36 = tl.load(in_ptr3 + (12 + x2 + 16 * x3), xmask, eviction_policy=
'evict_last')
tmp39 = tl.load(in_ptr4 + (12 + x2 + 16 * x3), xmask, eviction_policy=
'evict_last')
tmp43 = tl.load(in_ptr5 + (x6 + 256 * x3), xmask)
tmp45 = tl.load(in_ptr5 + (64 + x6 + 256 * x3), xmask)
tmp48 = tl.load(in_ptr5 + (128 + x6 + 256 * x3), xmask)
tmp51 = tl.load(in_ptr5 + (192 + x6 + 256 * x3), xmask)
tmp3 = tmp1 + tmp2
tmp5 = tmp3 - tmp4
tmp6 = tl_math.exp(tmp5)
tmp8 = tmp6 / tmp7
tmp9 = tmp0 * tmp8
tmp13 = tmp11 + tmp12
tmp15 = tmp13 - tmp14
tmp16 = tl_math.exp(tmp15)
tmp18 = tmp16 / tmp17
tmp19 = tmp10 * tmp18
tmp20 = tmp9 + tmp19
tmp24 = tmp22 + tmp23
tmp26 = tmp24 - tmp25
tmp27 = tl_math.exp(tmp26)
tmp29 = tmp27 / tmp28
tmp30 = tmp21 * tmp29
tmp31 = tmp20 + tmp30
tmp35 = tmp33 + tmp34
tmp37 = tmp35 - tmp36
tmp38 = tl_math.exp(tmp37)
tmp40 = tmp38 / tmp39
tmp41 = tmp32 * tmp40
tmp42 = tmp31 + tmp41
tmp44 = tmp43 * tmp0
tmp46 = tmp45 * tmp10
tmp47 = tmp44 + tmp46
tmp49 = tmp48 * tmp21
tmp50 = tmp47 + tmp49
tmp52 = tmp51 * tmp32
tmp53 = tmp50 + tmp52
tmp54 = tmp42 * tmp42
tmp55 = tmp53 - tmp54
tmp56 = 1e-08
tmp57 = tmp55 + tmp56
tmp58 = libdevice.sqrt(tmp57)
tmp59 = 2.0
tmp60 = tmp58 * tmp59
tmp61 = tmp42 * tmp59
tl.store(out_ptr0 + (x0 + 8 * x5), tmp42, xmask)
tl.store(out_ptr2 + (x0 + 8 * x5), tmp58, xmask)
tl.store(out_ptr3 + x8, tmp60, xmask)
tl.store(out_ptr4 + x8, tmp61, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8) = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (1, 4), (4, 1))
assert_size_stride(primals_7, (1,), (1,))
assert_size_stride(primals_8, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64,
4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0
), alpha=1, beta=1, out=buf0)
del primals_1
del primals_2
buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(buf0, reinterpret_tensor(primals_4, (4, 4), (1, 4
), 0), out=buf1)
buf2 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf1
buf14 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
get_raw_stream(0)
triton_poi_fused_relu_threshold_backward_0[grid(256)](buf2,
primals_5, buf14, 256, XBLOCK=256, num_warps=4, num_stages=1)
del primals_5
buf4 = empty_strided_cuda((64, 1), (1, 1), torch.float32)
extern_kernels.addmm(primals_7, reinterpret_tensor(buf2, (64, 4), (
4, 1), 0), reinterpret_tensor(primals_6, (4, 1), (1, 4), 0),
alpha=1, beta=1, out=buf4)
del primals_7
buf5 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
buf6 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
triton_poi_fused__softmax_add_1[grid(64)](primals_8, buf4, buf5,
buf6, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf8 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1),
torch.float32)
triton_poi_fused_mul_2[grid(1024)](primals_8, buf4, buf5, buf6,
buf0, buf8, 1024, XBLOCK=256, num_warps=4, num_stages=1)
buf11 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.float32
)
buf7 = reinterpret_tensor(buf11, (4, 4, 4, 4), (128, 32, 8, 1), 0)
buf10 = reinterpret_tensor(buf11, (4, 4, 4, 4), (128, 32, 8, 1), 4)
buf12 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf13 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_add_mul_pow_sqrt_sub_sum_3[grid(256)](buf0,
primals_8, buf4, buf5, buf6, buf8, buf7, buf10, buf12, buf13,
256, XBLOCK=256, num_warps=4, num_stages=1)
del buf5
del buf6
return buf11, primals_8, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), buf0, reinterpret_tensor(buf2, (64, 4), (4, 1), 0
), buf4, buf8, buf12, buf13, primals_6, buf14, primals_4
class AttentivePooling(nn.Module):
"""
Implementation of Attentive Pooling
"""
def __init__(self, input_dim, **kwargs):
super(AttentivePooling, self).__init__()
self.W_a = nn.Linear(input_dim, input_dim)
self.W = nn.Linear(input_dim, 1)
self.act_fn = nn.ReLU()
self.softmax = nn.functional.softmax
def forward(self, batch_rep, att_mask):
"""
input:
batch_rep : size (B, T, H), B: batch size, T: sequence length, H: Hidden dimension
attention_weight:
att_w : size (B, T, 1)
return:
utter_rep: size (B, H)
"""
att_logits = self.W(self.act_fn(self.W_a(batch_rep))).squeeze(-1)
att_logits = att_mask + att_logits
att_w = self.softmax(att_logits, dim=-1).unsqueeze(-1)
utter_rep = torch.sum(batch_rep * att_w, dim=1)
return utter_rep, att_w
class ASPNew(nn.Module):
""" Attentive Statistic Pooling module incoporate attention mask"""
def __init__(self, out_dim, input_dim):
super(ASPNew, self).__init__()
self.linear = nn.Linear(input_dim, out_dim)
self.ap_layer = AttentivePooling(out_dim)
def forward(self, input_0, input_1):
primals_1 = self.linear.weight
primals_2 = self.linear.bias
primals_4 = self.ap_layer.W_a.weight
primals_5 = self.ap_layer.W_a.bias
primals_6 = self.ap_layer.W.weight
primals_7 = self.ap_layer.W.bias
primals_3 = input_0
primals_8 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8])
return output[0]
|
gcambara/s3prl
|
ASP
| false
| 15,413
|
[
"MIT"
] | 856
|
33284ebde3a903ed8604d6dae85669d0174ae1d3
|
https://github.com/gcambara/s3prl/tree/33284ebde3a903ed8604d6dae85669d0174ae1d3
|
RegLoss
|
import torch
import torch.nn as nn
class RegLoss(nn.Module):
""" RegLoss, L2 regularization on model parameters
"""
def __init__(self):
super(RegLoss, self).__init__()
def forward(self, parameters):
reg_loss = None
for W in parameters:
if reg_loss is None:
reg_loss = W.norm(2)
else:
reg_loss = reg_loss + W.norm(2)
return reg_loss
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_add_linalg_vector_norm_0(in_out_ptr0, in_ptr0, xnumel,
rnumel, XBLOCK: tl.constexpr):
RBLOCK: tl.constexpr = 64
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp5 = tl.load(in_ptr0 + (64 + r0), None)
tmp10 = tl.load(in_ptr0 + (128 + r0), None)
tmp15 = tl.load(in_ptr0 + (192 + r0), None)
tmp1 = tmp0 * tmp0
tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp4 = tl.sum(tmp2, 1)[:, None]
tmp6 = tmp5 * tmp5
tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
tmp9 = tl.sum(tmp7, 1)[:, None]
tmp11 = tmp10 * tmp10
tmp12 = tl.broadcast_to(tmp11, [XBLOCK, RBLOCK])
tmp14 = tl.sum(tmp12, 1)[:, None]
tmp16 = tmp15 * tmp15
tmp17 = tl.broadcast_to(tmp16, [XBLOCK, RBLOCK])
tmp19 = tl.sum(tmp17, 1)[:, None]
tmp20 = libdevice.sqrt(tmp4)
tmp21 = libdevice.sqrt(tmp9)
tmp22 = tmp20 + tmp21
tmp23 = libdevice.sqrt(tmp14)
tmp24 = tmp22 + tmp23
tmp25 = libdevice.sqrt(tmp19)
tmp26 = tmp24 + tmp25
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp26, 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)
buf4 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_add_linalg_vector_norm_0[grid(1)](buf4, arg0_1, 1,
64, XBLOCK=1, num_warps=2, num_stages=1)
del arg0_1
return buf4,
class RegLossNew(nn.Module):
""" RegLoss, L2 regularization on model parameters
"""
def __init__(self):
super(RegLossNew, self).__init__()
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
geekinglcq/HRec
|
RegLoss
| false
| 15,414
|
[
"MIT"
] | 49
|
b3a67f7721e6e73a7af37d308b5b00e9df68d495
|
https://github.com/geekinglcq/HRec/tree/b3a67f7721e6e73a7af37d308b5b00e9df68d495
|
SelfAttentionPooling
|
import torch
import torch.nn as nn
class SelfAttentionPooling(nn.Module):
"""
Implementation of SelfAttentionPooling
Original Paper: Self-Attention Encoding and Pooling for Speaker Recognition
https://arxiv.org/pdf/2008.01077v1.pdf
"""
def __init__(self, input_dim):
super(SelfAttentionPooling, self).__init__()
self.W = nn.Linear(input_dim, 1)
def forward(self, batch_rep):
"""
input:
batch_rep : size (N, T, H), N: batch size, T: sequence length, H: Hidden dimension
attention_weight:
att_w : size (N, T, 1)
return:
utter_rep: size (N, H)
"""
softmax = nn.functional.softmax
att_w = softmax(self.W(batch_rep).squeeze(-1)).unsqueeze(-1)
utter_rep = torch.sum(batch_rep * att_w, dim=1)
return utter_rep
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 = 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_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (16 + x0), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (32 + x0), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (48 + x0), xmask, eviction_policy='evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x2, tmp9, xmask)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 16
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (16 + x0), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (32 + x0), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (48 + x0), 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_sum_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex // 16
x3 = xindex % 16
x1 = xindex // 4 % 4
x4 = xindex
tmp0 = tl.load(in_ptr0 + (x3 + 64 * x2), xmask)
tmp1 = tl.load(in_ptr1 + (x1 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (16 + x3 + 64 * x2), xmask)
tmp4 = tl.load(in_ptr1 + (4 + x1 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp7 = tl.load(in_ptr0 + (32 + x3 + 64 * x2), xmask)
tmp8 = tl.load(in_ptr1 + (8 + x1 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp11 = tl.load(in_ptr0 + (48 + x3 + 64 * x2), xmask)
tmp12 = tl.load(in_ptr1 + (12 + x1 + 16 * 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
tl.store(out_ptr0 + x4, 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), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf1 = empty_strided_cuda((64, 1), (1, 1), torch.float32)
extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64,
4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 1), (1, 4), 0
), alpha=1, beta=1, out=buf1)
del primals_1
del primals_2
buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__softmax_0[grid(64)](buf1, buf2, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_1[grid(64)](buf2, buf3, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf4 = buf2
del buf2
triton_poi_fused_mul_sum_2[grid(64)](primals_3, buf3, buf4, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del buf3
return buf4, primals_3, buf1
class SelfAttentionPoolingNew(nn.Module):
"""
Implementation of SelfAttentionPooling
Original Paper: Self-Attention Encoding and Pooling for Speaker Recognition
https://arxiv.org/pdf/2008.01077v1.pdf
"""
def __init__(self, input_dim):
super(SelfAttentionPoolingNew, self).__init__()
self.W = nn.Linear(input_dim, 1)
def forward(self, input_0):
primals_1 = self.W.weight
primals_2 = self.W.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
gcambara/s3prl
|
SelfAttentionPooling
| false
| 15,415
|
[
"MIT"
] | 856
|
33284ebde3a903ed8604d6dae85669d0174ae1d3
|
https://github.com/gcambara/s3prl/tree/33284ebde3a903ed8604d6dae85669d0174ae1d3
|
SoftmaxLoss
|
import torch
import torch.nn as nn
class SoftmaxLoss(nn.Module):
def __init__(self, hidden_dim, speaker_num, **kwargs):
"""
Softmax Loss
"""
super(SoftmaxLoss, self).__init__()
self.fc = nn.Linear(hidden_dim, speaker_num)
self.loss = nn.CrossEntropyLoss()
def forward(self, x_BxH, labels_B):
"""
x shape: (B, H)
labels shape: (B)
"""
logits_BxSpn = self.fc(x_BxH)
loss = self.loss(logits_BxSpn, labels_B)
return loss
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'hidden_dim': 4, 'speaker_num': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused__log_softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tl.store(out_ptr0 + x3, tmp8, xmask)
@triton.jit
def triton_per_fused__log_softmax_div_mul_neg_sum_1(in_out_ptr0, in_ptr0,
in_ptr1, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r3 = rindex
r0 = rindex % 16
r2 = rindex // 64
tmp0 = tl.load(in_ptr0 + r3, None)
tmp1 = tl.load(in_ptr0 + (r0 + 64 * r2), None, eviction_policy='evict_last'
)
tmp3 = tl.load(in_ptr0 + (16 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (32 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr0 + (48 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp14 = tl.load(in_ptr1 + r3, None)
tmp2 = tl_math.exp(tmp1)
tmp4 = tl_math.exp(tmp3)
tmp5 = tmp2 + tmp4
tmp7 = tl_math.exp(tmp6)
tmp8 = tmp5 + tmp7
tmp10 = tl_math.exp(tmp9)
tmp11 = tmp8 + tmp10
tmp12 = tl_math.log(tmp11)
tmp13 = tmp0 - tmp12
tmp15 = tmp13 * tmp14
tmp16 = tl.broadcast_to(tmp15, [RBLOCK])
tmp18 = triton_helpers.promote_to_tensor(tl.sum(tmp16, 0))
tmp19 = -tmp18
tmp20 = 0.015625
tmp21 = tmp19 * tmp20
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp21, None)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64,
4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0
), alpha=1, beta=1, out=buf0)
del primals_1
del primals_2
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__log_softmax_0[grid(256)](buf0, buf1, 256, XBLOCK=
128, num_warps=4, num_stages=1)
buf2 = empty_strided_cuda((), (), torch.float32)
buf3 = buf2
del buf2
triton_per_fused__log_softmax_div_mul_neg_sum_1[grid(1)](buf3, buf1,
primals_4, 1, 256, num_warps=2, num_stages=1)
del buf1
return buf3, primals_4, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), buf0
class SoftmaxLossNew(nn.Module):
def __init__(self, hidden_dim, speaker_num, **kwargs):
"""
Softmax Loss
"""
super(SoftmaxLossNew, self).__init__()
self.fc = nn.Linear(hidden_dim, speaker_num)
self.loss = nn.CrossEntropyLoss()
def forward(self, input_0, input_1):
primals_1 = self.fc.weight
primals_2 = self.fc.bias
primals_3 = input_0
primals_4 = input_1
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
gcambara/s3prl
|
SoftmaxLoss
| false
| 15,416
|
[
"MIT"
] | 856
|
33284ebde3a903ed8604d6dae85669d0174ae1d3
|
https://github.com/gcambara/s3prl/tree/33284ebde3a903ed8604d6dae85669d0174ae1d3
|
MLP
|
from torch.nn import Module
import torch
import torch.nn as nn
from torch.nn.modules.module import Module
class MLP(Module):
"""
A Simple two layers MLP to make SGC a bit better.
"""
def __init__(self, nfeat, nhid, nclass, dp=0.2):
super(MLP, self).__init__()
self.W1 = nn.Linear(nfeat, nhid)
self.W2 = nn.Linear(nhid, nclass)
self.dp = dp
self.act = nn.PReLU()
self.num_class = nclass
def forward(self, x):
x = self.act(self.W1(x))
x = nn.Dropout(p=self.dp)(x)
return self.W2(x)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'nfeat': 4, 'nhid': 4, 'nclass': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch.nn import Module
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__prelu_kernel_0(in_ptr0, in_ptr1, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp3 = tl.load(in_ptr1 + 0)
tmp4 = tl.broadcast_to(tmp3, [XBLOCK])
tmp1 = 0.0
tmp2 = tmp0 > tmp1
tmp5 = tmp4 * tmp0
tmp6 = tl.where(tmp2, tmp0, tmp5)
tl.store(out_ptr0 + x0, 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, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (1,), (1,))
assert_size_stride(primals_5, (4, 4), (4, 1))
assert_size_stride(primals_6, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.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__prelu_kernel_0[grid(256)](buf0, primals_4, buf1,
256, XBLOCK=256, num_warps=4, num_stages=1)
buf2 = torch.ops.aten.native_dropout.default(buf1, 0.2, True)
buf3 = buf2[0]
buf4 = buf2[1]
del buf2
buf5 = reinterpret_tensor(buf1, (64, 4), (4, 1), 0)
del buf1
extern_kernels.addmm(primals_6, reinterpret_tensor(buf3, (64, 4), (
4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0),
alpha=1, beta=1, out=buf5)
del primals_6
return reinterpret_tensor(buf5, (4, 4, 4, 4), (64, 16, 4, 1), 0
), primals_4, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), buf0, buf4, reinterpret_tensor(buf3, (64, 4), (4, 1), 0), primals_5
class MLPNew(Module):
"""
A Simple two layers MLP to make SGC a bit better.
"""
def __init__(self, nfeat, nhid, nclass, dp=0.2):
super(MLPNew, self).__init__()
self.W1 = nn.Linear(nfeat, nhid)
self.W2 = nn.Linear(nhid, nclass)
self.dp = dp
self.act = nn.PReLU()
self.num_class = nclass
def forward(self, input_0):
primals_1 = self.W1.weight
primals_2 = self.W1.bias
primals_5 = self.W2.weight
primals_6 = self.W2.bias
primals_4 = self.act.weight
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6])
return output[0]
|
gear/gfnn
|
MLP
| false
| 15,417
|
[
"MIT"
] | 46
|
36667861caacba921469d43917d002896e832c3f
|
https://github.com/gear/gfnn/tree/36667861caacba921469d43917d002896e832c3f
|
KGCN
|
from torch.nn import Module
import math
import torch
import torch.nn.functional as F
import torch.nn as nn
from torch.nn.parameter import Parameter
from torch.nn.modules.module import Module
class GraphConvolution(Module):
"""
Simple GCN layer
"""
def __init__(self, in_features, out_features, bias=True):
super(GraphConvolution, self).__init__()
self.in_features = in_features
self.out_features = out_features
self.weight = Parameter(torch.FloatTensor(in_features, out_features))
if bias:
self.bias = Parameter(torch.FloatTensor(out_features))
else:
self.register_parameter('bias', None)
self.reset_parameters()
def reset_parameters(self):
stdv = 1.0 / math.sqrt(self.weight.size(1))
self.weight.data.uniform_(-stdv, stdv)
if self.bias is not None:
self.bias.data.uniform_(-stdv, stdv)
def forward(self, input, adj):
support = torch.mm(input, self.weight)
output = torch.spmm(adj, support)
if self.bias is not None:
return output + self.bias
else:
return output
def __repr__(self):
return self.__class__.__name__ + ' (' + str(self.in_features
) + ' -> ' + str(self.out_features) + ')'
class KGCN(Module):
"""
A bit more complex GNN to deal with non-convex feature space.
"""
def __init__(self, nhidden, nfeat, nclass, degree):
super(KGCN, self).__init__()
self.Wx = GraphConvolution(nfeat, nhidden)
self.W = nn.Linear(nhidden, nclass)
self.d = degree
def forward(self, x, adj):
h = F.relu(self.Wx(x, adj))
for i in range(self.d):
h = torch.spmm(adj, h)
return self.W(h)
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4])]
def get_init_inputs():
return [[], {'nhidden': 4, 'nfeat': 4, 'nclass': 4, 'degree': 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 math
import torch.nn as nn
from torch.nn.parameter import Parameter
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_threshold_backward_0(in_out_ptr0, in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x2, tmp4, xmask)
tl.store(out_ptr0 + x2, tmp6, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4, 4), (4, 1))
assert_size_stride(primals_4, (4,), (1,))
assert_size_stride(primals_5, (4, 4), (4, 1))
assert_size_stride(primals_6, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((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
buf8 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
get_raw_stream(0)
triton_poi_fused_add_relu_threshold_backward_0[grid(16)](buf2,
primals_4, buf8, 16, XBLOCK=16, num_warps=1, num_stages=1)
del primals_4
buf3 = buf0
del buf0
extern_kernels.mm(primals_3, buf2, out=buf3)
buf4 = buf2
del buf2
extern_kernels.mm(primals_3, buf3, out=buf4)
buf5 = buf3
del buf3
extern_kernels.mm(primals_3, buf4, out=buf5)
buf6 = buf4
del buf4
extern_kernels.mm(primals_3, buf5, out=buf6)
buf7 = buf5
del buf5
extern_kernels.addmm(primals_6, buf6, reinterpret_tensor(primals_5,
(4, 4), (1, 4), 0), alpha=1, beta=1, out=buf7)
del primals_6
return buf7, buf6, primals_5, reinterpret_tensor(primals_3, (4, 4), (1,
4), 0), buf8, reinterpret_tensor(primals_2, (4, 4), (1, 4), 0)
class GraphConvolution(Module):
"""
Simple GCN layer
"""
def __init__(self, in_features, out_features, bias=True):
super(GraphConvolution, self).__init__()
self.in_features = in_features
self.out_features = out_features
self.weight = Parameter(torch.FloatTensor(in_features, out_features))
if bias:
self.bias = Parameter(torch.FloatTensor(out_features))
else:
self.register_parameter('bias', None)
self.reset_parameters()
def reset_parameters(self):
stdv = 1.0 / math.sqrt(self.weight.size(1))
self.weight.data.uniform_(-stdv, stdv)
if self.bias is not None:
self.bias.data.uniform_(-stdv, stdv)
def forward(self, input, adj):
support = torch.mm(input, self.weight)
output = torch.spmm(adj, support)
if self.bias is not None:
return output + self.bias
else:
return output
def __repr__(self):
return self.__class__.__name__ + ' (' + str(self.in_features
) + ' -> ' + str(self.out_features) + ')'
class KGCNNew(Module):
"""
A bit more complex GNN to deal with non-convex feature space.
"""
def __init__(self, nhidden, nfeat, nclass, degree):
super(KGCNNew, self).__init__()
self.Wx = GraphConvolution(nfeat, nhidden)
self.W = nn.Linear(nhidden, nclass)
self.d = degree
def forward(self, input_0, input_1):
primals_1 = self.Wx.weight
primals_4 = self.Wx.bias
primals_2 = self.W.weight
primals_6 = self.W.bias
primals_3 = input_0
primals_5 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6])
return output[0]
|
gear/gfnn
|
KGCN
| false
| 15,418
|
[
"MIT"
] | 46
|
36667861caacba921469d43917d002896e832c3f
|
https://github.com/gear/gfnn/tree/36667861caacba921469d43917d002896e832c3f
|
L2NormLoss
|
import torch
import torch.utils.data
import torch.nn as nn
class L2NormLoss(nn.Module):
def __init__(self):
super(L2NormLoss, self).__init__()
def forward(self, x1, x2, y1, y2):
dist_in = torch.norm(x1 - x2, dim=1, keepdim=True)
dist_out = torch.norm(y1 - y2, dim=1, keepdim=True)
loss = torch.norm(dist_in - dist_out) / x1.size(0)
return loss
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand(
[4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
import torch.utils.data
import torch.nn as nn
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_linalg_vector_norm_sub_0(in_out_ptr0, in_ptr0,
in_ptr1, in_ptr2, in_ptr3, 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)
tmp20 = tl.load(in_ptr2 + (r0 + 64 * r1), None)
tmp21 = tl.load(in_ptr3 + (r0 + 64 * r1), None)
tmp24 = tl.load(in_ptr2 + (16 + r0 + 64 * r1), None)
tmp25 = tl.load(in_ptr3 + (16 + r0 + 64 * r1), None)
tmp29 = tl.load(in_ptr2 + (32 + r0 + 64 * r1), None)
tmp30 = tl.load(in_ptr3 + (32 + r0 + 64 * r1), None)
tmp34 = tl.load(in_ptr2 + (48 + r0 + 64 * r1), None)
tmp35 = tl.load(in_ptr3 + (48 + r0 + 64 * r1), None)
tmp2 = tmp0 - tmp1
tmp3 = tmp2 * tmp2
tmp6 = tmp4 - tmp5
tmp7 = tmp6 * tmp6
tmp8 = tmp3 + tmp7
tmp11 = tmp9 - tmp10
tmp12 = tmp11 * tmp11
tmp13 = tmp8 + tmp12
tmp16 = tmp14 - tmp15
tmp17 = tmp16 * tmp16
tmp18 = tmp13 + tmp17
tmp19 = libdevice.sqrt(tmp18)
tmp22 = tmp20 - tmp21
tmp23 = tmp22 * tmp22
tmp26 = tmp24 - tmp25
tmp27 = tmp26 * tmp26
tmp28 = tmp23 + tmp27
tmp31 = tmp29 - tmp30
tmp32 = tmp31 * tmp31
tmp33 = tmp28 + tmp32
tmp36 = tmp34 - tmp35
tmp37 = tmp36 * tmp36
tmp38 = tmp33 + tmp37
tmp39 = libdevice.sqrt(tmp38)
tmp40 = tmp19 - tmp39
tmp41 = tmp40 * tmp40
tmp42 = tl.broadcast_to(tmp41, [XBLOCK, RBLOCK])
tmp44 = tl.sum(tmp42, 1)[:, None]
tmp45 = libdevice.sqrt(tmp44)
tmp46 = 0.25
tmp47 = tmp45 * tmp46
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp47, None)
def call(args):
arg0_1, arg1_1, arg2_1, arg3_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg3_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf1 = empty_strided_cuda((), (), torch.float32)
buf2 = buf1
del buf1
get_raw_stream(0)
triton_per_fused_div_linalg_vector_norm_sub_0[grid(1)](buf2, arg0_1,
arg1_1, arg2_1, arg3_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
del arg2_1
del arg3_1
return buf2,
class L2NormLossNew(nn.Module):
def __init__(self):
super(L2NormLossNew, self).__init__()
def forward(self, input_0, input_1, input_2, input_3):
arg0_1 = input_0
arg1_1 = input_1
arg2_1 = input_2
arg3_1 = input_3
output = call([arg0_1, arg1_1, arg2_1, arg3_1])
return output[0]
|
gfiumara/MSU-LatentAFIS
|
L2NormLoss
| false
| 15,419
|
[
"MIT"
] | 53
|
682464b0bc4501977f1304c51e2638c0ee89d87c
|
https://github.com/gfiumara/MSU-LatentAFIS/tree/682464b0bc4501977f1304c51e2638c0ee89d87c
|
AttLayer
|
import torch
import torch.nn as nn
import torch.nn.functional as fn
class AttLayer(nn.Module):
"""Calculate the attention signal(weight) according the input tensor.
Args:
infeatures (torch.FloatTensor): A 3D input tensor with shape of[batch_size, M, embed_dim].
Returns:
torch.FloatTensor: Attention weight of input. shape of [batch_size, M].
"""
def __init__(self, in_dim, att_dim):
super(AttLayer, self).__init__()
self.in_dim = in_dim
self.att_dim = att_dim
self.w = torch.nn.Linear(in_features=in_dim, out_features=att_dim,
bias=False)
self.h = nn.Parameter(torch.randn(att_dim), requires_grad=True)
def forward(self, infeatures):
att_singal = self.w(infeatures)
att_singal = fn.relu(att_singal)
att_singal = torch.mul(att_singal, self.h)
att_singal = torch.sum(att_singal, dim=2)
att_singal = fn.softmax(att_singal, dim=1)
return att_singal
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_dim': 4, 'att_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_mul_relu_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 % 4
x1 = xindex // 4
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 16 * x1), xmask)
tmp3 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (4 + x0 + 16 * x1), xmask)
tmp9 = tl.load(in_ptr0 + (8 + x0 + 16 * x1), xmask)
tmp13 = tl.load(in_ptr0 + (12 + x0 + 16 * x1), xmask)
tmp1 = tl.full([1], 0, tl.int32)
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp4 = tmp2 * tmp3
tmp6 = triton_helpers.maximum(tmp1, tmp5)
tmp7 = tmp6 * tmp3
tmp8 = tmp4 + tmp7
tmp10 = triton_helpers.maximum(tmp1, tmp9)
tmp11 = tmp10 * tmp3
tmp12 = tmp8 + tmp11
tmp14 = triton_helpers.maximum(tmp1, tmp13)
tmp15 = tmp14 * tmp3
tmp16 = tmp12 + tmp15
tl.store(out_ptr0 + x2, tmp16, xmask)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 4
x2 = xindex // 16
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x3, tmp9, xmask)
@triton.jit
def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 4
x2 = xindex // 16
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x3, tmp8, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_3, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0)
del primals_1
buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_mul_relu_sum_0[grid(64)](buf0, primals_3, buf1, 64,
XBLOCK=64, num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_1[grid(64)](buf1, buf2, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf3 = buf1
del buf1
triton_poi_fused__softmax_2[grid(64)](buf2, buf3, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del buf2
return buf3, primals_3, reinterpret_tensor(primals_2, (64, 4), (4, 1), 0
), buf0, buf3
class AttLayerNew(nn.Module):
"""Calculate the attention signal(weight) according the input tensor.
Args:
infeatures (torch.FloatTensor): A 3D input tensor with shape of[batch_size, M, embed_dim].
Returns:
torch.FloatTensor: Attention weight of input. shape of [batch_size, M].
"""
def __init__(self, in_dim, att_dim):
super(AttLayerNew, self).__init__()
self.in_dim = in_dim
self.att_dim = att_dim
self.w = torch.nn.Linear(in_features=in_dim, out_features=att_dim,
bias=False)
self.h = nn.Parameter(torch.randn(att_dim), requires_grad=True)
def forward(self, input_0):
primals_3 = self.h
primals_1 = self.w.weight
primals_2 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
geekinglcq/HRec
|
AttLayer
| false
| 15,420
|
[
"MIT"
] | 49
|
b3a67f7721e6e73a7af37d308b5b00e9df68d495
|
https://github.com/geekinglcq/HRec/tree/b3a67f7721e6e73a7af37d308b5b00e9df68d495
|
VisErrorLossV2
|
import torch
import torch.nn.functional as F
from torch import nn
class VisErrorLossV2(nn.Module):
def __init__(self):
super(VisErrorLossV2, self).__init__()
def compute_l1_weighted_loss(self, hm_targets, hm_preds, vismap, ohem=1.0):
"""
:param hm_targets: [batch size, keypoint number, h, w]
:param hm_preds: [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
epsilon = 0.0001
hm_preds = F.relu(hm_preds, False)
amplitude = torch.max(hm_targets)
b, k, h, w = hm_targets.size()
hm_targets = hm_targets.view(b, k, -1)
hm_preds = hm_preds.view(b, k, -1)
vismap = vismap.view(b, k, 1).repeat(1, 1, h * w)
pos_ids = (hm_targets > amplitude / 10) & (vismap == 1)
neg_ids = (hm_targets <= amplitude / 10) & (vismap == 1)
diff = (hm_targets - hm_preds).abs()
pos_loss = (diff * pos_ids.float()).sum(2).sum(0) / (pos_ids.float(
).sum(2).sum(0) + epsilon)
neg_loss = (diff * neg_ids.float()).sum(2).sum(0) / (neg_ids.float(
).sum(2).sum(0) + epsilon)
total_loss = 0.5 * pos_loss + 0.5 * neg_loss
if ohem < 1:
k = int(total_loss.size(0) * ohem)
total_loss, _ = total_loss.topk(k)
return total_loss.mean()
def compute_l2_loss(self, hm_targets, hm_preds, vismap, ohem=1.0):
"""
:param hm_targets: [batch size, keypoint number, h, w]
:param hm_preds: [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
epsilon = 0.0001
hm_preds = F.relu(hm_preds, False)
b, k, h, w = hm_targets.size()
hm_targets = hm_targets.view(b, k, -1)
hm_preds = hm_preds.view(b, k, -1)
vismap = vismap.view(b, k, 1).repeat(1, 1, h * w)
ids = vismap == 1
diff = (hm_targets - hm_preds) ** 2
total_loss = (diff * ids.float()).sum(2).sum(0) / (ids.float().sum(
2).sum(0) + epsilon)
if ohem < 1:
k = int(total_loss.size(0) * ohem)
total_loss, _ = total_loss.topk(k)
return total_loss.mean()
def forward(self, hm_targets, hm_preds1, hm_preds2, vismap):
"""
:param hm_targets: list of 4 elements, each is [batch size, keypoint number, h, w]
:param hm_preds1: list of 4 elements, each is [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
loss1 = 0
for t, p in zip(hm_targets, hm_preds1):
loss1 += self.compute_l1_weighted_loss(t, p, vismap)
break
loss2 = self.compute_l1_weighted_loss(hm_targets[0], hm_preds2,
vismap, ohem=0.5)
return loss1 + loss2, loss1, loss2
def get_inputs():
return [torch.rand([4, 4, 16, 4, 4]), torch.rand([4, 4, 4, 4]), torch.
rand([4, 4, 16, 4]), torch.rand([4, 16, 1])]
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.functional as F
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_max_0(in_ptr0, out_ptr0, out_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)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
tmp3 = triton_helpers.promote_to_tensor(triton_helpers.max2(tmp1, 0))
tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp3, None)
tl.store(out_ptr1 + tl.full([1], 0, tl.int32), tmp3, None)
@triton.jit
def triton_per_fused__to_copy_abs_bitwise_and_div_eq_gt_le_mul_repeat_sub_sum_1(
in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0,
out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5, out_ptr6, out_ptr7,
xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 64
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r2 = rindex
x3 = xindex
x0 = xindex % 16
x1 = xindex // 16
tmp0 = tl.load(in_ptr0 + (r2 + 16 * x3), xmask, other=0.0)
tmp1 = tl.load(in_ptr1 + (r2 + 16 * x0 + 256 * x1 + 256 * ((r2 + 16 *
x0) // 256)), xmask, eviction_policy='evict_last', other=0.0)
tmp6 = tl.load(in_ptr2 + 0)
tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
tmp11 = tl.load(in_ptr3 + x3, xmask, eviction_policy='evict_last')
tmp37 = tl.load(in_ptr4 + x3, xmask, eviction_policy='evict_last')
tmp41 = tl.load(in_ptr5 + 0)
tmp42 = tl.broadcast_to(tmp41, [XBLOCK, RBLOCK])
tmp2 = tl.full([1, 1], 0, tl.int32)
tmp3 = triton_helpers.maximum(tmp2, tmp1)
tmp4 = tmp0 - tmp3
tmp5 = tl_math.abs(tmp4)
tmp8 = 0.1
tmp9 = tmp7 * tmp8
tmp10 = tmp0 > tmp9
tmp12 = 1.0
tmp13 = tmp11 == tmp12
tmp14 = tmp10 & tmp13
tmp15 = tmp14.to(tl.float32)
tmp16 = tmp5 * tmp15
tmp17 = tl.broadcast_to(tmp16, [XBLOCK, RBLOCK])
tmp19 = tl.where(xmask, tmp17, 0)
tmp20 = tl.sum(tmp19, 1)[:, None]
tmp21 = tmp0 <= tmp9
tmp22 = tmp21 & tmp13
tmp23 = tmp22.to(tl.float32)
tmp24 = tmp5 * tmp23
tmp25 = tl.broadcast_to(tmp24, [XBLOCK, RBLOCK])
tmp27 = tl.where(xmask, tmp25, 0)
tmp28 = tl.sum(tmp27, 1)[:, None]
tmp29 = tl.broadcast_to(tmp15, [XBLOCK, RBLOCK])
tmp31 = tl.where(xmask, tmp29, 0)
tmp32 = tl.sum(tmp31, 1)[:, None]
tmp33 = tl.broadcast_to(tmp23, [XBLOCK, RBLOCK])
tmp35 = tl.where(xmask, tmp33, 0)
tmp36 = tl.sum(tmp35, 1)[:, None]
tmp38 = triton_helpers.maximum(tmp2, tmp37)
tmp39 = tmp0 - tmp38
tmp40 = tl_math.abs(tmp39)
tmp43 = tmp42 * tmp8
tmp44 = tmp0 > tmp43
tmp45 = tmp44 & tmp13
tmp46 = tmp45.to(tl.float32)
tmp47 = tmp40 * tmp46
tmp48 = tl.broadcast_to(tmp47, [XBLOCK, RBLOCK])
tmp50 = tl.where(xmask, tmp48, 0)
tmp51 = tl.sum(tmp50, 1)[:, None]
tmp52 = tmp0 <= tmp43
tmp53 = tmp52 & tmp13
tmp54 = tmp53.to(tl.float32)
tmp55 = tmp40 * tmp54
tmp56 = tl.broadcast_to(tmp55, [XBLOCK, RBLOCK])
tmp58 = tl.where(xmask, tmp56, 0)
tmp59 = tl.sum(tmp58, 1)[:, None]
tmp60 = tl.broadcast_to(tmp46, [XBLOCK, RBLOCK])
tmp62 = tl.where(xmask, tmp60, 0)
tmp63 = tl.sum(tmp62, 1)[:, None]
tmp64 = tl.broadcast_to(tmp54, [XBLOCK, RBLOCK])
tmp66 = tl.where(xmask, tmp64, 0)
tmp67 = tl.sum(tmp66, 1)[:, None]
tl.store(out_ptr0 + x3, tmp20, xmask)
tl.store(out_ptr1 + x3, tmp28, xmask)
tl.store(out_ptr2 + x3, tmp32, xmask)
tl.store(out_ptr3 + x3, tmp36, xmask)
tl.store(out_ptr4 + x3, tmp51, xmask)
tl.store(out_ptr5 + x3, tmp59, xmask)
tl.store(out_ptr6 + x3, tmp63, xmask)
tl.store(out_ptr7 + x3, tmp67, xmask)
@triton.jit
def triton_poi_fused_add_div_mul_sum_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + (16 + x0), xmask)
tmp3 = tl.load(in_ptr0 + (32 + x0), xmask)
tmp5 = tl.load(in_ptr0 + (48 + x0), xmask)
tmp7 = tl.load(in_ptr1 + x0, xmask)
tmp8 = tl.load(in_ptr1 + (16 + x0), xmask)
tmp10 = tl.load(in_ptr1 + (32 + x0), xmask)
tmp12 = tl.load(in_ptr1 + (48 + x0), xmask)
tmp19 = tl.load(in_ptr2 + x0, xmask)
tmp20 = tl.load(in_ptr2 + (16 + x0), xmask)
tmp22 = tl.load(in_ptr2 + (32 + x0), xmask)
tmp24 = tl.load(in_ptr2 + (48 + x0), xmask)
tmp26 = tl.load(in_ptr3 + x0, xmask)
tmp27 = tl.load(in_ptr3 + (16 + x0), xmask)
tmp29 = tl.load(in_ptr3 + (32 + x0), xmask)
tmp31 = tl.load(in_ptr3 + (48 + x0), xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp9 = tmp7 + tmp8
tmp11 = tmp9 + tmp10
tmp13 = tmp11 + tmp12
tmp14 = 0.0001
tmp15 = tmp13 + tmp14
tmp16 = tmp6 / tmp15
tmp17 = 0.5
tmp18 = tmp16 * tmp17
tmp21 = tmp19 + tmp20
tmp23 = tmp21 + tmp22
tmp25 = tmp23 + tmp24
tmp28 = tmp26 + tmp27
tmp30 = tmp28 + tmp29
tmp32 = tmp30 + tmp31
tmp33 = tmp32 + tmp14
tmp34 = tmp25 / tmp33
tmp35 = tmp34 * tmp17
tmp36 = tmp18 + tmp35
tl.store(out_ptr0 + x0, tmp36, xmask)
@triton.jit
def triton_per_fused_mean_3(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl.
constexpr):
RBLOCK: tl.constexpr = 8
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.sum(tmp1, 1)[:, None]
tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp3, None)
@triton.jit
def triton_per_fused_add_div_mean_mul_sum_4(in_out_ptr0, in_out_ptr1,
in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_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_ptr0 + (16 + r0), None)
tmp3 = tl.load(in_ptr0 + (32 + r0), None)
tmp5 = tl.load(in_ptr0 + (48 + r0), None)
tmp7 = tl.load(in_ptr1 + r0, None)
tmp8 = tl.load(in_ptr1 + (16 + r0), None)
tmp10 = tl.load(in_ptr1 + (32 + r0), None)
tmp12 = tl.load(in_ptr1 + (48 + r0), None)
tmp19 = tl.load(in_ptr2 + r0, None)
tmp20 = tl.load(in_ptr2 + (16 + r0), None)
tmp22 = tl.load(in_ptr2 + (32 + r0), None)
tmp24 = tl.load(in_ptr2 + (48 + r0), None)
tmp26 = tl.load(in_ptr3 + r0, None)
tmp27 = tl.load(in_ptr3 + (16 + r0), None)
tmp29 = tl.load(in_ptr3 + (32 + r0), None)
tmp31 = tl.load(in_ptr3 + (48 + r0), None)
tmp44 = tl.load(in_out_ptr1 + 0)
tmp45 = tl.broadcast_to(tmp44, [XBLOCK, 1])
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp9 = tmp7 + tmp8
tmp11 = tmp9 + tmp10
tmp13 = tmp11 + tmp12
tmp14 = 0.0001
tmp15 = tmp13 + tmp14
tmp16 = tmp6 / tmp15
tmp17 = 0.5
tmp18 = tmp16 * tmp17
tmp21 = tmp19 + tmp20
tmp23 = tmp21 + tmp22
tmp25 = tmp23 + tmp24
tmp28 = tmp26 + tmp27
tmp30 = tmp28 + tmp29
tmp32 = tmp30 + tmp31
tmp33 = tmp32 + tmp14
tmp34 = tmp25 / tmp33
tmp35 = tmp34 * tmp17
tmp36 = tmp18 + tmp35
tmp37 = tl.broadcast_to(tmp36, [XBLOCK, RBLOCK])
tmp39 = tl.sum(tmp37, 1)[:, None]
tmp40 = 16.0
tmp41 = tmp39 / tmp40
tmp42 = 0.0
tmp43 = tmp41 + tmp42
tmp46 = 8.0
tmp47 = tmp45 / tmp46
tmp48 = tmp43 + tmp47
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp43, None)
tl.debug_barrier()
tl.store(in_out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp47, None)
tl.store(out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp48, None)
def call(args):
arg0_1, arg1_1, arg2_1, arg3_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 16, 4, 4), (1024, 256, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg2_1, (4, 16, 1), (16, 1, 1))
assert_size_stride(arg3_1, (4, 4, 16, 4), (256, 64, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((), (), torch.float32)
buf9 = empty_strided_cuda((), (), torch.float32)
get_raw_stream(0)
triton_per_fused_max_0[grid(1)](arg0_1, buf0, buf9, 1, 1024,
num_warps=8, num_stages=1)
buf1 = empty_strided_cuda((4, 16), (16, 1), torch.float32)
buf3 = empty_strided_cuda((4, 16), (16, 1), torch.float32)
buf2 = empty_strided_cuda((4, 16), (16, 1), torch.float32)
buf4 = empty_strided_cuda((4, 16), (16, 1), torch.float32)
buf10 = empty_strided_cuda((4, 16), (16, 1), torch.float32)
buf12 = empty_strided_cuda((4, 16), (16, 1), torch.float32)
buf11 = empty_strided_cuda((4, 16), (16, 1), torch.float32)
buf13 = empty_strided_cuda((4, 16), (16, 1), torch.float32)
triton_per_fused__to_copy_abs_bitwise_and_div_eq_gt_le_mul_repeat_sub_sum_1[
grid(64)](arg0_1, arg3_1, buf0, arg2_1, arg1_1, buf9, buf1,
buf3, buf2, buf4, buf10, buf12, buf11, buf13, 64, 16, XBLOCK=1,
num_warps=2, num_stages=1)
del arg0_1
del arg1_1
del arg2_1
del arg3_1
buf5 = empty_strided_cuda((16,), (1,), torch.float32)
triton_poi_fused_add_div_mul_sum_2[grid(16)](buf1, buf2, buf3, buf4,
buf5, 16, XBLOCK=16, num_warps=1, num_stages=1)
del buf1
del buf2
del buf3
del buf4
buf6 = torch.ops.aten.topk.default(buf5, 8)
del buf5
buf7 = buf6[0]
del buf6
buf17 = buf9
del buf9
triton_per_fused_mean_3[grid(1)](buf7, buf17, 1, 8, XBLOCK=1,
num_warps=2, num_stages=1)
del buf7
buf15 = buf0
del buf0
buf16 = buf15
del buf15
buf18 = buf17
del buf17
buf19 = empty_strided_cuda((), (), torch.float32)
triton_per_fused_add_div_mean_mul_sum_4[grid(1)](buf16, buf18,
buf10, buf11, buf12, buf13, buf19, 1, 16, XBLOCK=1, num_warps=2,
num_stages=1)
del buf10
del buf11
del buf12
del buf13
return buf19, buf16, buf18
class VisErrorLossV2New(nn.Module):
def __init__(self):
super(VisErrorLossV2New, self).__init__()
def compute_l1_weighted_loss(self, hm_targets, hm_preds, vismap, ohem=1.0):
"""
:param hm_targets: [batch size, keypoint number, h, w]
:param hm_preds: [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
epsilon = 0.0001
hm_preds = F.relu(hm_preds, False)
amplitude = torch.max(hm_targets)
b, k, h, w = hm_targets.size()
hm_targets = hm_targets.view(b, k, -1)
hm_preds = hm_preds.view(b, k, -1)
vismap = vismap.view(b, k, 1).repeat(1, 1, h * w)
pos_ids = (hm_targets > amplitude / 10) & (vismap == 1)
neg_ids = (hm_targets <= amplitude / 10) & (vismap == 1)
diff = (hm_targets - hm_preds).abs()
pos_loss = (diff * pos_ids.float()).sum(2).sum(0) / (pos_ids.float(
).sum(2).sum(0) + epsilon)
neg_loss = (diff * neg_ids.float()).sum(2).sum(0) / (neg_ids.float(
).sum(2).sum(0) + epsilon)
total_loss = 0.5 * pos_loss + 0.5 * neg_loss
if ohem < 1:
k = int(total_loss.size(0) * ohem)
total_loss, _ = total_loss.topk(k)
return total_loss.mean()
def compute_l2_loss(self, hm_targets, hm_preds, vismap, ohem=1.0):
"""
:param hm_targets: [batch size, keypoint number, h, w]
:param hm_preds: [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
epsilon = 0.0001
hm_preds = F.relu(hm_preds, False)
b, k, h, w = hm_targets.size()
hm_targets = hm_targets.view(b, k, -1)
hm_preds = hm_preds.view(b, k, -1)
vismap = vismap.view(b, k, 1).repeat(1, 1, h * w)
ids = vismap == 1
diff = (hm_targets - hm_preds) ** 2
total_loss = (diff * ids.float()).sum(2).sum(0) / (ids.float().sum(
2).sum(0) + epsilon)
if ohem < 1:
k = int(total_loss.size(0) * ohem)
total_loss, _ = total_loss.topk(k)
return total_loss.mean()
def forward(self, input_0, input_1, input_2, input_3):
arg0_1 = input_0
arg1_1 = input_1
arg3_1 = input_2
arg2_1 = input_3
output = call([arg0_1, arg1_1, arg2_1, arg3_1])
return output[0], output[1], output[2]
|
gathierry/FashionAI-KeyPointsDetectionOfApparel
|
VisErrorLossV2
| false
| 15,421
|
[
"Apache-2.0"
] | 174
|
2e0942b42b4a9cd974cdddc151675738dc8a8cb4
|
https://github.com/gathierry/FashionAI-KeyPointsDetectionOfApparel/tree/2e0942b42b4a9cd974cdddc151675738dc8a8cb4
|
RobertaOutput
|
from _paritybench_helpers import _mock_config
import torch
from torch import nn
import torch.utils.checkpoint
class RobertaOutput(nn.Module):
def __init__(self, config):
super().__init__()
self.dense = nn.Linear(config.intermediate_size, config.hidden_size)
self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.
layer_norm_eps)
self.dropout = nn.Dropout(config.hidden_dropout_prob)
def forward(self, hidden_states, input_tensor):
hidden_states = self.dense(hidden_states)
hidden_states = self.dropout(hidden_states)
hidden_states = self.LayerNorm(hidden_states + input_tensor)
return hidden_states
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'config': _mock_config(intermediate_size=4, hidden_size=4,
layer_norm_eps=1, hidden_dropout_prob=0.5)}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
from torch import nn
import torch.utils.checkpoint
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_add_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK:
tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x2, xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tl.store(in_out_ptr0 + x2, tmp4, xmask)
@triton.jit
def triton_poi_fused_native_layer_norm_1(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 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 = 1.0
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_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = tmp2 * tmp3
tmp6 = tmp4 * tmp5
tmp8 = tmp6 + tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0)
del primals_1
buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf0
get_raw_stream(0)
triton_poi_fused_add_0[grid(256)](buf1, primals_2, primals_4, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_2
del primals_4
buf2 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
buf3 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
triton_poi_fused_native_layer_norm_1[grid(64)](buf1, buf2, buf3, 64,
XBLOCK=64, num_warps=1, num_stages=1)
buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_native_layer_norm_2[grid(256)](buf1, buf2, buf3,
primals_5, primals_6, buf4, 256, XBLOCK=256, num_warps=4,
num_stages=1)
del buf2
del buf3
del primals_6
return buf4, primals_5, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), buf1
class RobertaOutputNew(nn.Module):
def __init__(self, config):
super().__init__()
self.dense = nn.Linear(config.intermediate_size, config.hidden_size)
self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.
layer_norm_eps)
self.dropout = nn.Dropout(config.hidden_dropout_prob)
def forward(self, input_0, input_1):
primals_1 = self.dense.weight
primals_2 = self.dense.bias
primals_5 = self.LayerNorm.weight
primals_6 = self.LayerNorm.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]
|
IntelLabs/Model-Compression-Research-Package
|
RobertaOutput
| false
| 15,422
|
[
"Apache-2.0"
] | 58
|
69aecbf5cc73b10fab88a13d8ca6d8314d284c0b
|
https://github.com/IntelLabs/Model-Compression-Research-Package/tree/69aecbf5cc73b10fab88a13d8ca6d8314d284c0b
|
Net
|
import torch
import torch.nn as nn
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.conv1_1 = nn.Conv2d(1, 8, 5, 2, 0)
self.conv2_1 = nn.Conv2d(8, 16, 3, 1, 0)
self.conv2_2 = nn.Conv2d(16, 16, 3, 1, 0)
self.conv3_1 = nn.Conv2d(16, 24, 3, 1, 0)
self.conv3_2 = nn.Conv2d(24, 24, 3, 1, 0)
self.conv4_1 = nn.Conv2d(24, 40, 3, 1, 1)
self.conv4_2 = nn.Conv2d(40, 80, 3, 1, 1)
self.ip1 = nn.Linear(4 * 4 * 80, 128)
self.ip2 = nn.Linear(128, 128)
self.ip3 = nn.Linear(128, 42)
self.prelu1_1 = nn.PReLU()
self.prelu2_1 = nn.PReLU()
self.prelu2_2 = nn.PReLU()
self.prelu3_1 = nn.PReLU()
self.prelu3_2 = nn.PReLU()
self.prelu4_1 = nn.PReLU()
self.prelu4_2 = nn.PReLU()
self.preluip1 = nn.PReLU()
self.preluip2 = nn.PReLU()
self.ave_pool = nn.AvgPool2d(2, 2, ceil_mode=True)
def forward(self, x):
x = self.ave_pool(self.prelu1_1(self.conv1_1(x)))
x = self.prelu2_1(self.conv2_1(x))
x = self.prelu2_2(self.conv2_2(x))
x = self.ave_pool(x)
x = self.prelu3_1(self.conv3_1(x))
x = self.prelu3_2(self.conv3_2(x))
x = self.ave_pool(x)
x = self.prelu4_1(self.conv4_1(x))
ip3 = self.prelu4_2(self.conv4_2(x))
ip3 = ip3.view(-1, 4 * 4 * 80)
ip3 = self.preluip1(self.ip1(ip3))
ip3 = self.preluip2(self.ip2(ip3))
ip3 = self.ip3(ip3)
return ip3
def get_inputs():
return [torch.rand([4, 1, 144, 144])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 128
xnumel = 9
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 8
y1 = yindex // 8
tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask & ymask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (y0 + 8 * x2 + 72 * y1), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 256
xnumel = 9
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 16
y1 = yindex // 16
tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask & ymask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (y0 + 16 * x2 + 144 * y1), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 384
xnumel = 9
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 16
y1 = yindex // 16
tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask & ymask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (y0 + 16 * x2 + 144 * y1), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 576
xnumel = 9
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 24
y1 = yindex // 24
tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask & ymask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (y0 + 24 * x2 + 216 * y1), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 960
xnumel = 9
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 24
y1 = yindex // 24
tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask & ymask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (y0 + 24 * x2 + 216 * y1), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_5(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 3200
xnumel = 9
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 40
y1 = yindex // 40
tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask & ymask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (y0 + 40 * x2 + 360 * y1), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_convolution_6(in_ptr0, in_ptr1, out_ptr0, ynumel,
xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 32
xnumel = 4900
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 % 8
y1 = yindex // 8
tmp0 = tl.load(in_ptr0 + (x2 + 4900 * y3), xmask & ymask,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + (y0 + 8 * x2 + 39200 * y1), tmp2, xmask & ymask)
@triton.jit
def triton_poi_fused__prelu_kernel_7(in_ptr0, in_ptr1, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 156800
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp3 = tl.load(in_ptr1 + 0)
tmp4 = tl.broadcast_to(tmp3, [XBLOCK])
tmp1 = 0.0
tmp2 = tmp0 > tmp1
tmp5 = tmp4 * tmp0
tmp6 = tl.where(tmp2, tmp0, tmp5)
tl.store(out_ptr0 + x0, tmp6, xmask)
@triton.jit
def triton_poi_fused_avg_pool2d_8(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 39200
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 8
x1 = xindex // 8 % 35
x2 = xindex // 280
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 16 * x1 + 1120 * x2), xmask)
tmp1 = tl.load(in_ptr0 + (8 + x0 + 16 * x1 + 1120 * x2), xmask)
tmp3 = tl.load(in_ptr0 + (560 + x0 + 16 * x1 + 1120 * x2), xmask)
tmp5 = tl.load(in_ptr0 + (568 + x0 + 16 * x1 + 1120 * x2), xmask)
tmp2 = tmp1 + tmp0
tmp4 = tmp3 + tmp2
tmp6 = tmp5 + tmp4
tmp7 = 0.25
tmp8 = tmp6 * tmp7
tl.store(out_ptr0 + x3, tmp8, xmask)
@triton.jit
def triton_poi_fused__prelu_kernel_convolution_9(in_out_ptr0, in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 69696
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 16
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + 0)
tmp6 = tl.broadcast_to(tmp5, [XBLOCK])
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp7 = tmp6 * tmp2
tmp8 = tl.where(tmp4, tmp2, tmp7)
tl.store(in_out_ptr0 + x2, tmp2, xmask)
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused__prelu_kernel_convolution_10(in_out_ptr0, in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 61504
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 16
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + 0)
tmp6 = tl.broadcast_to(tmp5, [XBLOCK])
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp7 = tmp6 * tmp2
tmp8 = tl.where(tmp4, tmp2, tmp7)
tl.store(in_out_ptr0 + x2, tmp2, xmask)
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused_avg_pool2d_11(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x2 = xindex // 256 % 16
x1 = xindex // 16 % 16
x0 = xindex % 16
x3 = xindex // 4096
x6 = xindex
tmp0 = 2 * x2
tmp1 = tl.full([1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1], 31, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tmp2 & tmp4
tmp6 = 2 * x1
tmp7 = tmp6 >= tmp1
tmp8 = tmp6 < tmp3
tmp9 = tmp7 & tmp8
tmp10 = tmp5 & tmp9
tmp11 = tl.load(in_ptr0 + (x0 + 32 * x1 + 992 * x2 + 15376 * x3), tmp10,
other=0.0)
tmp12 = 1 + 2 * x1
tmp13 = tmp12 >= tmp1
tmp14 = tmp12 < tmp3
tmp15 = tmp13 & tmp14
tmp16 = tmp5 & tmp15
tmp17 = tl.load(in_ptr0 + (16 + x0 + 32 * x1 + 992 * x2 + 15376 * x3),
tmp16, other=0.0)
tmp18 = tmp17 + tmp11
tmp19 = 1 + 2 * x2
tmp20 = tmp19 >= tmp1
tmp21 = tmp19 < tmp3
tmp22 = tmp20 & tmp21
tmp23 = tmp22 & tmp9
tmp24 = tl.load(in_ptr0 + (496 + x0 + 32 * x1 + 992 * x2 + 15376 * x3),
tmp23, other=0.0)
tmp25 = tmp24 + tmp18
tmp26 = tmp22 & tmp15
tmp27 = tl.load(in_ptr0 + (512 + x0 + 32 * x1 + 992 * x2 + 15376 * x3),
tmp26, other=0.0)
tmp28 = tmp27 + tmp25
tmp29 = (31 * (31 <= 2 + 2 * x1) + (2 + 2 * x1) * (2 + 2 * x1 < 31)) * (
31 * (31 <= 2 + 2 * x2) + (2 + 2 * x2) * (2 + 2 * x2 < 31)
) + -2 * x1 * (31 * (31 <= 2 + 2 * x2) + (2 + 2 * x2) * (2 + 2 * x2 <
31)) + -2 * x2 * (31 * (31 <= 2 + 2 * x1) + (2 + 2 * x1) * (2 + 2 *
x1 < 31)) + 4 * x1 * x2
tmp30 = tmp28 / tmp29
tl.store(out_ptr0 + x6, tmp30, None)
@triton.jit
def triton_poi_fused__prelu_kernel_convolution_12(in_out_ptr0, in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 18816
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 24
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + 0)
tmp6 = tl.broadcast_to(tmp5, [XBLOCK])
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp7 = tmp6 * tmp2
tmp8 = tl.where(tmp4, tmp2, tmp7)
tl.store(in_out_ptr0 + x2, tmp2, xmask)
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused__prelu_kernel_convolution_13(in_out_ptr0, in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 13824
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 24
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + 0)
tmp6 = tl.broadcast_to(tmp5, [XBLOCK])
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp7 = tmp6 * tmp2
tmp8 = tl.where(tmp4, tmp2, tmp7)
tl.store(in_out_ptr0 + x2, tmp2, xmask)
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused_avg_pool2d_14(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 3456
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 24
x1 = xindex // 24 % 6
x2 = xindex // 144
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 48 * x1 + 576 * x2), xmask)
tmp1 = tl.load(in_ptr0 + (24 + x0 + 48 * x1 + 576 * x2), xmask)
tmp3 = tl.load(in_ptr0 + (288 + x0 + 48 * x1 + 576 * x2), xmask)
tmp5 = tl.load(in_ptr0 + (312 + x0 + 48 * x1 + 576 * x2), xmask)
tmp2 = tmp1 + tmp0
tmp4 = tmp3 + tmp2
tmp6 = tmp5 + tmp4
tmp7 = 0.25
tmp8 = tmp6 * tmp7
tl.store(out_ptr0 + x3, tmp8, xmask)
@triton.jit
def triton_poi_fused__prelu_kernel_convolution_15(in_out_ptr0, in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 5760
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 40
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + 0)
tmp6 = tl.broadcast_to(tmp5, [XBLOCK])
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp7 = tmp6 * tmp2
tmp8 = tl.where(tmp4, tmp2, tmp7)
tl.store(in_out_ptr0 + x2, tmp2, xmask)
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused__prelu_kernel_convolution_16(in_out_ptr0, in_ptr0,
in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.
constexpr):
ynumel = 144
xnumel = 80
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
y2 = yindex % 36
y3 = yindex // 36
tmp0 = tl.load(in_out_ptr0 + (x1 + 80 * y0), xmask & ymask,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + 0)
tmp6 = tl.broadcast_to(tmp5, [XBLOCK, YBLOCK])
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp7 = tmp6 * tmp2
tmp8 = tl.where(tmp4, tmp2, tmp7)
tl.debug_barrier()
tl.store(in_out_ptr0 + (x1 + 80 * y0), tmp2, xmask & ymask)
tl.store(out_ptr0 + (y2 + 36 * x1 + 2880 * y3), tmp8, xmask & ymask)
@triton.jit
def triton_poi_fused__prelu_kernel_17(in_ptr0, in_ptr1, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 1152
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp3 = tl.load(in_ptr1 + 0)
tmp4 = tl.broadcast_to(tmp3, [XBLOCK])
tmp1 = 0.0
tmp2 = tmp0 > tmp1
tmp5 = tmp4 * tmp0
tmp6 = tl.where(tmp2, tmp0, tmp5)
tl.store(out_ptr0 + x0, tmp6, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
primals_13, primals_14, primals_15, primals_16, 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, (8, 1, 5, 5), (25, 25, 5, 1))
assert_size_stride(primals_2, (8,), (1,))
assert_size_stride(primals_3, (4, 1, 144, 144), (20736, 20736, 144, 1))
assert_size_stride(primals_4, (1,), (1,))
assert_size_stride(primals_5, (16, 8, 3, 3), (72, 9, 3, 1))
assert_size_stride(primals_6, (16,), (1,))
assert_size_stride(primals_7, (1,), (1,))
assert_size_stride(primals_8, (16, 16, 3, 3), (144, 9, 3, 1))
assert_size_stride(primals_9, (16,), (1,))
assert_size_stride(primals_10, (1,), (1,))
assert_size_stride(primals_11, (24, 16, 3, 3), (144, 9, 3, 1))
assert_size_stride(primals_12, (24,), (1,))
assert_size_stride(primals_13, (1,), (1,))
assert_size_stride(primals_14, (24, 24, 3, 3), (216, 9, 3, 1))
assert_size_stride(primals_15, (24,), (1,))
assert_size_stride(primals_16, (1,), (1,))
assert_size_stride(primals_17, (40, 24, 3, 3), (216, 9, 3, 1))
assert_size_stride(primals_18, (40,), (1,))
assert_size_stride(primals_19, (1,), (1,))
assert_size_stride(primals_20, (80, 40, 3, 3), (360, 9, 3, 1))
assert_size_stride(primals_21, (80,), (1,))
assert_size_stride(primals_22, (1,), (1,))
assert_size_stride(primals_23, (128, 1280), (1280, 1))
assert_size_stride(primals_24, (128,), (1,))
assert_size_stride(primals_25, (1,), (1,))
assert_size_stride(primals_26, (128, 128), (128, 1))
assert_size_stride(primals_27, (128,), (1,))
assert_size_stride(primals_28, (1,), (1,))
assert_size_stride(primals_29, (42, 128), (128, 1))
assert_size_stride(primals_30, (42,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((16, 8, 3, 3), (72, 1, 24, 8), torch.float32)
get_raw_stream(0)
triton_poi_fused_0[grid(128, 9)](primals_5, buf0, 128, 9, XBLOCK=16,
YBLOCK=64, num_warps=4, num_stages=1)
del primals_5
buf1 = empty_strided_cuda((16, 16, 3, 3), (144, 1, 48, 16), torch.
float32)
triton_poi_fused_1[grid(256, 9)](primals_8, buf1, 256, 9, XBLOCK=16,
YBLOCK=64, num_warps=4, num_stages=1)
del primals_8
buf2 = empty_strided_cuda((24, 16, 3, 3), (144, 1, 48, 16), torch.
float32)
triton_poi_fused_2[grid(384, 9)](primals_11, buf2, 384, 9, XBLOCK=
16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_11
buf3 = empty_strided_cuda((24, 24, 3, 3), (216, 1, 72, 24), torch.
float32)
triton_poi_fused_3[grid(576, 9)](primals_14, buf3, 576, 9, XBLOCK=
16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_14
buf4 = empty_strided_cuda((40, 24, 3, 3), (216, 1, 72, 24), torch.
float32)
triton_poi_fused_4[grid(960, 9)](primals_17, buf4, 960, 9, XBLOCK=
16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_17
buf5 = empty_strided_cuda((80, 40, 3, 3), (360, 1, 120, 40), torch.
float32)
triton_poi_fused_5[grid(3200, 9)](primals_20, buf5, 3200, 9, XBLOCK
=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_20
buf6 = extern_kernels.convolution(primals_3, primals_1, stride=(2,
2), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf6, (4, 8, 70, 70), (39200, 4900, 70, 1))
buf7 = empty_strided_cuda((4, 8, 70, 70), (39200, 1, 560, 8), torch
.float32)
triton_poi_fused_convolution_6[grid(32, 4900)](buf6, primals_2,
buf7, 32, 4900, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
del primals_2
buf8 = reinterpret_tensor(buf6, (4, 8, 70, 70), (39200, 1, 560, 8), 0)
del buf6
triton_poi_fused__prelu_kernel_7[grid(156800)](buf7, primals_4,
buf8, 156800, XBLOCK=512, num_warps=8, num_stages=1)
buf9 = empty_strided_cuda((4, 8, 35, 35), (9800, 1, 280, 8), torch.
float32)
triton_poi_fused_avg_pool2d_8[grid(39200)](buf8, buf9, 39200,
XBLOCK=512, num_warps=4, num_stages=1)
buf10 = extern_kernels.convolution(buf9, buf0, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf10, (4, 16, 33, 33), (17424, 1, 528, 16))
buf11 = buf10
del buf10
buf12 = empty_strided_cuda((4, 16, 33, 33), (17424, 1, 528, 16),
torch.float32)
triton_poi_fused__prelu_kernel_convolution_9[grid(69696)](buf11,
primals_6, primals_7, buf12, 69696, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_6
buf13 = extern_kernels.convolution(buf12, buf1, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf13, (4, 16, 31, 31), (15376, 1, 496, 16))
buf14 = buf13
del buf13
buf15 = empty_strided_cuda((4, 16, 31, 31), (15376, 1, 496, 16),
torch.float32)
triton_poi_fused__prelu_kernel_convolution_10[grid(61504)](buf14,
primals_9, primals_10, buf15, 61504, XBLOCK=512, num_warps=4,
num_stages=1)
del primals_9
buf16 = empty_strided_cuda((4, 16, 16, 16), (4096, 1, 256, 16),
torch.float32)
triton_poi_fused_avg_pool2d_11[grid(16384)](buf15, buf16, 16384,
XBLOCK=256, num_warps=4, num_stages=1)
buf17 = extern_kernels.convolution(buf16, buf2, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf17, (4, 24, 14, 14), (4704, 1, 336, 24))
buf18 = buf17
del buf17
buf19 = empty_strided_cuda((4, 24, 14, 14), (4704, 1, 336, 24),
torch.float32)
triton_poi_fused__prelu_kernel_convolution_12[grid(18816)](buf18,
primals_12, primals_13, buf19, 18816, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_12
buf20 = extern_kernels.convolution(buf19, buf3, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf20, (4, 24, 12, 12), (3456, 1, 288, 24))
buf21 = buf20
del buf20
buf22 = empty_strided_cuda((4, 24, 12, 12), (3456, 1, 288, 24),
torch.float32)
triton_poi_fused__prelu_kernel_convolution_13[grid(13824)](buf21,
primals_15, primals_16, buf22, 13824, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_15
buf23 = empty_strided_cuda((4, 24, 6, 6), (864, 1, 144, 24), torch.
float32)
triton_poi_fused_avg_pool2d_14[grid(3456)](buf22, buf23, 3456,
XBLOCK=256, num_warps=4, num_stages=1)
buf24 = extern_kernels.convolution(buf23, buf4, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf24, (4, 40, 6, 6), (1440, 1, 240, 40))
buf25 = buf24
del buf24
buf26 = empty_strided_cuda((4, 40, 6, 6), (1440, 1, 240, 40), torch
.float32)
triton_poi_fused__prelu_kernel_convolution_15[grid(5760)](buf25,
primals_18, primals_19, buf26, 5760, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_18
buf27 = extern_kernels.convolution(buf26, buf5, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf27, (4, 80, 6, 6), (2880, 1, 480, 80))
buf28 = buf27
del buf27
buf29 = empty_strided_cuda((4, 80, 6, 6), (2880, 36, 6, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_16[grid(144, 80)](buf28,
primals_21, primals_22, buf29, 144, 80, XBLOCK=32, YBLOCK=32,
num_warps=4, num_stages=1)
del primals_21
buf30 = empty_strided_cuda((9, 128), (128, 1), torch.float32)
extern_kernels.addmm(primals_24, reinterpret_tensor(buf29, (9, 1280
), (1280, 1), 0), reinterpret_tensor(primals_23, (1280, 128), (
1, 1280), 0), alpha=1, beta=1, out=buf30)
del primals_24
buf31 = empty_strided_cuda((9, 128), (128, 1), torch.float32)
triton_poi_fused__prelu_kernel_17[grid(1152)](buf30, primals_25,
buf31, 1152, XBLOCK=256, num_warps=4, num_stages=1)
buf32 = empty_strided_cuda((9, 128), (128, 1), torch.float32)
extern_kernels.addmm(primals_27, buf31, reinterpret_tensor(
primals_26, (128, 128), (1, 128), 0), alpha=1, beta=1, out=buf32)
del primals_27
buf33 = empty_strided_cuda((9, 128), (128, 1), torch.float32)
triton_poi_fused__prelu_kernel_17[grid(1152)](buf32, primals_28,
buf33, 1152, XBLOCK=256, num_warps=4, num_stages=1)
buf34 = empty_strided_cuda((9, 42), (42, 1), torch.float32)
extern_kernels.addmm(primals_30, buf33, reinterpret_tensor(
primals_29, (128, 42), (1, 128), 0), alpha=1, beta=1, out=buf34)
del primals_30
return (buf34, primals_1, primals_3, primals_4, buf0, primals_7, buf1,
primals_10, buf2, primals_13, buf3, primals_16, buf4, primals_19,
buf5, primals_22, primals_25, primals_28, buf7, buf8, buf9, buf11,
buf12, buf14, buf15, buf16, buf18, buf19, buf21, buf22, buf23,
buf25, buf26, buf28, reinterpret_tensor(buf29, (9, 1280), (1280, 1),
0), buf30, buf31, buf32, buf33, primals_29, primals_26, primals_23)
class NetNew(nn.Module):
def __init__(self):
super(NetNew, self).__init__()
self.conv1_1 = nn.Conv2d(1, 8, 5, 2, 0)
self.conv2_1 = nn.Conv2d(8, 16, 3, 1, 0)
self.conv2_2 = nn.Conv2d(16, 16, 3, 1, 0)
self.conv3_1 = nn.Conv2d(16, 24, 3, 1, 0)
self.conv3_2 = nn.Conv2d(24, 24, 3, 1, 0)
self.conv4_1 = nn.Conv2d(24, 40, 3, 1, 1)
self.conv4_2 = nn.Conv2d(40, 80, 3, 1, 1)
self.ip1 = nn.Linear(4 * 4 * 80, 128)
self.ip2 = nn.Linear(128, 128)
self.ip3 = nn.Linear(128, 42)
self.prelu1_1 = nn.PReLU()
self.prelu2_1 = nn.PReLU()
self.prelu2_2 = nn.PReLU()
self.prelu3_1 = nn.PReLU()
self.prelu3_2 = nn.PReLU()
self.prelu4_1 = nn.PReLU()
self.prelu4_2 = nn.PReLU()
self.preluip1 = nn.PReLU()
self.preluip2 = nn.PReLU()
self.ave_pool = nn.AvgPool2d(2, 2, ceil_mode=True)
def forward(self, input_0):
primals_1 = self.conv1_1.weight
primals_2 = self.conv1_1.bias
primals_5 = self.conv2_1.weight
primals_6 = self.conv2_1.bias
primals_8 = self.conv2_2.weight
primals_9 = self.conv2_2.bias
primals_11 = self.conv3_1.weight
primals_12 = self.conv3_1.bias
primals_14 = self.conv3_2.weight
primals_15 = self.conv3_2.bias
primals_17 = self.conv4_1.weight
primals_18 = self.conv4_1.bias
primals_20 = self.conv4_2.weight
primals_21 = self.conv4_2.bias
primals_23 = self.ip1.weight
primals_24 = self.ip1.bias
primals_26 = self.ip2.weight
primals_27 = self.ip2.bias
primals_29 = self.ip3.weight
primals_30 = self.ip3.bias
primals_4 = self.prelu1_1.weight
primals_7 = self.prelu2_1.weight
primals_10 = self.prelu2_2.weight
primals_13 = self.prelu3_1.weight
primals_16 = self.prelu3_2.weight
primals_19 = self.prelu4_1.weight
primals_22 = self.prelu4_2.weight
primals_25 = self.preluip1.weight
primals_28 = self.preluip2.weight
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11, primals_12, primals_13, primals_14,
primals_15, primals_16, primals_17, primals_18, primals_19,
primals_20, primals_21, primals_22, primals_23, primals_24,
primals_25, primals_26, primals_27, primals_28, primals_29,
primals_30])
return output[0]
|
fengjixuchui/EmbeddedSystem
|
Net
| false
| 15,423
|
[
"MIT"
] | 228
|
ae17e41bb120922a99f2d91818c381e38e868040
|
https://github.com/fengjixuchui/EmbeddedSystem/tree/ae17e41bb120922a99f2d91818c381e38e868040
|
Delta
|
import torch
import torch.nn as nn
from torchaudio import transforms
class Delta(nn.Module):
def __init__(self, order=2, **kwargs):
super(Delta, self).__init__()
self.order = order
self.compute_delta = transforms.ComputeDeltas(**kwargs)
def forward(self, x):
feats = [x]
for o in range(self.order):
feat = feats[-1].transpose(0, 1).unsqueeze(0)
delta = self.compute_delta(feat)
feats.append(delta.squeeze(0).transpose(0, 1))
x = torch.cat(feats, 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
from torchaudio import transforms
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_replication_pad1d_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 512
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 8
x1 = xindex // 8
x2 = xindex
tmp0 = tl.load(in_ptr0 + (4 * (x1 % 4) + 16 * (x1 // 16) + 64 * (x1 //
4 % 4) + (3 * (3 <= 0 * (0 >= -2 + x0) + (-2 + x0) * (-2 + x0 > 0)) +
(0 * (0 >= -2 + x0) + (-2 + x0) * (-2 + x0 > 0)) * (0 * (0 >= -2 +
x0) + (-2 + x0) * (-2 + x0 > 0) < 3))), xmask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + x2, tmp0, xmask)
@triton.jit
def triton_poi_fused_arange_repeat_1(out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 320
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 5
x2 = xindex
tmp0 = -2 + x0
tmp1 = tmp0.to(tl.float32)
tl.store(out_ptr0 + x2, tmp1, xmask)
@triton.jit
def triton_poi_fused_replication_pad1d_2(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 512
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 8
x1 = xindex // 8
x2 = xindex
tmp0 = tl.load(in_ptr0 + (4 * x1 + (3 * (3 <= 0 * (0 >= -2 + x0) + (-2 +
x0) * (-2 + x0 > 0)) + (0 * (0 >= -2 + x0) + (-2 + x0) * (-2 + x0 >
0)) * (0 * (0 >= -2 + x0) + (-2 + x0) * (-2 + x0 > 0) < 3))), xmask,
eviction_policy='evict_last')
tmp1 = 0.1
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x2, tmp2, xmask)
@triton.jit
def triton_poi_fused_cat_3(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 768
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 12
x4 = xindex // 12
x1 = xindex // 12 % 4
x2 = xindex // 48 % 4
x3 = xindex // 192
x5 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (4 * x4 + x0), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tmp0 >= tmp3
tmp7 = tl.full([1], 8, tl.int64)
tmp8 = tmp0 < tmp7
tmp9 = tmp6 & tmp8
tmp10 = tl.load(in_ptr1 + (4 * x1 + 16 * x3 + 64 * x2 + (-4 + x0)),
tmp9 & xmask, eviction_policy='evict_last', other=0.0)
tmp11 = 0.1
tmp12 = tmp10 * tmp11
tmp13 = tl.full(tmp12.shape, 0.0, tmp12.dtype)
tmp14 = tl.where(tmp9, tmp12, tmp13)
tmp15 = tmp0 >= tmp7
tl.full([1], 12, tl.int64)
tmp18 = tl.load(in_ptr2 + (4 * x1 + 16 * x3 + 64 * x2 + (-8 + x0)),
tmp15 & xmask, eviction_policy='evict_last', other=0.0)
tmp19 = tmp18 * tmp11
tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype)
tmp21 = tl.where(tmp15, tmp19, tmp20)
tmp22 = tl.where(tmp9, tmp14, tmp21)
tmp23 = tl.where(tmp4, tmp5, tmp22)
tl.store(out_ptr0 + x5, tmp23, 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((1, 64, 8), (512, 8, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_replication_pad1d_0[grid(512)](arg0_1, buf0, 512,
XBLOCK=128, num_warps=4, num_stages=1)
buf1 = empty_strided_cuda((64, 1, 5), (5, 5, 1), torch.float32)
triton_poi_fused_arange_repeat_1[grid(320)](buf1, 320, XBLOCK=256,
num_warps=4, num_stages=1)
buf2 = extern_kernels.convolution(buf0, buf1, stride=(1,), padding=
(0,), dilation=(1,), transposed=False, output_padding=(0,),
groups=64, bias=None)
assert_size_stride(buf2, (1, 64, 4), (256, 4, 1))
buf3 = buf0
del buf0
triton_poi_fused_replication_pad1d_2[grid(512)](buf2, buf3, 512,
XBLOCK=256, num_warps=4, num_stages=1)
buf4 = buf1
del buf1
triton_poi_fused_arange_repeat_1[grid(320)](buf4, 320, XBLOCK=256,
num_warps=4, num_stages=1)
buf5 = extern_kernels.convolution(buf3, buf4, stride=(1,), padding=
(0,), dilation=(1,), transposed=False, output_padding=(0,),
groups=64, bias=None)
assert_size_stride(buf5, (1, 64, 4), (256, 4, 1))
del buf3
del buf4
buf6 = empty_strided_cuda((4, 4, 4, 12), (192, 48, 12, 1), torch.
float32)
triton_poi_fused_cat_3[grid(768)](arg0_1, buf2, buf5, buf6, 768,
XBLOCK=128, num_warps=4, num_stages=1)
del arg0_1
del buf2
del buf5
return buf6,
class DeltaNew(nn.Module):
def __init__(self, order=2, **kwargs):
super(DeltaNew, self).__init__()
self.order = order
self.compute_delta = transforms.ComputeDeltas(**kwargs)
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
gcambara/s3prl
|
Delta
| false
| 15,424
|
[
"MIT"
] | 856
|
33284ebde3a903ed8604d6dae85669d0174ae1d3
|
https://github.com/gcambara/s3prl/tree/33284ebde3a903ed8604d6dae85669d0174ae1d3
|
Glu
|
import torch
import torch.nn as nn
class Glu(nn.Module):
def __init__(self, dim):
super(Glu, self).__init__()
self.dim = dim
def forward(self, x):
x_in, x_gate = x.chunk(2, dim=self.dim)
return x_in * x_gate.sigmoid()
def get_inputs():
return [torch.rand([4, 4, 4, 4, 4])]
def get_init_inputs():
return [[], {'dim': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_mul_sigmoid_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 512
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 2
x1 = xindex // 2
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4 * x1), xmask)
tmp1 = tl.load(in_ptr0 + (2 + x0 + 4 * x1), xmask)
tmp2 = tl.sigmoid(tmp1)
tmp3 = tmp0 * tmp2
tl.store(out_ptr0 + x2, tmp3, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4, 2), (128, 32, 8, 2, 1),
torch.float32)
get_raw_stream(0)
triton_poi_fused_mul_sigmoid_0[grid(512)](arg0_1, buf0, 512, XBLOCK
=128, num_warps=4, num_stages=1)
del arg0_1
return buf0,
class GluNew(nn.Module):
def __init__(self, dim):
super(GluNew, self).__init__()
self.dim = dim
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
gheyret/EfficientConformer
|
Glu
| false
| 15,425
|
[
"Apache-2.0"
] | 101
|
b28a0aaa3b182f72abaccbeb12df0402adf96097
|
https://github.com/gheyret/EfficientConformer/tree/b28a0aaa3b182f72abaccbeb12df0402adf96097
|
VisErrorLoss
|
import torch
import torch.nn.functional as F
from torch import nn
class VisErrorLoss(nn.Module):
def __init__(self):
super(VisErrorLoss, self).__init__()
def compute_l1_weighted_loss(self, hm_targets, hm_preds, vismap, ohem=1.0):
"""
:param hm_targets: [batch size, keypoint number, h, w]
:param hm_preds: [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
epsilon = 0.0001
hm_preds = F.relu(hm_preds, False)
amplitude = torch.max(hm_targets)
b, k, h, w = hm_targets.size()
hm_targets = hm_targets.view(b, k, -1)
hm_preds = hm_preds.view(b, k, -1)
vismap = vismap.view(b, k, 1).repeat(1, 1, h * w)
pos_ids = (hm_targets > amplitude / 10) & (vismap >= 0)
neg_ids = (hm_targets <= amplitude / 10) & (vismap >= 0)
diff = (hm_targets - hm_preds).abs()
pos_loss = (diff * pos_ids.float()).sum(2).sum(0) / (pos_ids.float(
).sum(2).sum(0) + epsilon)
neg_loss = (diff * neg_ids.float()).sum(2).sum(0) / (neg_ids.float(
).sum(2).sum(0) + epsilon)
total_loss = 0.5 * pos_loss + 0.5 * neg_loss
if ohem < 1:
k = int(total_loss.size(0) * ohem)
total_loss, _ = total_loss.topk(k)
return total_loss.mean()
def compute_l2_loss(self, hm_targets, hm_preds, vismap, ohem=1.0):
"""
:param hm_targets: [batch size, keypoint number, h, w]
:param hm_preds: [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
epsilon = 0.0001
hm_preds = F.relu(hm_preds, False)
b, k, h, w = hm_targets.size()
hm_targets = hm_targets.view(b, k, -1)
hm_preds = hm_preds.view(b, k, -1)
vismap = vismap.view(b, k, 1).repeat(1, 1, h * w)
ids = vismap == 1
diff = (hm_targets - hm_preds) ** 2
total_loss = (diff * ids.float()).sum(2).sum(0) / (ids.float().sum(
2).sum(0) + epsilon)
if ohem < 1:
k = int(total_loss.size(0) * ohem)
total_loss, _ = total_loss.topk(k)
return total_loss.mean()
def forward(self, hm_targets, hm_preds1, hm_preds2, vismap):
"""
:param hm_targets: [batch size, keypoint number, h, w]
:param hm_preds: [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
loss1 = self.compute_l1_weighted_loss(hm_targets, hm_preds1, vismap)
loss2 = self.compute_l1_weighted_loss(hm_targets, hm_preds2, vismap,
ohem=0.5)
return loss1 + loss2, loss1, loss2
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand(
[4, 4, 4, 4]), torch.rand([4, 4, 1])]
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.functional as F
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_max_0(in_ptr0, out_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.broadcast_to(tmp0, [RBLOCK])
tmp3 = triton_helpers.promote_to_tensor(triton_helpers.max2(tmp1, 0))
tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp3, None)
tl.store(out_ptr1 + tl.full([1], 0, tl.int32), tmp3, None)
@triton.jit
def triton_per_fused__to_copy_abs_bitwise_and_div_ge_gt_le_mul_repeat_sub_sum_1(
in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0,
out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5, out_ptr6, out_ptr7,
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.load(in_ptr1 + (r1 + 16 * x0), xmask, other=0.0)
tmp6 = tl.load(in_ptr2 + 0)
tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
tmp11 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
tmp37 = tl.load(in_ptr4 + (r1 + 16 * x0), xmask, other=0.0)
tmp41 = tl.load(in_ptr5 + 0)
tmp42 = tl.broadcast_to(tmp41, [XBLOCK, RBLOCK])
tmp2 = tl.full([1, 1], 0, tl.int32)
tmp3 = triton_helpers.maximum(tmp2, tmp1)
tmp4 = tmp0 - tmp3
tmp5 = tl_math.abs(tmp4)
tmp8 = 0.1
tmp9 = tmp7 * tmp8
tmp10 = tmp0 > tmp9
tmp12 = 0.0
tmp13 = tmp11 >= tmp12
tmp14 = tmp10 & tmp13
tmp15 = tmp14.to(tl.float32)
tmp16 = tmp5 * tmp15
tmp17 = tl.broadcast_to(tmp16, [XBLOCK, RBLOCK])
tmp19 = tl.where(xmask, tmp17, 0)
tmp20 = tl.sum(tmp19, 1)[:, None]
tmp21 = tmp0 <= tmp9
tmp22 = tmp21 & tmp13
tmp23 = tmp22.to(tl.float32)
tmp24 = tmp5 * tmp23
tmp25 = tl.broadcast_to(tmp24, [XBLOCK, RBLOCK])
tmp27 = tl.where(xmask, tmp25, 0)
tmp28 = tl.sum(tmp27, 1)[:, None]
tmp29 = tl.broadcast_to(tmp15, [XBLOCK, RBLOCK])
tmp31 = tl.where(xmask, tmp29, 0)
tmp32 = tl.sum(tmp31, 1)[:, None]
tmp33 = tl.broadcast_to(tmp23, [XBLOCK, RBLOCK])
tmp35 = tl.where(xmask, tmp33, 0)
tmp36 = tl.sum(tmp35, 1)[:, None]
tmp38 = triton_helpers.maximum(tmp2, tmp37)
tmp39 = tmp0 - tmp38
tmp40 = tl_math.abs(tmp39)
tmp43 = tmp42 * tmp8
tmp44 = tmp0 > tmp43
tmp45 = tmp44 & tmp13
tmp46 = tmp45.to(tl.float32)
tmp47 = tmp40 * tmp46
tmp48 = tl.broadcast_to(tmp47, [XBLOCK, RBLOCK])
tmp50 = tl.where(xmask, tmp48, 0)
tmp51 = tl.sum(tmp50, 1)[:, None]
tmp52 = tmp0 <= tmp43
tmp53 = tmp52 & tmp13
tmp54 = tmp53.to(tl.float32)
tmp55 = tmp40 * tmp54
tmp56 = tl.broadcast_to(tmp55, [XBLOCK, RBLOCK])
tmp58 = tl.where(xmask, tmp56, 0)
tmp59 = tl.sum(tmp58, 1)[:, None]
tmp60 = tl.broadcast_to(tmp46, [XBLOCK, RBLOCK])
tmp62 = tl.where(xmask, tmp60, 0)
tmp63 = tl.sum(tmp62, 1)[:, None]
tmp64 = tl.broadcast_to(tmp54, [XBLOCK, RBLOCK])
tmp66 = tl.where(xmask, tmp64, 0)
tmp67 = tl.sum(tmp66, 1)[:, None]
tl.store(out_ptr0 + x0, tmp20, xmask)
tl.store(out_ptr1 + x0, tmp28, xmask)
tl.store(out_ptr2 + x0, tmp32, xmask)
tl.store(out_ptr3 + x0, tmp36, xmask)
tl.store(out_ptr4 + x0, tmp51, xmask)
tl.store(out_ptr5 + x0, tmp59, xmask)
tl.store(out_ptr6 + x0, tmp63, xmask)
tl.store(out_ptr7 + x0, tmp67, xmask)
@triton.jit
def triton_poi_fused_add_div_mul_sum_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + (4 + x0), xmask)
tmp3 = tl.load(in_ptr0 + (8 + x0), xmask)
tmp5 = tl.load(in_ptr0 + (12 + x0), xmask)
tmp7 = tl.load(in_ptr1 + x0, xmask)
tmp8 = tl.load(in_ptr1 + (4 + x0), xmask)
tmp10 = tl.load(in_ptr1 + (8 + x0), xmask)
tmp12 = tl.load(in_ptr1 + (12 + x0), xmask)
tmp19 = tl.load(in_ptr2 + x0, xmask)
tmp20 = tl.load(in_ptr2 + (4 + x0), xmask)
tmp22 = tl.load(in_ptr2 + (8 + x0), xmask)
tmp24 = tl.load(in_ptr2 + (12 + x0), xmask)
tmp26 = tl.load(in_ptr3 + x0, xmask)
tmp27 = tl.load(in_ptr3 + (4 + x0), xmask)
tmp29 = tl.load(in_ptr3 + (8 + x0), xmask)
tmp31 = tl.load(in_ptr3 + (12 + x0), xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp9 = tmp7 + tmp8
tmp11 = tmp9 + tmp10
tmp13 = tmp11 + tmp12
tmp14 = 0.0001
tmp15 = tmp13 + tmp14
tmp16 = tmp6 / tmp15
tmp17 = 0.5
tmp18 = tmp16 * tmp17
tmp21 = tmp19 + tmp20
tmp23 = tmp21 + tmp22
tmp25 = tmp23 + tmp24
tmp28 = tmp26 + tmp27
tmp30 = tmp28 + tmp29
tmp32 = tmp30 + tmp31
tmp33 = tmp32 + tmp14
tmp34 = tmp25 / tmp33
tmp35 = tmp34 * tmp17
tmp36 = tmp18 + tmp35
tl.store(out_ptr0 + x0, tmp36, xmask)
@triton.jit
def triton_per_fused_mean_3(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl.
constexpr):
RBLOCK: tl.constexpr = 2
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.sum(tmp1, 1)[:, None]
tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp3, None)
@triton.jit
def triton_per_fused_add_div_mean_mul_sum_4(in_out_ptr0, in_out_ptr1,
in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr1, xnumel, rnumel, XBLOCK:
tl.constexpr):
RBLOCK: tl.constexpr = 4
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp1 = tl.load(in_ptr0 + (4 + r0), None)
tmp3 = tl.load(in_ptr0 + (8 + r0), None)
tmp5 = tl.load(in_ptr0 + (12 + r0), None)
tmp7 = tl.load(in_ptr1 + r0, None)
tmp8 = tl.load(in_ptr1 + (4 + r0), None)
tmp10 = tl.load(in_ptr1 + (8 + r0), None)
tmp12 = tl.load(in_ptr1 + (12 + r0), None)
tmp19 = tl.load(in_ptr2 + r0, None)
tmp20 = tl.load(in_ptr2 + (4 + r0), None)
tmp22 = tl.load(in_ptr2 + (8 + r0), None)
tmp24 = tl.load(in_ptr2 + (12 + r0), None)
tmp26 = tl.load(in_ptr3 + r0, None)
tmp27 = tl.load(in_ptr3 + (4 + r0), None)
tmp29 = tl.load(in_ptr3 + (8 + r0), None)
tmp31 = tl.load(in_ptr3 + (12 + r0), None)
tmp42 = tl.load(in_out_ptr1 + 0)
tmp43 = tl.broadcast_to(tmp42, [XBLOCK, 1])
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp9 = tmp7 + tmp8
tmp11 = tmp9 + tmp10
tmp13 = tmp11 + tmp12
tmp14 = 0.0001
tmp15 = tmp13 + tmp14
tmp16 = tmp6 / tmp15
tmp17 = 0.5
tmp18 = tmp16 * tmp17
tmp21 = tmp19 + tmp20
tmp23 = tmp21 + tmp22
tmp25 = tmp23 + tmp24
tmp28 = tmp26 + tmp27
tmp30 = tmp28 + tmp29
tmp32 = tmp30 + tmp31
tmp33 = tmp32 + tmp14
tmp34 = tmp25 / tmp33
tmp35 = tmp34 * tmp17
tmp36 = tmp18 + tmp35
tmp37 = tl.broadcast_to(tmp36, [XBLOCK, RBLOCK])
tmp39 = tl.sum(tmp37, 1)[:, None]
tmp40 = 4.0
tmp41 = tmp39 / tmp40
tmp44 = 2.0
tmp45 = tmp43 / tmp44
tmp46 = tmp41 + tmp45
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp41, None)
tl.debug_barrier()
tl.store(in_out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp45, None)
tl.store(out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp46, None)
def call(args):
arg0_1, arg1_1, arg2_1, arg3_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg2_1, (4, 4, 1), (4, 1, 1))
assert_size_stride(arg3_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((), (), torch.float32)
buf9 = empty_strided_cuda((), (), torch.float32)
get_raw_stream(0)
triton_per_fused_max_0[grid(1)](arg1_1, buf0, buf9, 1, 256,
num_warps=2, num_stages=1)
buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf10 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf12 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf11 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf13 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_per_fused__to_copy_abs_bitwise_and_div_ge_gt_le_mul_repeat_sub_sum_1[
grid(16)](arg1_1, arg3_1, buf0, arg2_1, arg0_1, buf9, buf1,
buf3, buf2, buf4, buf10, buf12, buf11, buf13, 16, 16, XBLOCK=8,
num_warps=2, num_stages=1)
del arg0_1
del arg1_1
del arg2_1
del arg3_1
buf5 = empty_strided_cuda((4,), (1,), torch.float32)
triton_poi_fused_add_div_mul_sum_2[grid(4)](buf1, buf2, buf3, buf4,
buf5, 4, XBLOCK=4, num_warps=1, num_stages=1)
del buf1
del buf2
del buf3
del buf4
buf6 = torch.ops.aten.topk.default(buf5, 2)
del buf5
buf7 = buf6[0]
del buf6
buf17 = buf9
del buf9
triton_per_fused_mean_3[grid(1)](buf7, buf17, 1, 2, XBLOCK=1,
num_warps=2, num_stages=1)
del buf7
buf15 = buf0
del buf0
buf16 = buf15
del buf15
buf18 = buf17
del buf17
buf19 = empty_strided_cuda((), (), torch.float32)
triton_per_fused_add_div_mean_mul_sum_4[grid(1)](buf16, buf18,
buf10, buf11, buf12, buf13, buf19, 1, 4, XBLOCK=1, num_warps=2,
num_stages=1)
del buf10
del buf11
del buf12
del buf13
return buf19, buf16, buf18
class VisErrorLossNew(nn.Module):
def __init__(self):
super(VisErrorLossNew, self).__init__()
def compute_l1_weighted_loss(self, hm_targets, hm_preds, vismap, ohem=1.0):
"""
:param hm_targets: [batch size, keypoint number, h, w]
:param hm_preds: [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
epsilon = 0.0001
hm_preds = F.relu(hm_preds, False)
amplitude = torch.max(hm_targets)
b, k, h, w = hm_targets.size()
hm_targets = hm_targets.view(b, k, -1)
hm_preds = hm_preds.view(b, k, -1)
vismap = vismap.view(b, k, 1).repeat(1, 1, h * w)
pos_ids = (hm_targets > amplitude / 10) & (vismap >= 0)
neg_ids = (hm_targets <= amplitude / 10) & (vismap >= 0)
diff = (hm_targets - hm_preds).abs()
pos_loss = (diff * pos_ids.float()).sum(2).sum(0) / (pos_ids.float(
).sum(2).sum(0) + epsilon)
neg_loss = (diff * neg_ids.float()).sum(2).sum(0) / (neg_ids.float(
).sum(2).sum(0) + epsilon)
total_loss = 0.5 * pos_loss + 0.5 * neg_loss
if ohem < 1:
k = int(total_loss.size(0) * ohem)
total_loss, _ = total_loss.topk(k)
return total_loss.mean()
def compute_l2_loss(self, hm_targets, hm_preds, vismap, ohem=1.0):
"""
:param hm_targets: [batch size, keypoint number, h, w]
:param hm_preds: [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
epsilon = 0.0001
hm_preds = F.relu(hm_preds, False)
b, k, h, w = hm_targets.size()
hm_targets = hm_targets.view(b, k, -1)
hm_preds = hm_preds.view(b, k, -1)
vismap = vismap.view(b, k, 1).repeat(1, 1, h * w)
ids = vismap == 1
diff = (hm_targets - hm_preds) ** 2
total_loss = (diff * ids.float()).sum(2).sum(0) / (ids.float().sum(
2).sum(0) + epsilon)
if ohem < 1:
k = int(total_loss.size(0) * ohem)
total_loss, _ = total_loss.topk(k)
return total_loss.mean()
def forward(self, input_0, input_1, input_2, input_3):
arg0_1 = input_0
arg1_1 = input_1
arg3_1 = input_2
arg2_1 = input_3
output = call([arg0_1, arg1_1, arg2_1, arg3_1])
return output[0], output[1], output[2]
|
gathierry/FashionAI-KeyPointsDetectionOfApparel
|
VisErrorLoss
| false
| 15,426
|
[
"Apache-2.0"
] | 174
|
2e0942b42b4a9cd974cdddc151675738dc8a8cb4
|
https://github.com/gathierry/FashionAI-KeyPointsDetectionOfApparel/tree/2e0942b42b4a9cd974cdddc151675738dc8a8cb4
|
GroupedMultiHeadAttention
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class Linear(nn.Linear):
def __init__(self, in_features, out_features, bias=True):
super(Linear, self).__init__(in_features=in_features, out_features=
out_features, bias=bias)
self.noise = None
self.vn_std = None
def init_vn(self, vn_std):
self.vn_std = vn_std
def sample_synaptic_noise(self, distributed):
self.noise = torch.normal(mean=0.0, std=1.0, size=self.weight.size(
), device=self.weight.device, dtype=self.weight.dtype)
if distributed:
torch.distributed.broadcast(self.noise, 0)
def forward(self, input):
weight = self.weight
if self.noise is not None and self.training:
weight = weight + self.vn_std * self.noise
return F.linear(input, weight, self.bias)
class MultiHeadAttention(nn.Module):
"""Mutli-Head Attention Layer
Args:
dim_model: model feature dimension
num_heads: number of attention heads
References:
Attention Is All You Need, Vaswani et al.
https://arxiv.org/abs/1706.03762
"""
def __init__(self, dim_model, num_heads):
super(MultiHeadAttention, self).__init__()
self.num_heads = num_heads
self.dim_model = dim_model
self.dim_head = dim_model // num_heads
self.query_layer = Linear(self.dim_model, self.dim_model)
self.key_layer = Linear(self.dim_model, self.dim_model)
self.value_layer = Linear(self.dim_model, self.dim_model)
self.output_layer = Linear(self.dim_model, self.dim_model)
def forward(self, Q, K, V, mask=None):
"""Scaled Dot-Product Multi-Head Attention
Args:
Q: Query of shape (B, T, D)
K: Key of shape (B, T, D)
V: Value of shape (B, T, D)
mask: Optional position mask of shape (1 or B, 1 or H, 1 or T, 1 or T)
Return:
O: Attention output of shape (B, T, D)
att_w: Attention weights of shape (B, H, T, T)
"""
batch_size = Q.size(0)
Q = self.query_layer(Q)
K = self.key_layer(K)
V = self.value_layer(V)
Q = Q.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
K = K.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
V = V.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
att_scores = Q.matmul(K.transpose(2, 3)) / K.shape[-1] ** 0.5
if mask is not None:
att_scores += mask * -1000000000.0
att_w = att_scores.softmax(dim=-1)
O = att_w.matmul(V)
O = O.transpose(1, 2).reshape(batch_size, -1, self.dim_model)
O = self.output_layer(O)
return O, att_w.detach()
def pad(self, Q, K, V, mask, chunk_size):
overflow_Q = Q.size(1) % chunk_size
overflow_KV = K.size(1) % chunk_size
padding_Q = chunk_size - overflow_Q if overflow_Q else 0
padding_KV = chunk_size - overflow_KV if overflow_KV else 0
batch_size, seq_len_KV, _ = K.size()
Q = F.pad(Q, (0, 0, 0, padding_Q), value=0)
K = F.pad(K, (0, 0, 0, padding_KV), value=0)
V = F.pad(V, (0, 0, 0, padding_KV), value=0)
if mask is not None:
if mask.size(2) == 1:
mask = F.pad(mask, pad=(0, padding_KV), value=1)
else:
mask = F.pad(mask, pad=(0, padding_Q, 0, padding_KV), value=1)
elif padding_KV:
mask = F.pad(Q.new_zeros(batch_size, 1, 1, seq_len_KV), pad=(0,
padding_KV), value=1)
return Q, K, V, mask, padding_Q
class GroupedMultiHeadAttention(MultiHeadAttention):
"""Grouped Mutli-Head Attention Layer
Grouped multi-head attention reduces attention complexity from O(T2·D) to O(T2·D/G)
by grouping neighbouring time elements along the feature dimension before applying
scaled dot-product attention.
Args:
dim_model: model feature dimension
num_heads: number of attention heads
group_size: attention group size
"""
def __init__(self, dim_model, num_heads, group_size):
super(GroupedMultiHeadAttention, self).__init__(dim_model, num_heads)
self.group_size = group_size
self.dim_head = self.group_size * dim_model // self.num_heads
def forward(self, Q, K, V, mask=None):
batch_size = Q.size(0)
Q = self.query_layer(Q)
K = self.key_layer(K)
V = self.value_layer(V)
Q, K, V, mask, padding = self.pad(Q, K, V, mask, chunk_size=self.
group_size)
Q = Q.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
K = K.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
V = V.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
att_scores = Q.matmul(K.transpose(2, 3)) / K.shape[-1] ** 0.5
if mask is not None:
mask = mask[:, :, ::self.group_size, ::self.group_size]
att_scores += mask * -1000000000.0
att_w = att_scores.softmax(dim=-1)
O = att_w.matmul(V)
O = O.transpose(1, 2).reshape(batch_size, -1, self.dim_model)
O = O[:, :O.size(1) - padding]
O = self.output_layer(O)
return O, att_w.detach()
def get_inputs():
return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4]), torch.rand([4, 4, 4])
]
def get_init_inputs():
return [[], {'dim_model': 4, 'num_heads': 4, 'group_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import math as tl_math
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__softmax_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 = 1.0
tmp2 = tmp0 * tmp1
tmp3 = tmp2 - tmp2
tmp4 = 0.5
tmp5 = tmp3 * tmp4
tmp6 = tl_math.exp(tmp5)
tmp7 = tmp6 / tmp6
tl.store(in_out_ptr0 + x0, tmp7, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_7, (4, 4), (4, 1))
assert_size_stride(primals_8, (4,), (1,))
assert_size_stride(primals_9, (4, 4, 4), (16, 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)
buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_3, reinterpret_tensor(primals_1, (16,
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((16, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_5, reinterpret_tensor(primals_6, (16,
4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0
), alpha=1, beta=1, out=buf1)
del primals_4
del primals_5
buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_8, reinterpret_tensor(primals_9, (16,
4), (4, 1), 0), reinterpret_tensor(primals_7, (4, 4), (1, 4), 0
), alpha=1, beta=1, out=buf2)
del primals_7
del primals_8
buf3 = empty_strided_cuda((16, 1, 1), (1, 1, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf0, (16, 1, 4), (4, 4, 1),
0), reinterpret_tensor(buf1, (16, 4, 1), (4, 1, 1), 0), out=buf3)
buf4 = reinterpret_tensor(buf3, (4, 4, 1, 1), (4, 1, 1, 1), 0)
del buf3
get_raw_stream(0)
triton_poi_fused__softmax_0[grid(16)](buf4, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf5 = empty_strided_cuda((16, 1, 4), (4, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf4, (16, 1, 1), (1, 1, 1),
0), reinterpret_tensor(buf2, (16, 1, 4), (4, 4, 1), 0), out=buf5)
buf6 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_11, reinterpret_tensor(buf5, (16, 4),
(4, 1), 0), reinterpret_tensor(primals_10, (4, 4), (1, 4), 0),
alpha=1, beta=1, out=buf6)
del primals_11
return reinterpret_tensor(buf6, (4, 4, 4), (16, 4, 1), 0
), buf4, reinterpret_tensor(primals_1, (16, 4), (4, 1), 0
), reinterpret_tensor(primals_6, (16, 4), (4, 1), 0
), reinterpret_tensor(primals_9, (16, 4), (4, 1), 0
), buf4, reinterpret_tensor(buf5, (16, 4), (4, 1), 0
), primals_10, reinterpret_tensor(buf2, (16, 4, 1), (4, 1, 16), 0
), reinterpret_tensor(buf0, (16, 4, 1), (4, 1, 16), 0
), reinterpret_tensor(buf1, (16, 1, 4), (4, 16, 1), 0)
class Linear(nn.Linear):
def __init__(self, in_features, out_features, bias=True):
super(Linear, self).__init__(in_features=in_features, out_features=
out_features, bias=bias)
self.noise = None
self.vn_std = None
def init_vn(self, vn_std):
self.vn_std = vn_std
def sample_synaptic_noise(self, distributed):
self.noise = torch.normal(mean=0.0, std=1.0, size=self.weight.size(
), device=self.weight.device, dtype=self.weight.dtype)
if distributed:
torch.distributed.broadcast(self.noise, 0)
def forward(self, input):
weight = self.weight
if self.noise is not None and self.training:
weight = weight + self.vn_std * self.noise
return F.linear(input, weight, self.bias)
class MultiHeadAttention(nn.Module):
"""Mutli-Head Attention Layer
Args:
dim_model: model feature dimension
num_heads: number of attention heads
References:
Attention Is All You Need, Vaswani et al.
https://arxiv.org/abs/1706.03762
"""
def __init__(self, dim_model, num_heads):
super(MultiHeadAttention, self).__init__()
self.num_heads = num_heads
self.dim_model = dim_model
self.dim_head = dim_model // num_heads
self.query_layer = Linear(self.dim_model, self.dim_model)
self.key_layer = Linear(self.dim_model, self.dim_model)
self.value_layer = Linear(self.dim_model, self.dim_model)
self.output_layer = Linear(self.dim_model, self.dim_model)
def forward(self, Q, K, V, mask=None):
"""Scaled Dot-Product Multi-Head Attention
Args:
Q: Query of shape (B, T, D)
K: Key of shape (B, T, D)
V: Value of shape (B, T, D)
mask: Optional position mask of shape (1 or B, 1 or H, 1 or T, 1 or T)
Return:
O: Attention output of shape (B, T, D)
att_w: Attention weights of shape (B, H, T, T)
"""
batch_size = Q.size(0)
Q = self.query_layer(Q)
K = self.key_layer(K)
V = self.value_layer(V)
Q = Q.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
K = K.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
V = V.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
att_scores = Q.matmul(K.transpose(2, 3)) / K.shape[-1] ** 0.5
if mask is not None:
att_scores += mask * -1000000000.0
att_w = att_scores.softmax(dim=-1)
O = att_w.matmul(V)
O = O.transpose(1, 2).reshape(batch_size, -1, self.dim_model)
O = self.output_layer(O)
return O, att_w.detach()
def pad(self, Q, K, V, mask, chunk_size):
overflow_Q = Q.size(1) % chunk_size
overflow_KV = K.size(1) % chunk_size
padding_Q = chunk_size - overflow_Q if overflow_Q else 0
padding_KV = chunk_size - overflow_KV if overflow_KV else 0
batch_size, seq_len_KV, _ = K.size()
Q = F.pad(Q, (0, 0, 0, padding_Q), value=0)
K = F.pad(K, (0, 0, 0, padding_KV), value=0)
V = F.pad(V, (0, 0, 0, padding_KV), value=0)
if mask is not None:
if mask.size(2) == 1:
mask = F.pad(mask, pad=(0, padding_KV), value=1)
else:
mask = F.pad(mask, pad=(0, padding_Q, 0, padding_KV), value=1)
elif padding_KV:
mask = F.pad(Q.new_zeros(batch_size, 1, 1, seq_len_KV), pad=(0,
padding_KV), value=1)
return Q, K, V, mask, padding_Q
class GroupedMultiHeadAttentionNew(MultiHeadAttention):
"""Grouped Mutli-Head Attention Layer
Grouped multi-head attention reduces attention complexity from O(T2·D) to O(T2·D/G)
by grouping neighbouring time elements along the feature dimension before applying
scaled dot-product attention.
Args:
dim_model: model feature dimension
num_heads: number of attention heads
group_size: attention group size
"""
def __init__(self, dim_model, num_heads, group_size):
super(GroupedMultiHeadAttentionNew, self).__init__(dim_model, num_heads
)
self.group_size = group_size
self.dim_head = self.group_size * dim_model // self.num_heads
def forward(self, input_0, input_1, input_2):
primals_2 = self.query_layer.weight
primals_3 = self.query_layer.bias
primals_4 = self.key_layer.weight
primals_5 = self.key_layer.bias
primals_7 = self.value_layer.weight
primals_8 = self.value_layer.bias
primals_10 = self.output_layer.weight
primals_11 = self.output_layer.bias
primals_1 = input_0
primals_6 = input_1
primals_9 = input_2
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11])
return output[0], output[1]
|
gheyret/EfficientConformer
|
GroupedMultiHeadAttention
| false
| 15,427
|
[
"Apache-2.0"
] | 101
|
b28a0aaa3b182f72abaccbeb12df0402adf96097
|
https://github.com/gheyret/EfficientConformer/tree/b28a0aaa3b182f72abaccbeb12df0402adf96097
|
RelativeThreshold_RegLoss
|
import torch
import torch.nn as nn
import torch.nn.init
class RelativeThreshold_RegLoss(nn.Module):
def __init__(self, threshold, size_average=True):
super(RelativeThreshold_RegLoss, self).__init__()
self.size_average = size_average
self.eps = 1e-07
self.threshold = threshold
def forward(self, preds, targets):
"""
Args:
inputs:(n, h, w, d)
targets:(n, h, w, d)
"""
assert not targets.requires_grad
assert preds.shape == targets.shape, 'dim of preds and targets are different'
dist = torch.abs(preds - targets).view(-1)
baseV = targets.view(-1)
baseV = torch.abs(baseV + self.eps)
relativeDist = torch.div(dist, baseV)
mask = relativeDist.ge(self.threshold)
largerLossVec = torch.masked_select(dist, mask)
loss = torch.mean(largerLossVec)
return loss
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'threshold': 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 math as tl_math
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_abs_add_div_ge_sub_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
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask)
tmp2 = tmp0 - tmp1
tmp3 = tl_math.abs(tmp2)
tmp4 = 1e-07
tmp5 = tmp1 + tmp4
tmp6 = tl_math.abs(tmp5)
tmp7 = tmp3 / tmp6
tmp8 = 4.0
tmp9 = tmp7 >= tmp8
tl.store(out_ptr0 + x0, tmp3, xmask)
tl.store(out_ptr1 + x0, tmp9, 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)
buf1 = empty_strided_cuda((256,), (1,), torch.bool)
get_raw_stream(0)
triton_poi_fused_abs_add_div_ge_sub_0[grid(256)](arg1_1, arg0_1,
buf0, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1)
del arg0_1
del arg1_1
return reinterpret_tensor(buf0, (256,), (1,), 0), buf1
class RelativeThreshold_RegLossNew(nn.Module):
def __init__(self, threshold, size_average=True):
super(RelativeThreshold_RegLossNew, self).__init__()
self.size_average = size_average
self.eps = 1e-07
self.threshold = threshold
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
ginobilinie/medSynthesisV1
|
RelativeThreshold_RegLoss
| false
| 15,428
|
[
"MIT"
] | 166
|
1fd202c5928466ef9b11cfebc4490341899312e7
|
https://github.com/ginobilinie/medSynthesisV1/tree/1fd202c5928466ef9b11cfebc4490341899312e7
|
Conv1d
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class Conv1d(nn.Conv1d):
def __init__(self, in_channels, out_channels, kernel_size, stride=1,
padding='same', dilation=1, groups=1, bias=True):
super(Conv1d, self).__init__(in_channels=in_channels, out_channels=
out_channels, kernel_size=kernel_size, stride=stride, padding=0,
dilation=dilation, groups=groups, bias=bias, padding_mode='zeros')
assert padding in ['valid', 'same', 'causal']
if padding == 'valid':
self.pre_padding = None
elif padding == 'same':
self.pre_padding = nn.ConstantPad1d(padding=((kernel_size - 1) //
2, (kernel_size - 1) // 2), value=0)
elif padding == 'causal':
self.pre_padding = nn.ConstantPad1d(padding=(kernel_size - 1, 0
), value=0)
self.noise = None
self.vn_std = None
def init_vn(self, vn_std):
self.vn_std = vn_std
def sample_synaptic_noise(self, distributed):
self.noise = torch.normal(mean=0.0, std=1.0, size=self.weight.size(
), device=self.weight.device, dtype=self.weight.dtype)
if distributed:
torch.distributed.broadcast(self.noise, 0)
def forward(self, input):
weight = self.weight
if self.noise is not None and self.training:
weight = weight + self.vn_std * self.noise
if self.pre_padding is not None:
input = self.pre_padding(input)
return F.conv1d(input, weight, self.bias, self.stride, self.padding,
self.dilation, self.groups)
def get_inputs():
return [torch.rand([4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 24
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_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 12
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 3
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)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 6), (6, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_constant_pad_nd_0[grid(24)](primals_2, buf0, 24,
XBLOCK=32, num_warps=1, num_stages=1)
del primals_2
buf1 = extern_kernels.convolution(reinterpret_tensor(buf0, (1, 4, 6
), (0, 6, 1), 0), primals_1, stride=(1,), padding=(0,),
dilation=(1,), transposed=False, output_padding=(0,), groups=1,
bias=None)
assert_size_stride(buf1, (1, 4, 3), (12, 3, 1))
buf2 = buf1
del buf1
triton_poi_fused_convolution_1[grid(12)](buf2, primals_3, 12,
XBLOCK=16, num_warps=1, num_stages=1)
del primals_3
return reinterpret_tensor(buf2, (4, 3), (3, 1), 0
), primals_1, reinterpret_tensor(buf0, (1, 4, 6), (24, 6, 1), 0)
class Conv1dNew(nn.Conv1d):
def __init__(self, in_channels, out_channels, kernel_size, stride=1,
padding='same', dilation=1, groups=1, bias=True):
super(Conv1dNew, self).__init__(in_channels=in_channels,
out_channels=out_channels, kernel_size=kernel_size, stride=
stride, padding=0, dilation=dilation, groups=groups, bias=bias,
padding_mode='zeros')
assert padding in ['valid', 'same', 'causal']
if padding == 'valid':
self.pre_padding = None
elif padding == 'same':
self.pre_padding = nn.ConstantPad1d(padding=((kernel_size - 1) //
2, (kernel_size - 1) // 2), value=0)
elif padding == 'causal':
self.pre_padding = nn.ConstantPad1d(padding=(kernel_size - 1, 0
), value=0)
self.noise = None
self.vn_std = None
def init_vn(self, vn_std):
self.vn_std = vn_std
def sample_synaptic_noise(self, distributed):
self.noise = torch.normal(mean=0.0, std=1.0, size=self.weight.size(
), device=self.weight.device, dtype=self.weight.dtype)
if distributed:
torch.distributed.broadcast(self.noise, 0)
def forward(self, input_0):
primals_1 = self.weight
primals_3 = self.bias
primals_2 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
gheyret/EfficientConformer
|
Conv1d
| false
| 15,429
|
[
"Apache-2.0"
] | 101
|
b28a0aaa3b182f72abaccbeb12df0402adf96097
|
https://github.com/gheyret/EfficientConformer/tree/b28a0aaa3b182f72abaccbeb12df0402adf96097
|
GCN
|
import torch
import torch.nn.functional as F
from torch import nn
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
import torch.nn.functional as F
from torch import nn
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=256, num_warps=4, num_stages=1)
buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1))
buf2 = empty_strided_cuda((4, 4, 4, 6), (96, 24, 6, 1), torch.float32)
triton_poi_fused_constant_pad_nd_convolution_1[grid(384)](buf1,
primals_3, buf2, 384, XBLOCK=256, 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]
|
gist-ailab/uoais
|
GCN
| false
| 15,430
|
[
"BSD-2-Clause"
] | 52
|
fb42d9a96cd54daad61c956d8d9d65dd0ebef4c7
|
https://github.com/gist-ailab/uoais/tree/fb42d9a96cd54daad61c956d8d9d65dd0ebef4c7
|
maxPool23DUinit
|
import torch
import torch.nn as nn
import torch.nn.init
class maxPool23DUinit(nn.Module):
def __init__(self, kernel_size, stride, padding=1, dilation=1, nd=2):
super(maxPool23DUinit, self).__init__()
assert nd == 1 or nd == 2 or nd == 3, 'nd is not correctly specified!!!!, it should be {1,2,3}'
if nd == 2:
self.pool1 = nn.MaxPool2d(kernel_size=kernel_size, stride=
stride, padding=padding, dilation=dilation)
elif nd == 3:
self.pool1 = nn.MaxPool3d(kernel_size=kernel_size, stride=
stride, padding=padding, dilation=dilation)
else:
self.pool1 = nn.MaxPool1d(kernel_size=kernel_size, stride=
stride, padding=padding, dilation=dilation)
def forward(self, x):
return self.pool1(x)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'kernel_size': 4, 'stride': 1}]
|
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.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_max_pool2d_with_indices_0(in_ptr0, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 144
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 3 % 3
x0 = xindex % 3
x2 = xindex // 9
x4 = xindex
tmp0 = -1 + x1
tmp1 = tl.full([1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tmp2 & tmp4
tmp6 = -1 + x0
tmp7 = tmp6 >= tmp1
tmp8 = tmp6 < tmp3
tmp9 = tmp7 & tmp8
tmp10 = tmp5 & tmp9
tmp11 = tl.load(in_ptr0 + (-5 + x0 + 4 * x1 + 16 * x2), 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 + x0 + 4 * x1 + 16 * x2), 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 + x0 + 4 * x1 + 16 * x2), tmp23 & xmask,
other=float('-inf'))
tmp25 = triton_helpers.maximum(tmp24, tmp18)
tmp26 = 2 + x0
tmp27 = tmp26 >= tmp1
tmp28 = tmp26 < tmp3
tmp29 = tmp27 & tmp28
tmp30 = tmp5 & tmp29
tmp31 = tl.load(in_ptr0 + (-2 + x0 + 4 * x1 + 16 * x2), tmp30 & xmask,
other=float('-inf'))
tmp32 = triton_helpers.maximum(tmp31, tmp25)
tmp33 = x1
tmp34 = tmp33 >= tmp1
tmp35 = tmp33 < tmp3
tmp36 = tmp34 & tmp35
tmp37 = tmp36 & tmp9
tmp38 = tl.load(in_ptr0 + (-1 + x0 + 4 * x1 + 16 * x2), tmp37 & xmask,
other=float('-inf'))
tmp39 = triton_helpers.maximum(tmp38, tmp32)
tmp40 = tmp36 & tmp15
tmp41 = tl.load(in_ptr0 + (x0 + 4 * x1 + 16 * x2), tmp40 & xmask, other
=float('-inf'))
tmp42 = triton_helpers.maximum(tmp41, tmp39)
tmp43 = tmp36 & tmp22
tmp44 = tl.load(in_ptr0 + (1 + x0 + 4 * x1 + 16 * x2), tmp43 & xmask,
other=float('-inf'))
tmp45 = triton_helpers.maximum(tmp44, tmp42)
tmp46 = tmp36 & tmp29
tmp47 = tl.load(in_ptr0 + (2 + x0 + 4 * x1 + 16 * x2), tmp46 & xmask,
other=float('-inf'))
tmp48 = triton_helpers.maximum(tmp47, tmp45)
tmp49 = 1 + x1
tmp50 = tmp49 >= tmp1
tmp51 = tmp49 < tmp3
tmp52 = tmp50 & tmp51
tmp53 = tmp52 & tmp9
tmp54 = tl.load(in_ptr0 + (3 + x0 + 4 * x1 + 16 * x2), tmp53 & xmask,
other=float('-inf'))
tmp55 = triton_helpers.maximum(tmp54, tmp48)
tmp56 = tmp52 & tmp15
tmp57 = tl.load(in_ptr0 + (4 + x0 + 4 * x1 + 16 * x2), tmp56 & xmask,
other=float('-inf'))
tmp58 = triton_helpers.maximum(tmp57, tmp55)
tmp59 = tmp52 & tmp22
tmp60 = tl.load(in_ptr0 + (5 + x0 + 4 * x1 + 16 * x2), tmp59 & xmask,
other=float('-inf'))
tmp61 = triton_helpers.maximum(tmp60, tmp58)
tmp62 = tmp52 & tmp29
tmp63 = tl.load(in_ptr0 + (6 + x0 + 4 * x1 + 16 * x2), tmp62 & xmask,
other=float('-inf'))
tmp64 = triton_helpers.maximum(tmp63, tmp61)
tmp65 = 2 + x1
tmp66 = tmp65 >= tmp1
tmp67 = tmp65 < tmp3
tmp68 = tmp66 & tmp67
tmp69 = tmp68 & tmp9
tmp70 = tl.load(in_ptr0 + (7 + x0 + 4 * x1 + 16 * x2), tmp69 & xmask,
other=float('-inf'))
tmp71 = triton_helpers.maximum(tmp70, tmp64)
tmp72 = tmp68 & tmp15
tmp73 = tl.load(in_ptr0 + (8 + x0 + 4 * x1 + 16 * x2), tmp72 & xmask,
other=float('-inf'))
tmp74 = triton_helpers.maximum(tmp73, tmp71)
tmp75 = tmp68 & tmp22
tmp76 = tl.load(in_ptr0 + (9 + x0 + 4 * x1 + 16 * x2), tmp75 & xmask,
other=float('-inf'))
tmp77 = triton_helpers.maximum(tmp76, tmp74)
tmp78 = tmp68 & tmp29
tmp79 = tl.load(in_ptr0 + (10 + x0 + 4 * x1 + 16 * x2), tmp78 & xmask,
other=float('-inf'))
tmp80 = triton_helpers.maximum(tmp79, tmp77)
tl.store(out_ptr0 + x4, tmp80, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 3, 3), (36, 9, 3, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_max_pool2d_with_indices_0[grid(144)](arg0_1, buf0,
144, XBLOCK=256, num_warps=4, num_stages=1)
del arg0_1
return buf0,
class maxPool23DUinitNew(nn.Module):
def __init__(self, kernel_size, stride, padding=1, dilation=1, nd=2):
super(maxPool23DUinitNew, self).__init__()
assert nd == 1 or nd == 2 or nd == 3, 'nd is not correctly specified!!!!, it should be {1,2,3}'
if nd == 2:
self.pool1 = nn.MaxPool2d(kernel_size=kernel_size, stride=
stride, padding=padding, dilation=dilation)
elif nd == 3:
self.pool1 = nn.MaxPool3d(kernel_size=kernel_size, stride=
stride, padding=padding, dilation=dilation)
else:
self.pool1 = nn.MaxPool1d(kernel_size=kernel_size, stride=
stride, padding=padding, dilation=dilation)
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
ginobilinie/medSynthesisV1
|
maxPool23DUinit
| false
| 15,431
|
[
"MIT"
] | 166
|
1fd202c5928466ef9b11cfebc4490341899312e7
|
https://github.com/ginobilinie/medSynthesisV1/tree/1fd202c5928466ef9b11cfebc4490341899312e7
|
residualUnit
|
import torch
import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torch.nn.init as init
import torch.nn.init
class conv23DUnit(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size, stride=1,
padding=0, groups=1, bias=True, dilation=1, nd=2):
super(conv23DUnit, self).__init__()
assert nd == 1 or nd == 2 or nd == 3, 'nd is not correctly specified!!!!, it should be {1,2,3}'
if nd == 2:
self.conv = nn.Conv2d(in_channels, out_channels, kernel_size,
stride=stride, padding=padding, groups=groups, bias=bias,
dilation=dilation)
elif nd == 3:
self.conv = nn.Conv3d(in_channels, out_channels, kernel_size,
stride=stride, padding=padding, groups=groups, bias=bias,
dilation=dilation)
else:
self.conv = nn.Conv1d(in_channels, out_channels, kernel_size,
stride=stride, padding=padding, groups=groups, bias=bias,
dilation=dilation)
init.xavier_uniform(self.conv.weight, gain=np.sqrt(2.0))
init.constant(self.conv.bias, 0)
def forward(self, x):
return self.conv(x)
class residualUnit(nn.Module):
def __init__(self, in_size, out_size, kernel_size=3, stride=1, padding=
1, activation=F.relu, nd=2):
super(residualUnit, self).__init__()
self.conv1 = conv23DUnit(in_size, out_size, kernel_size, stride,
padding, nd=nd)
self.conv2 = conv23DUnit(out_size, out_size, kernel_size, stride,
padding, nd=nd)
def forward(self, x):
return F.relu(self.conv2(F.elu(self.conv1(x))) + x)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_size': 4, 'out_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torch.nn.init as init
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_elu_0(in_out_ptr0, in_ptr0, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.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, tmp2, xmask)
tl.store(out_ptr0 + x3, tmp9, xmask)
@triton.jit
def triton_poi_fused_add_convolution_relu_threshold_backward_1(in_out_ptr0,
in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x3, xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp5 = tl.full([1], 0, tl.int32)
tmp6 = triton_helpers.maximum(tmp5, tmp4)
tmp7 = 0.0
tmp8 = tmp6 <= tmp7
tl.store(in_out_ptr0 + x3, tmp6, xmask)
tl.store(out_ptr0 + x3, tmp8, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1))
buf1 = buf0
del buf0
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_convolution_elu_0[grid(256)](buf1, primals_2, buf2,
256, XBLOCK=128, num_warps=4, num_stages=1)
del primals_2
buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf3, (4, 4, 4, 4), (64, 16, 4, 1))
buf4 = buf3
del buf3
buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
triton_poi_fused_add_convolution_relu_threshold_backward_1[grid(256)](
buf4, primals_5, primals_3, buf5, 256, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_5
return buf4, primals_1, primals_3, primals_4, buf1, buf2, buf5
class conv23DUnit(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size, stride=1,
padding=0, groups=1, bias=True, dilation=1, nd=2):
super(conv23DUnit, self).__init__()
assert nd == 1 or nd == 2 or nd == 3, 'nd is not correctly specified!!!!, it should be {1,2,3}'
if nd == 2:
self.conv = nn.Conv2d(in_channels, out_channels, kernel_size,
stride=stride, padding=padding, groups=groups, bias=bias,
dilation=dilation)
elif nd == 3:
self.conv = nn.Conv3d(in_channels, out_channels, kernel_size,
stride=stride, padding=padding, groups=groups, bias=bias,
dilation=dilation)
else:
self.conv = nn.Conv1d(in_channels, out_channels, kernel_size,
stride=stride, padding=padding, groups=groups, bias=bias,
dilation=dilation)
init.xavier_uniform(self.conv.weight, gain=np.sqrt(2.0))
init.constant(self.conv.bias, 0)
def forward(self, x):
return self.conv(x)
class residualUnitNew(nn.Module):
def __init__(self, in_size, out_size, kernel_size=3, stride=1, padding=
1, activation=F.relu, nd=2):
super(residualUnitNew, self).__init__()
self.conv1 = conv23DUnit(in_size, out_size, kernel_size, stride,
padding, nd=nd)
self.conv2 = conv23DUnit(out_size, out_size, kernel_size, stride,
padding, nd=nd)
def forward(self, input_0):
primals_1 = self.conv1.conv.weight
primals_2 = self.conv1.conv.bias
primals_4 = self.conv2.conv.weight
primals_5 = self.conv2.conv.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
ginobilinie/medSynthesisV1
|
residualUnit
| false
| 15,432
|
[
"MIT"
] | 166
|
1fd202c5928466ef9b11cfebc4490341899312e7
|
https://github.com/ginobilinie/medSynthesisV1/tree/1fd202c5928466ef9b11cfebc4490341899312e7
|
PACRRConvMax2dModule
|
import torch
class PACRRConvMax2dModule(torch.nn.Module):
def __init__(self, shape, n_filters, k, channels):
super().__init__()
self.shape = shape
if shape != 1:
self.pad = torch.nn.ConstantPad2d((0, shape - 1, 0, shape - 1), 0)
else:
self.pad = None
self.conv = torch.nn.Conv2d(channels, n_filters, shape)
self.activation = torch.nn.ReLU()
self.k = k
self.shape = shape
self.channels = channels
def forward(self, simmat):
BATCH, _CHANNELS, QLEN, DLEN = simmat.shape
if self.pad:
simmat = self.pad(simmat)
conv = self.activation(self.conv(simmat))
top_filters, _ = conv.max(dim=1)
if DLEN < self.k:
top_filters = torch.nn.functional.pad(top_filters, (0, self.k -
DLEN))
top_toks, _ = top_filters.topk(self.k, dim=2)
result = top_toks.reshape(BATCH, QLEN, self.k)
return result
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'shape': 4, 'n_filters': 4, 'k': 4, '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
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 784
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 7 % 7
x0 = xindex % 7
x2 = xindex // 49
x3 = xindex
tmp0 = x1
tmp1 = tl.full([1], 4, tl.int64)
tmp2 = tmp0 < tmp1
tmp3 = x0
tmp4 = tmp3 < tmp1
tmp5 = tmp2 & tmp4
tmp6 = tl.load(in_ptr0 + (x0 + 4 * x1 + 16 * x2), tmp5 & xmask, other=0.0)
tl.store(out_ptr0 + x3, tmp6, xmask)
@triton.jit
def triton_poi_fused_convolution_max_relu_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 % 16
x1 = xindex // 16
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask)
tmp1 = tl.load(in_ptr1 + 0)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
tmp6 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask)
tmp7 = tl.load(in_ptr1 + 1)
tmp8 = tl.broadcast_to(tmp7, [XBLOCK])
tmp26 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask)
tmp27 = tl.load(in_ptr1 + 2)
tmp28 = tl.broadcast_to(tmp27, [XBLOCK])
tmp45 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask)
tmp46 = tl.load(in_ptr1 + 3)
tmp47 = tl.broadcast_to(tmp46, [XBLOCK])
tmp3 = tmp0 + tmp2
tmp4 = tl.full([1], 0, tl.int32)
tmp5 = triton_helpers.maximum(tmp4, tmp3)
tmp9 = tmp6 + tmp8
tmp10 = triton_helpers.maximum(tmp4, tmp9)
tmp11 = tmp5 > tmp10
tmp12 = tmp5 == tmp10
tmp13 = tmp5 != tmp5
tmp14 = tmp10 != tmp10
tmp15 = tmp13 > tmp14
tmp16 = tmp11 | tmp15
tmp17 = tmp13 & tmp14
tmp18 = tmp12 | tmp17
tmp19 = tl.full([1], 0, tl.int64)
tmp20 = tl.full([1], 1, tl.int64)
tmp21 = tmp19 < tmp20
tmp22 = tmp18 & tmp21
tmp23 = tmp16 | tmp22
tmp24 = tl.where(tmp23, tmp5, tmp10)
tmp25 = tl.where(tmp23, tmp19, tmp20)
tmp29 = tmp26 + tmp28
tmp30 = triton_helpers.maximum(tmp4, tmp29)
tmp31 = tmp24 > tmp30
tmp32 = tmp24 == tmp30
tmp33 = tmp24 != tmp24
tmp34 = tmp30 != tmp30
tmp35 = tmp33 > tmp34
tmp36 = tmp31 | tmp35
tmp37 = tmp33 & tmp34
tmp38 = tmp32 | tmp37
tmp39 = tl.full([1], 2, tl.int64)
tmp40 = tmp25 < tmp39
tmp41 = tmp38 & tmp40
tmp42 = tmp36 | tmp41
tmp43 = tl.where(tmp42, tmp24, tmp30)
tmp44 = tl.where(tmp42, tmp25, tmp39)
tmp48 = tmp45 + tmp47
tmp49 = triton_helpers.maximum(tmp4, tmp48)
tmp50 = tmp43 > tmp49
tmp51 = tmp43 == tmp49
tmp52 = tmp43 != tmp43
tmp53 = tmp49 != tmp49
tmp54 = tmp52 > tmp53
tmp55 = tmp50 | tmp54
tmp56 = tmp52 & tmp53
tmp57 = tmp51 | tmp56
tmp58 = tl.full([1], 3, tl.int64)
tmp59 = tmp44 < tmp58
tmp60 = tmp57 & tmp59
tmp61 = tmp55 | tmp60
tl.where(tmp61, tmp43, tmp49)
tmp63 = tl.where(tmp61, tmp44, tmp58)
tmp64 = triton_helpers.maximum(tmp5, tmp10)
tmp65 = triton_helpers.maximum(tmp64, tmp30)
tmp66 = triton_helpers.maximum(tmp65, tmp49)
tl.store(out_ptr0 + x2, tmp63, xmask)
tl.store(out_ptr1 + x2, tmp66, xmask)
@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_2(in_ptr0, in_ptr1,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
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 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(out_ptr0 + x3, tmp6, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_3, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 7, 7), (196, 49, 7, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_constant_pad_nd_0[grid(784)](primals_1, buf0, 784,
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 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.int64)
buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_convolution_max_relu_1[grid(64)](buf1, primals_3,
buf2, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf4 = torch.ops.aten.topk.default(buf3, 4, 2)
del buf3
buf5 = buf4[0]
buf6 = buf4[1]
del buf4
buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
triton_poi_fused_convolution_relu_threshold_backward_2[grid(256)](buf1,
primals_3, buf7, 256, XBLOCK=256, num_warps=4, num_stages=1)
del buf1
del primals_3
return buf5, primals_2, buf0, buf6, reinterpret_tensor(buf2, (4, 1, 4,
4), (16, 16, 4, 1), 0), buf7
class PACRRConvMax2dModuleNew(torch.nn.Module):
def __init__(self, shape, n_filters, k, channels):
super().__init__()
self.shape = shape
if shape != 1:
self.pad = torch.nn.ConstantPad2d((0, shape - 1, 0, shape - 1), 0)
else:
self.pad = None
self.conv = torch.nn.Conv2d(channels, n_filters, shape)
self.activation = torch.nn.ReLU()
self.k = k
self.shape = shape
self.channels = channels
def forward(self, input_0):
primals_1 = self.conv.weight
primals_3 = self.conv.bias
primals_2 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
gitter-badger/FlexNeuART
|
PACRRConvMax2dModule
| false
| 15,433
|
[
"Apache-2.0"
] | 101
|
f69e5421bdebe9db0d993b5470dace61872f90df
|
https://github.com/gitter-badger/FlexNeuART/tree/f69e5421bdebe9db0d993b5470dace61872f90df
|
VisErrorLossV3
|
import torch
import torch.nn.functional as F
from torch import nn
class VisErrorLossV3(nn.Module):
def __init__(self):
super(VisErrorLossV3, self).__init__()
def compute_l1_weighted_loss(self, hm_targets, hm_preds, vismap, ohem=1.0):
"""
:param hm_targets: [batch size, keypoint number, h, w]
:param hm_preds: [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
epsilon = 0.0001
hm_preds = F.relu(hm_preds, False)
amplitude = torch.max(hm_targets)
b, k, h, w = hm_targets.size()
hm_targets = hm_targets.view(b, k, -1)
hm_preds = hm_preds.view(b, k, -1)
vismap = vismap.view(b, k, 1).repeat(1, 1, h * w)
pos_ids = (hm_targets > amplitude / 10) & (vismap == 1)
neg_ids = (hm_targets <= amplitude / 10) & (vismap == 1)
diff = (hm_targets - hm_preds).abs()
pos_loss = (diff * pos_ids.float()).sum(2).sum(0) / (pos_ids.float(
).sum(2).sum(0) + epsilon)
neg_loss = (diff * neg_ids.float()).sum(2).sum(0) / (neg_ids.float(
).sum(2).sum(0) + epsilon)
total_loss = 0.5 * pos_loss + 0.5 * neg_loss
if ohem < 1:
k = int(total_loss.size(0) * ohem)
total_loss, _ = total_loss.topk(k)
return total_loss.mean()
def compute_l2_loss(self, hm_targets, hm_preds, vismap, ohem=1.0):
"""
:param hm_targets: [batch size, keypoint number, h, w]
:param hm_preds: [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
epsilon = 0.0001
hm_preds = F.relu(hm_preds, False)
b, k, h, w = hm_targets.size()
hm_targets = hm_targets.view(b, k, -1)
hm_preds = hm_preds.view(b, k, -1)
vismap = vismap.view(b, k, 1).repeat(1, 1, h * w)
ids = vismap == 1
diff = (hm_targets - hm_preds) ** 2
total_loss = (diff * ids.float()).sum(2).sum(0) / (ids.float().sum(
2).sum(0) + epsilon)
if ohem < 1:
k = int(total_loss.size(0) * ohem)
total_loss, _ = total_loss.topk(k)
return total_loss.mean()
def forward(self, hm_targets, hm_preds1, hm_preds2, vismap):
"""
:param hm_targets: [batch size, keypoint number, h, w]
:param hm_preds: [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
loss1 = self.compute_l1_weighted_loss(hm_targets, hm_preds1, vismap)
loss2 = self.compute_l1_weighted_loss(hm_targets, hm_preds2[0],
vismap, ohem=0.5)
loss3 = self.compute_l1_weighted_loss(hm_targets, hm_preds2[1],
vismap, ohem=0.3)
return loss1 + loss2 + loss3, loss1, loss2, loss3
def get_inputs():
return [torch.rand([4, 4, 16, 4]), torch.rand([4, 4, 64]), torch.rand([
4, 4, 4]), torch.rand([4, 4, 1])]
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.functional as F
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_per_fused_max_0(in_ptr0, out_ptr0, out_ptr1, out_ptr2, 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)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
tmp3 = triton_helpers.promote_to_tensor(triton_helpers.max2(tmp1, 0))
tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp3, None)
tl.store(out_ptr1 + tl.full([1], 0, tl.int32), tmp3, None)
tl.store(out_ptr2 + tl.full([1], 0, tl.int32), tmp3, None)
@triton.jit
def triton_per_fused__to_copy_abs_bitwise_and_div_eq_gt_le_mul_relu_repeat_sub_sum_view_1(
in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, out_ptr0,
out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5, out_ptr6, out_ptr7,
out_ptr8, out_ptr9, out_ptr10, out_ptr11, xnumel, rnumel, XBLOCK: tl.
constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0)
tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr2 + 0)
tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
tmp11 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
tmp37 = tl.load(in_ptr1 + (16 + x0), xmask, eviction_policy='evict_last')
tmp41 = tl.load(in_ptr4 + 0)
tmp42 = tl.broadcast_to(tmp41, [XBLOCK, RBLOCK])
tmp68 = tl.load(in_ptr5 + (r1 + 64 * x0), xmask, other=0.0)
tmp72 = tl.load(in_ptr6 + 0)
tmp73 = tl.broadcast_to(tmp72, [XBLOCK, RBLOCK])
tmp2 = tl.full([1, 1], 0, tl.int32)
tmp3 = triton_helpers.maximum(tmp2, tmp1)
tmp4 = tmp0 - tmp3
tmp5 = tl_math.abs(tmp4)
tmp8 = 0.1
tmp9 = tmp7 * tmp8
tmp10 = tmp0 > tmp9
tmp12 = 1.0
tmp13 = tmp11 == tmp12
tmp14 = tmp10 & tmp13
tmp15 = tmp14.to(tl.float32)
tmp16 = tmp5 * tmp15
tmp17 = tl.broadcast_to(tmp16, [XBLOCK, RBLOCK])
tmp19 = tl.where(xmask, tmp17, 0)
tmp20 = tl.sum(tmp19, 1)[:, None]
tmp21 = tmp0 <= tmp9
tmp22 = tmp21 & tmp13
tmp23 = tmp22.to(tl.float32)
tmp24 = tmp5 * tmp23
tmp25 = tl.broadcast_to(tmp24, [XBLOCK, RBLOCK])
tmp27 = tl.where(xmask, tmp25, 0)
tmp28 = tl.sum(tmp27, 1)[:, None]
tmp29 = tl.broadcast_to(tmp15, [XBLOCK, RBLOCK])
tmp31 = tl.where(xmask, tmp29, 0)
tmp32 = tl.sum(tmp31, 1)[:, None]
tmp33 = tl.broadcast_to(tmp23, [XBLOCK, RBLOCK])
tmp35 = tl.where(xmask, tmp33, 0)
tmp36 = tl.sum(tmp35, 1)[:, None]
tmp38 = triton_helpers.maximum(tmp2, tmp37)
tmp39 = tmp0 - tmp38
tmp40 = tl_math.abs(tmp39)
tmp43 = tmp42 * tmp8
tmp44 = tmp0 > tmp43
tmp45 = tmp44 & tmp13
tmp46 = tmp45.to(tl.float32)
tmp47 = tmp40 * tmp46
tmp48 = tl.broadcast_to(tmp47, [XBLOCK, RBLOCK])
tmp50 = tl.where(xmask, tmp48, 0)
tmp51 = tl.sum(tmp50, 1)[:, None]
tmp52 = tmp0 <= tmp43
tmp53 = tmp52 & tmp13
tmp54 = tmp53.to(tl.float32)
tmp55 = tmp40 * tmp54
tmp56 = tl.broadcast_to(tmp55, [XBLOCK, RBLOCK])
tmp58 = tl.where(xmask, tmp56, 0)
tmp59 = tl.sum(tmp58, 1)[:, None]
tmp60 = tl.broadcast_to(tmp46, [XBLOCK, RBLOCK])
tmp62 = tl.where(xmask, tmp60, 0)
tmp63 = tl.sum(tmp62, 1)[:, None]
tmp64 = tl.broadcast_to(tmp54, [XBLOCK, RBLOCK])
tmp66 = tl.where(xmask, tmp64, 0)
tmp67 = tl.sum(tmp66, 1)[:, None]
tmp69 = triton_helpers.maximum(tmp2, tmp68)
tmp70 = tmp0 - tmp69
tmp71 = tl_math.abs(tmp70)
tmp74 = tmp73 * tmp8
tmp75 = tmp0 > tmp74
tmp76 = tmp75 & tmp13
tmp77 = tmp76.to(tl.float32)
tmp78 = tmp71 * tmp77
tmp79 = tl.broadcast_to(tmp78, [XBLOCK, RBLOCK])
tmp81 = tl.where(xmask, tmp79, 0)
tmp82 = tl.sum(tmp81, 1)[:, None]
tmp83 = tmp0 <= tmp74
tmp84 = tmp83 & tmp13
tmp85 = tmp84.to(tl.float32)
tmp86 = tmp71 * tmp85
tmp87 = tl.broadcast_to(tmp86, [XBLOCK, RBLOCK])
tmp89 = tl.where(xmask, tmp87, 0)
tmp90 = tl.sum(tmp89, 1)[:, None]
tmp91 = tl.broadcast_to(tmp77, [XBLOCK, RBLOCK])
tmp93 = tl.where(xmask, tmp91, 0)
tmp94 = tl.sum(tmp93, 1)[:, None]
tmp95 = tl.broadcast_to(tmp85, [XBLOCK, RBLOCK])
tmp97 = tl.where(xmask, tmp95, 0)
tmp98 = tl.sum(tmp97, 1)[:, None]
tl.store(out_ptr0 + x0, tmp20, xmask)
tl.store(out_ptr1 + x0, tmp28, xmask)
tl.store(out_ptr2 + x0, tmp32, xmask)
tl.store(out_ptr3 + x0, tmp36, xmask)
tl.store(out_ptr4 + x0, tmp51, xmask)
tl.store(out_ptr5 + x0, tmp59, xmask)
tl.store(out_ptr6 + x0, tmp63, xmask)
tl.store(out_ptr7 + x0, tmp67, xmask)
tl.store(out_ptr8 + x0, tmp82, xmask)
tl.store(out_ptr9 + x0, tmp90, xmask)
tl.store(out_ptr10 + x0, tmp94, xmask)
tl.store(out_ptr11 + x0, tmp98, xmask)
@triton.jit
def triton_poi_fused_add_div_mul_sum_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + (4 + x0), xmask)
tmp3 = tl.load(in_ptr0 + (8 + x0), xmask)
tmp5 = tl.load(in_ptr0 + (12 + x0), xmask)
tmp7 = tl.load(in_ptr1 + x0, xmask)
tmp8 = tl.load(in_ptr1 + (4 + x0), xmask)
tmp10 = tl.load(in_ptr1 + (8 + x0), xmask)
tmp12 = tl.load(in_ptr1 + (12 + x0), xmask)
tmp19 = tl.load(in_ptr2 + x0, xmask)
tmp20 = tl.load(in_ptr2 + (4 + x0), xmask)
tmp22 = tl.load(in_ptr2 + (8 + x0), xmask)
tmp24 = tl.load(in_ptr2 + (12 + x0), xmask)
tmp26 = tl.load(in_ptr3 + x0, xmask)
tmp27 = tl.load(in_ptr3 + (4 + x0), xmask)
tmp29 = tl.load(in_ptr3 + (8 + x0), xmask)
tmp31 = tl.load(in_ptr3 + (12 + x0), xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp9 = tmp7 + tmp8
tmp11 = tmp9 + tmp10
tmp13 = tmp11 + tmp12
tmp14 = 0.0001
tmp15 = tmp13 + tmp14
tmp16 = tmp6 / tmp15
tmp17 = 0.5
tmp18 = tmp16 * tmp17
tmp21 = tmp19 + tmp20
tmp23 = tmp21 + tmp22
tmp25 = tmp23 + tmp24
tmp28 = tmp26 + tmp27
tmp30 = tmp28 + tmp29
tmp32 = tmp30 + tmp31
tmp33 = tmp32 + tmp14
tmp34 = tmp25 / tmp33
tmp35 = tmp34 * tmp17
tmp36 = tmp18 + tmp35
tl.store(out_ptr0 + x0, tmp36, xmask)
@triton.jit
def triton_per_fused_mean_3(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl.
constexpr):
RBLOCK: tl.constexpr = 2
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.sum(tmp1, 1)[:, None]
tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp3, None)
@triton.jit
def triton_per_fused_add_div_mean_mul_sum_4(in_out_ptr0, in_out_ptr1,
in_out_ptr2, in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr1, xnumel,
rnumel, XBLOCK: tl.constexpr):
RBLOCK: tl.constexpr = 4
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp1 = tl.load(in_ptr0 + (4 + r0), None)
tmp3 = tl.load(in_ptr0 + (8 + r0), None)
tmp5 = tl.load(in_ptr0 + (12 + r0), None)
tmp7 = tl.load(in_ptr1 + r0, None)
tmp8 = tl.load(in_ptr1 + (4 + r0), None)
tmp10 = tl.load(in_ptr1 + (8 + r0), None)
tmp12 = tl.load(in_ptr1 + (12 + r0), None)
tmp19 = tl.load(in_ptr2 + r0, None)
tmp20 = tl.load(in_ptr2 + (4 + r0), None)
tmp22 = tl.load(in_ptr2 + (8 + r0), None)
tmp24 = tl.load(in_ptr2 + (12 + r0), None)
tmp26 = tl.load(in_ptr3 + r0, None)
tmp27 = tl.load(in_ptr3 + (4 + r0), None)
tmp29 = tl.load(in_ptr3 + (8 + r0), None)
tmp31 = tl.load(in_ptr3 + (12 + r0), None)
tmp42 = tl.load(in_out_ptr1 + 0)
tmp43 = tl.broadcast_to(tmp42, [XBLOCK, 1])
tmp46 = tl.load(in_out_ptr2 + 0)
tmp47 = tl.broadcast_to(tmp46, [XBLOCK, 1])
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp9 = tmp7 + tmp8
tmp11 = tmp9 + tmp10
tmp13 = tmp11 + tmp12
tmp14 = 0.0001
tmp15 = tmp13 + tmp14
tmp16 = tmp6 / tmp15
tmp17 = 0.5
tmp18 = tmp16 * tmp17
tmp21 = tmp19 + tmp20
tmp23 = tmp21 + tmp22
tmp25 = tmp23 + tmp24
tmp28 = tmp26 + tmp27
tmp30 = tmp28 + tmp29
tmp32 = tmp30 + tmp31
tmp33 = tmp32 + tmp14
tmp34 = tmp25 / tmp33
tmp35 = tmp34 * tmp17
tmp36 = tmp18 + tmp35
tmp37 = tl.broadcast_to(tmp36, [XBLOCK, RBLOCK])
tmp39 = tl.sum(tmp37, 1)[:, None]
tmp40 = 4.0
tmp41 = tmp39 / tmp40
tmp44 = 2.0
tmp45 = tmp43 / tmp44
tmp48 = 1.0
tmp49 = tmp47 / tmp48
tmp50 = tmp41 + tmp45
tmp51 = tmp50 + tmp49
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp41, None)
tl.debug_barrier()
tl.store(in_out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp45, None)
tl.debug_barrier()
tl.store(in_out_ptr2 + tl.full([XBLOCK, 1], 0, tl.int32), tmp49, None)
tl.store(out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp51, None)
def call(args):
arg0_1, arg1_1, arg2_1, arg3_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 64), (256, 64, 1))
assert_size_stride(arg1_1, (4, 4, 16, 4), (256, 64, 4, 1))
assert_size_stride(arg2_1, (4, 4, 1), (4, 1, 1))
assert_size_stride(arg3_1, (4, 4, 4), (16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((), (), torch.float32)
buf9 = empty_strided_cuda((), (), torch.float32)
buf18 = empty_strided_cuda((), (), torch.float32)
get_raw_stream(0)
triton_per_fused_max_0[grid(1)](arg1_1, buf0, buf9, buf18, 1, 1024,
num_warps=8, num_stages=1)
buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf10 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf12 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf11 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf13 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf19 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf21 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf20 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf22 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_per_fused__to_copy_abs_bitwise_and_div_eq_gt_le_mul_relu_repeat_sub_sum_view_1[
grid(16)](arg1_1, arg3_1, buf0, arg2_1, buf9, arg0_1, buf18,
buf1, buf3, buf2, buf4, buf10, buf12, buf11, buf13, buf19,
buf21, buf20, buf22, 16, 64, XBLOCK=8, num_warps=4, num_stages=1)
del arg0_1
del arg1_1
del arg2_1
del arg3_1
buf5 = empty_strided_cuda((4,), (1,), torch.float32)
triton_poi_fused_add_div_mul_sum_2[grid(4)](buf1, buf2, buf3, buf4,
buf5, 4, XBLOCK=4, num_warps=1, num_stages=1)
del buf1
del buf2
del buf3
del buf4
buf6 = torch.ops.aten.topk.default(buf5, 2)
buf7 = buf6[0]
del buf6
buf14 = buf5
del buf5
triton_poi_fused_add_div_mul_sum_2[grid(4)](buf10, buf11, buf12,
buf13, buf14, 4, XBLOCK=4, num_warps=1, num_stages=1)
del buf10
del buf11
del buf12
del buf13
buf15 = torch.ops.aten.topk.default(buf14, 1)
del buf14
buf16 = buf15[0]
del buf15
buf26 = buf9
del buf9
triton_per_fused_mean_3[grid(1)](buf7, buf26, 1, 2, XBLOCK=1,
num_warps=2, num_stages=1)
del buf7
buf24 = buf18
del buf18
buf25 = buf24
del buf24
buf27 = buf26
del buf26
buf28 = reinterpret_tensor(buf16, (), (), 0)
del buf16
buf29 = buf0
del buf0
triton_per_fused_add_div_mean_mul_sum_4[grid(1)](buf25, buf27,
buf28, buf19, buf20, buf21, buf22, buf29, 1, 4, XBLOCK=1,
num_warps=2, num_stages=1)
del buf19
del buf20
del buf21
del buf22
return buf29, buf25, buf27, buf28
class VisErrorLossV3New(nn.Module):
def __init__(self):
super(VisErrorLossV3New, self).__init__()
def compute_l1_weighted_loss(self, hm_targets, hm_preds, vismap, ohem=1.0):
"""
:param hm_targets: [batch size, keypoint number, h, w]
:param hm_preds: [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
epsilon = 0.0001
hm_preds = F.relu(hm_preds, False)
amplitude = torch.max(hm_targets)
b, k, h, w = hm_targets.size()
hm_targets = hm_targets.view(b, k, -1)
hm_preds = hm_preds.view(b, k, -1)
vismap = vismap.view(b, k, 1).repeat(1, 1, h * w)
pos_ids = (hm_targets > amplitude / 10) & (vismap == 1)
neg_ids = (hm_targets <= amplitude / 10) & (vismap == 1)
diff = (hm_targets - hm_preds).abs()
pos_loss = (diff * pos_ids.float()).sum(2).sum(0) / (pos_ids.float(
).sum(2).sum(0) + epsilon)
neg_loss = (diff * neg_ids.float()).sum(2).sum(0) / (neg_ids.float(
).sum(2).sum(0) + epsilon)
total_loss = 0.5 * pos_loss + 0.5 * neg_loss
if ohem < 1:
k = int(total_loss.size(0) * ohem)
total_loss, _ = total_loss.topk(k)
return total_loss.mean()
def compute_l2_loss(self, hm_targets, hm_preds, vismap, ohem=1.0):
"""
:param hm_targets: [batch size, keypoint number, h, w]
:param hm_preds: [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
epsilon = 0.0001
hm_preds = F.relu(hm_preds, False)
b, k, h, w = hm_targets.size()
hm_targets = hm_targets.view(b, k, -1)
hm_preds = hm_preds.view(b, k, -1)
vismap = vismap.view(b, k, 1).repeat(1, 1, h * w)
ids = vismap == 1
diff = (hm_targets - hm_preds) ** 2
total_loss = (diff * ids.float()).sum(2).sum(0) / (ids.float().sum(
2).sum(0) + epsilon)
if ohem < 1:
k = int(total_loss.size(0) * ohem)
total_loss, _ = total_loss.topk(k)
return total_loss.mean()
def forward(self, input_0, input_1, input_2, input_3):
arg1_1 = input_0
arg0_1 = input_1
arg3_1 = input_2
arg2_1 = input_3
output = call([arg0_1, arg1_1, arg2_1, arg3_1])
return output[0], output[1], output[2], output[3]
|
gathierry/FashionAI-KeyPointsDetectionOfApparel
|
VisErrorLossV3
| false
| 15,434
|
[
"Apache-2.0"
] | 174
|
2e0942b42b4a9cd974cdddc151675738dc8a8cb4
|
https://github.com/gathierry/FashionAI-KeyPointsDetectionOfApparel/tree/2e0942b42b4a9cd974cdddc151675738dc8a8cb4
|
ClusterAssignment
|
import torch
import torch.nn as nn
from torch.nn import Parameter
from typing import Optional
class ClusterAssignment(nn.Module):
def __init__(self, cluster_number: 'int', embedding_dimension: 'int',
alpha: 'float'=1.0, cluster_centers: 'Optional[torch.Tensor]'=None
) ->None:
"""
Module to handle the soft assignment, for a description see in 3.1.1. in Xie/Girshick/Farhadi,
where the Student's t-distribution is used measure similarity between feature vector and each
cluster centroid.
:param cluster_number: number of clusters
:param embedding_dimension: embedding dimension of feature vectors
:param alpha: parameter representing the degrees of freedom in the t-distribution, default 1.0
:param cluster_centers: clusters centers to initialise, if None then use Xavier uniform
"""
super(ClusterAssignment, self).__init__()
self.embedding_dimension = embedding_dimension
self.cluster_number = cluster_number
self.alpha = alpha
if cluster_centers is None:
initial_cluster_centers = torch.zeros(self.cluster_number, self
.embedding_dimension, dtype=torch.float)
nn.init.xavier_uniform_(initial_cluster_centers)
else:
initial_cluster_centers = cluster_centers
self.cluster_centers = Parameter(initial_cluster_centers)
def forward(self, batch: 'torch.Tensor') ->torch.Tensor:
"""
Compute the soft assignment for a batch of feature vectors, returning a batch of assignments
for each cluster.
:param batch: FloatTensor of [batch size, embedding dimension]
:return: FloatTensor [batch size, number of clusters]
"""
norm_squared = torch.sum((batch.unsqueeze(1) - self.cluster_centers
) ** 2, 2)
numerator = 1.0 / (1.0 + norm_squared / self.alpha)
power = float(self.alpha + 1) / 2
numerator = numerator ** power
return numerator / torch.sum(numerator, dim=1, keepdim=True)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'cluster_number': 4, 'embedding_dimension': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
from torch.nn import Parameter
from typing import Optional
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_add_div_mul_pow_reciprocal_sub_sum_0(in_out_ptr0,
in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 16
x1 = xindex // 16
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask)
tmp8 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask)
tmp12 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask)
tmp2 = tmp0 - tmp1
tmp3 = tmp2 * tmp2
tmp5 = tmp4 - tmp1
tmp6 = tmp5 * tmp5
tmp7 = tmp3 + tmp6
tmp9 = tmp8 - tmp1
tmp10 = tmp9 * tmp9
tmp11 = tmp7 + tmp10
tmp13 = tmp12 - tmp1
tmp14 = tmp13 * tmp13
tmp15 = tmp11 + tmp14
tmp16 = 1.0
tmp17 = tmp15 * tmp16
tmp18 = tmp17 + tmp16
tmp19 = tl.full([1], 1, tl.int32)
tmp20 = tmp19 / tmp18
tmp21 = tmp20 * tmp16
tmp22 = tmp21 / tmp21
tl.store(in_out_ptr0 + x2, tmp22, xmask)
def call(args):
primals_1, primals_2 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 1, 4, 4), (16, 64, 4, 1), torch.float32)
buf1 = reinterpret_tensor(buf0, (4, 1, 4, 4), (16, 16, 4, 1), 0)
del buf0
get_raw_stream(0)
triton_poi_fused_add_div_mul_pow_reciprocal_sub_sum_0[grid(64)](buf1,
primals_1, primals_2, 64, XBLOCK=64, num_warps=1, num_stages=1)
return buf1, primals_1, primals_2
class ClusterAssignmentNew(nn.Module):
def __init__(self, cluster_number: 'int', embedding_dimension: 'int',
alpha: 'float'=1.0, cluster_centers: 'Optional[torch.Tensor]'=None
) ->None:
"""
Module to handle the soft assignment, for a description see in 3.1.1. in Xie/Girshick/Farhadi,
where the Student's t-distribution is used measure similarity between feature vector and each
cluster centroid.
:param cluster_number: number of clusters
:param embedding_dimension: embedding dimension of feature vectors
:param alpha: parameter representing the degrees of freedom in the t-distribution, default 1.0
:param cluster_centers: clusters centers to initialise, if None then use Xavier uniform
"""
super(ClusterAssignmentNew, self).__init__()
self.embedding_dimension = embedding_dimension
self.cluster_number = cluster_number
self.alpha = alpha
if cluster_centers is None:
initial_cluster_centers = torch.zeros(self.cluster_number, self
.embedding_dimension, dtype=torch.float)
nn.init.xavier_uniform_(initial_cluster_centers)
else:
initial_cluster_centers = cluster_centers
self.cluster_centers = Parameter(initial_cluster_centers)
def forward(self, input_0):
primals_2 = self.cluster_centers
primals_1 = input_0
output = call([primals_1, primals_2])
return output[0]
|
giorgosVardakas/pt-dec
|
ClusterAssignment
| false
| 15,435
|
[
"MIT"
] | 200
|
c29b9634eb74c828efd9d2b87c613cdb0ddd1dd5
|
https://github.com/giorgosVardakas/pt-dec/tree/c29b9634eb74c828efd9d2b87c613cdb0ddd1dd5
|
SqueezeAndExcitationModule
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class Swish(nn.Module):
def __init__(self):
super(Swish, self).__init__()
def forward(self, x):
return x * x.sigmoid()
class Conv1d(nn.Conv1d):
def __init__(self, in_channels, out_channels, kernel_size, stride=1,
padding='same', dilation=1, groups=1, bias=True):
super(Conv1d, self).__init__(in_channels=in_channels, out_channels=
out_channels, kernel_size=kernel_size, stride=stride, padding=0,
dilation=dilation, groups=groups, bias=bias, padding_mode='zeros')
assert padding in ['valid', 'same', 'causal']
if padding == 'valid':
self.pre_padding = None
elif padding == 'same':
self.pre_padding = nn.ConstantPad1d(padding=((kernel_size - 1) //
2, (kernel_size - 1) // 2), value=0)
elif padding == 'causal':
self.pre_padding = nn.ConstantPad1d(padding=(kernel_size - 1, 0
), value=0)
self.noise = None
self.vn_std = None
def init_vn(self, vn_std):
self.vn_std = vn_std
def sample_synaptic_noise(self, distributed):
self.noise = torch.normal(mean=0.0, std=1.0, size=self.weight.size(
), device=self.weight.device, dtype=self.weight.dtype)
if distributed:
torch.distributed.broadcast(self.noise, 0)
def forward(self, input):
weight = self.weight
if self.noise is not None and self.training:
weight = weight + self.vn_std * self.noise
if self.pre_padding is not None:
input = self.pre_padding(input)
return F.conv1d(input, weight, self.bias, self.stride, self.padding,
self.dilation, self.groups)
class SqueezeAndExcitationModule(nn.Module):
"""Squeeze And Excitation Module
Args:
input_dim: input feature dimension
reduction_ratio: bottleneck reduction ratio
inner_act: bottleneck inner activation function
Input: (batch_size, in_dim, in_length)
Output: (batch_size, out_dim, out_length)
"""
def __init__(self, input_dim, reduction_ratio, inner_act='relu'):
super(SqueezeAndExcitationModule, self).__init__()
assert input_dim % reduction_ratio == 0
self.conv1 = Conv1d(input_dim, input_dim // reduction_ratio,
kernel_size=1)
self.conv2 = Conv1d(input_dim // reduction_ratio, input_dim,
kernel_size=1)
assert inner_act in ['relu', 'swish']
if inner_act == 'relu':
self.inner_act = nn.ReLU()
elif inner_act == 'swish':
self.inner_act = Swish()
def forward(self, x):
scale = x.mean(dim=-1, keepdim=True)
scale = self.conv1(scale)
scale = self.inner_act(scale)
scale = self.conv2(scale)
scale = scale.sigmoid()
x = x * scale
return x
def get_inputs():
return [torch.rand([4, 4])]
def get_init_inputs():
return [[], {'input_dim': 4, 'reduction_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 import triton_helpers
import torch.nn as nn
import torch.nn.functional as F
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_mean_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp7 = 4.0
tmp8 = tmp6 / tmp7
tl.store(out_ptr0 + x0, tmp8, xmask)
@triton.jit
def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
tmp0 = tl.load(in_out_ptr0 + 0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
tmp2 = tl.load(in_ptr0 + 0)
tmp3 = tl.broadcast_to(tmp2, [XBLOCK])
tmp4 = tmp1 + tmp3
tmp5 = tl.full([1], 0, tl.int32)
tmp6 = triton_helpers.maximum(tmp5, tmp4)
tmp7 = 0.0
tmp8 = tmp6 <= tmp7
tl.store(in_out_ptr0 + tl.full([XBLOCK], 0, tl.int32), tmp6, None)
tl.store(out_ptr0 + tl.full([XBLOCK], 0, tl.int32), tmp8, None)
@triton.jit
def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused_mul_sigmoid_3(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
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tl.sigmoid(tmp1)
tmp3 = tmp0 * tmp2
tl.store(out_ptr0 + x2, tmp3, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (1, 4, 1), (4, 1, 1))
assert_size_stride(primals_3, (1,), (1,))
assert_size_stride(primals_4, (4, 1, 1), (1, 1, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_mean_0[grid(4)](primals_1, buf0, 4, XBLOCK=4,
num_warps=1, num_stages=1)
buf1 = extern_kernels.convolution(reinterpret_tensor(buf0, (1, 4, 1
), (0, 1, 0), 0), primals_2, stride=(1,), padding=(0,),
dilation=(1,), transposed=False, output_padding=(0,), groups=1,
bias=None)
assert_size_stride(buf1, (1, 1, 1), (1, 1, 1))
buf2 = reinterpret_tensor(buf1, (1, 1), (1, 1), 0)
del buf1
buf6 = empty_strided_cuda((1, 1), (1, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_1[grid(1)](buf2, primals_3,
buf6, 1, XBLOCK=1, num_warps=1, num_stages=1)
del primals_3
buf3 = extern_kernels.convolution(reinterpret_tensor(buf2, (1, 1, 1
), (0, 0, 0), 0), primals_4, stride=(1,), padding=(0,),
dilation=(1,), transposed=False, output_padding=(0,), groups=1,
bias=None)
assert_size_stride(buf3, (1, 4, 1), (4, 1, 1))
buf4 = buf3
del buf3
triton_poi_fused_convolution_2[grid(4)](buf4, primals_5, 4, XBLOCK=
4, num_warps=1, num_stages=1)
del primals_5
buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused_mul_sigmoid_3[grid(16)](primals_1, buf4, buf5, 16,
XBLOCK=16, num_warps=1, num_stages=1)
return buf5, primals_1, primals_2, primals_4, reinterpret_tensor(buf0,
(1, 4, 1), (4, 1, 1), 0), reinterpret_tensor(buf2, (1, 1, 1), (1, 1,
1), 0), buf4, buf6
class Swish(nn.Module):
def __init__(self):
super(Swish, self).__init__()
def forward(self, x):
return x * x.sigmoid()
class Conv1d(nn.Conv1d):
def __init__(self, in_channels, out_channels, kernel_size, stride=1,
padding='same', dilation=1, groups=1, bias=True):
super(Conv1d, self).__init__(in_channels=in_channels, out_channels=
out_channels, kernel_size=kernel_size, stride=stride, padding=0,
dilation=dilation, groups=groups, bias=bias, padding_mode='zeros')
assert padding in ['valid', 'same', 'causal']
if padding == 'valid':
self.pre_padding = None
elif padding == 'same':
self.pre_padding = nn.ConstantPad1d(padding=((kernel_size - 1) //
2, (kernel_size - 1) // 2), value=0)
elif padding == 'causal':
self.pre_padding = nn.ConstantPad1d(padding=(kernel_size - 1, 0
), value=0)
self.noise = None
self.vn_std = None
def init_vn(self, vn_std):
self.vn_std = vn_std
def sample_synaptic_noise(self, distributed):
self.noise = torch.normal(mean=0.0, std=1.0, size=self.weight.size(
), device=self.weight.device, dtype=self.weight.dtype)
if distributed:
torch.distributed.broadcast(self.noise, 0)
def forward(self, input):
weight = self.weight
if self.noise is not None and self.training:
weight = weight + self.vn_std * self.noise
if self.pre_padding is not None:
input = self.pre_padding(input)
return F.conv1d(input, weight, self.bias, self.stride, self.padding,
self.dilation, self.groups)
class SqueezeAndExcitationModuleNew(nn.Module):
"""Squeeze And Excitation Module
Args:
input_dim: input feature dimension
reduction_ratio: bottleneck reduction ratio
inner_act: bottleneck inner activation function
Input: (batch_size, in_dim, in_length)
Output: (batch_size, out_dim, out_length)
"""
def __init__(self, input_dim, reduction_ratio, inner_act='relu'):
super(SqueezeAndExcitationModuleNew, self).__init__()
assert input_dim % reduction_ratio == 0
self.conv1 = Conv1d(input_dim, input_dim // reduction_ratio,
kernel_size=1)
self.conv2 = Conv1d(input_dim // reduction_ratio, input_dim,
kernel_size=1)
assert inner_act in ['relu', 'swish']
if inner_act == 'relu':
self.inner_act = nn.ReLU()
elif inner_act == 'swish':
self.inner_act = Swish()
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]
|
gheyret/EfficientConformer
|
SqueezeAndExcitationModule
| false
| 15,436
|
[
"Apache-2.0"
] | 101
|
b28a0aaa3b182f72abaccbeb12df0402adf96097
|
https://github.com/gheyret/EfficientConformer/tree/b28a0aaa3b182f72abaccbeb12df0402adf96097
|
_Extraction
|
import torch
from torch import Tensor
import torch.onnx.operators
def create_max_segment_mask(tensor: 'Tensor', max_segment_length):
"""
Create max-segment mask.
Args:
tensor:
:math: (N, T, *) where T is target dimension
Returns:
- max-segment mask:
:math:`(N, T)` where T is target dimension
"""
sz = tensor.size(1)
mask = [[(i <= j < i + max_segment_length) for j in range(sz)] for i in
range(sz)]
mask = torch.BoolTensor(mask).type_as(tensor).bool()
return mask
def create_upper_triangular_mask(tensor: 'Tensor'):
"""
Create upper triangular mask. It is usually used in auto-regressive model in training
Args:
tensor:
:math: (N, T, *) where T is target dimension
Returns:
- upper triangular mask:
:math:`(N, T)` where T is target dimension
"""
sz = tensor.size(1)
mask = (torch.triu(torch.ones(sz, sz)) == 1).type_as(tensor).bool()
return mask.detach()
class _Extraction(torch.nn.Module):
"""
Extraction methods transform a pair of start and end position to a segment of context.
Args:
pad: pad index
max_segment_length: maximum length for extracted results
"""
def __init__(self, pad, max_segment_length=None):
super().__init__()
self._pad = pad
self._max_segment_length = max_segment_length
def forward(self, context, start_logits, end_logits):
"""
Extract a piece of content from context
Args:
context: whole context for extraction
start_logits: log probability of start position
end_logits: log probability of end position
Returns:
- an extracted sequence of maximum probability
"""
attention_mask = context.ne(self._pad)
start_logits = start_logits.masked_fill(~attention_mask, float('-inf'))
end_logits = end_logits.masked_fill(~attention_mask, float('-inf'))
batch_size, seqlen = context.size()
logits = start_logits.unsqueeze(dim=2) + end_logits.unsqueeze(dim=1)
mask = create_upper_triangular_mask(context)
if self._max_segment_length:
max_segment_mask = create_max_segment_mask(context, self.
_max_segment_length)
mask = mask & max_segment_mask
logits = logits.masked_fill(~mask, float('-inf'))
logits = logits.view(batch_size, seqlen * seqlen)
_, pos = logits.max(dim=-1)
start_pos, end_pos = pos // seqlen, pos % seqlen
return start_pos, end_pos
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4]), torch.rand([4, 4])]
def get_init_inputs():
return [[], {'pad': 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
from torch import Tensor
import torch.onnx.operators
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_floor_divide_max_remainder_0(in_ptr0, in_ptr1, in_ptr2,
out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 4
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp10 = tl.load(in_ptr0 + (4 * x0 + r1 // 4), xmask, eviction_policy=
'evict_last', other=0.0)
tmp14 = tl.load(in_ptr1 + (4 * x0 + r1 // 4), xmask, eviction_policy=
'evict_last', other=0.0)
tmp17 = tl.load(in_ptr0 + (4 * x0 + r1 % 4), xmask, other=0.0)
tmp20 = tl.load(in_ptr2 + (4 * x0 + r1 % 4), xmask, other=0.0)
tmp0 = -1 * (r1 // 4) + r1 % 4
tmp1 = tl.full([1, 1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = 1.0
tmp4 = 0.0
tmp5 = tl.where(tmp2, tmp3, tmp4)
tmp6 = tmp5 == tmp3
tmp7 = tmp6.to(tl.float32)
tmp8 = tmp7 != 0
tmp9 = tmp8 == 0
tmp11 = 4.0
tmp12 = tmp10 != tmp11
tmp13 = tmp12 == 0
tmp15 = float('-inf')
tmp16 = tl.where(tmp13, tmp15, tmp14)
tmp18 = tmp17 != tmp11
tmp19 = tmp18 == 0
tmp21 = tl.where(tmp19, tmp15, tmp20)
tmp22 = tmp16 + tmp21
tmp23 = tl.where(tmp9, tmp15, tmp22)
tmp24 = tl.broadcast_to(tmp23, [XBLOCK, RBLOCK])
tmp26 = tl.where(xmask, tmp24, float('-inf'))
tmp27 = tl.broadcast_to(rindex, tmp26.shape)
_, tmp25_tmp = triton_helpers.max_with_index(tmp26, tmp27, 1)
tmp25 = tmp25_tmp[:, None]
tmp28 = tl.full([1, 1], 4, tl.int64)
tmp29 = tl.where((tmp25 < 0) != (tmp28 < 0), tl.where(tmp25 % tmp28 !=
0, tmp25 // tmp28 - 1, tmp25 // tmp28), tmp25 // tmp28)
tmp30 = tmp25 % tmp28
tmp31 = tl.full([1, 1], 0, tl.int32)
tmp32 = tmp30 != tmp31
tmp33 = libdevice.signbit(tmp30
) if tmp30.dtype is tl.float32 else tmp30 < 0
tmp34 = libdevice.signbit(tmp28
) if tmp28.dtype is tl.float32 else tmp28 < 0
tmp35 = tmp33 != tmp34
tmp36 = tmp32 & tmp35
tmp37 = tmp30 + tmp28
tmp38 = tl.where(tmp36, tmp37, tmp30)
tl.store(out_ptr1 + x0, tmp29, xmask)
tl.store(out_ptr2 + x0, tmp38, xmask)
def call(args):
arg0_1, arg1_1, arg2_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4), (4, 1))
assert_size_stride(arg1_1, (4, 4), (4, 1))
assert_size_stride(arg2_1, (4, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf2 = empty_strided_cuda((4,), (1,), torch.int64)
buf3 = empty_strided_cuda((4,), (1,), torch.int64)
get_raw_stream(0)
triton_per_fused_floor_divide_max_remainder_0[grid(4)](arg0_1,
arg1_1, arg2_1, buf2, buf3, 4, 16, XBLOCK=1, num_warps=2,
num_stages=1)
del arg0_1
del arg1_1
del arg2_1
return buf2, buf3
def create_max_segment_mask(tensor: 'Tensor', max_segment_length):
"""
Create max-segment mask.
Args:
tensor:
:math: (N, T, *) where T is target dimension
Returns:
- max-segment mask:
:math:`(N, T)` where T is target dimension
"""
sz = tensor.size(1)
mask = [[(i <= j < i + max_segment_length) for j in range(sz)] for i in
range(sz)]
mask = torch.BoolTensor(mask).type_as(tensor).bool()
return mask
def create_upper_triangular_mask(tensor: 'Tensor'):
"""
Create upper triangular mask. It is usually used in auto-regressive model in training
Args:
tensor:
:math: (N, T, *) where T is target dimension
Returns:
- upper triangular mask:
:math:`(N, T)` where T is target dimension
"""
sz = tensor.size(1)
mask = (torch.triu(torch.ones(sz, sz)) == 1).type_as(tensor).bool()
return mask.detach()
class _ExtractionNew(torch.nn.Module):
"""
Extraction methods transform a pair of start and end position to a segment of context.
Args:
pad: pad index
max_segment_length: maximum length for extracted results
"""
def __init__(self, pad, max_segment_length=None):
super().__init__()
self._pad = pad
self._max_segment_length = max_segment_length
def forward(self, input_0, input_1, input_2):
arg0_1 = input_0
arg1_1 = input_1
arg2_1 = input_2
output = call([arg0_1, arg1_1, arg2_1])
return output[0], output[1]
|
godweiyang/ParaGen
|
_Extraction
| false
| 15,437
|
[
"Apache-2.0"
] | 50
|
9665d1244ea38a41fc06b4e0a7f6411985e2221f
|
https://github.com/godweiyang/ParaGen/tree/9665d1244ea38a41fc06b4e0a7f6411985e2221f
|
MultiHeadLinearAttention
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class Linear(nn.Linear):
def __init__(self, in_features, out_features, bias=True):
super(Linear, self).__init__(in_features=in_features, out_features=
out_features, bias=bias)
self.noise = None
self.vn_std = None
def init_vn(self, vn_std):
self.vn_std = vn_std
def sample_synaptic_noise(self, distributed):
self.noise = torch.normal(mean=0.0, std=1.0, size=self.weight.size(
), device=self.weight.device, dtype=self.weight.dtype)
if distributed:
torch.distributed.broadcast(self.noise, 0)
def forward(self, input):
weight = self.weight
if self.noise is not None and self.training:
weight = weight + self.vn_std * self.noise
return F.linear(input, weight, self.bias)
class MultiHeadAttention(nn.Module):
"""Mutli-Head Attention Layer
Args:
dim_model: model feature dimension
num_heads: number of attention heads
References:
Attention Is All You Need, Vaswani et al.
https://arxiv.org/abs/1706.03762
"""
def __init__(self, dim_model, num_heads):
super(MultiHeadAttention, self).__init__()
self.num_heads = num_heads
self.dim_model = dim_model
self.dim_head = dim_model // num_heads
self.query_layer = Linear(self.dim_model, self.dim_model)
self.key_layer = Linear(self.dim_model, self.dim_model)
self.value_layer = Linear(self.dim_model, self.dim_model)
self.output_layer = Linear(self.dim_model, self.dim_model)
def forward(self, Q, K, V, mask=None):
"""Scaled Dot-Product Multi-Head Attention
Args:
Q: Query of shape (B, T, D)
K: Key of shape (B, T, D)
V: Value of shape (B, T, D)
mask: Optional position mask of shape (1 or B, 1 or H, 1 or T, 1 or T)
Return:
O: Attention output of shape (B, T, D)
att_w: Attention weights of shape (B, H, T, T)
"""
batch_size = Q.size(0)
Q = self.query_layer(Q)
K = self.key_layer(K)
V = self.value_layer(V)
Q = Q.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
K = K.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
V = V.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
att_scores = Q.matmul(K.transpose(2, 3)) / K.shape[-1] ** 0.5
if mask is not None:
att_scores += mask * -1000000000.0
att_w = att_scores.softmax(dim=-1)
O = att_w.matmul(V)
O = O.transpose(1, 2).reshape(batch_size, -1, self.dim_model)
O = self.output_layer(O)
return O, att_w.detach()
def pad(self, Q, K, V, mask, chunk_size):
overflow_Q = Q.size(1) % chunk_size
overflow_KV = K.size(1) % chunk_size
padding_Q = chunk_size - overflow_Q if overflow_Q else 0
padding_KV = chunk_size - overflow_KV if overflow_KV else 0
batch_size, seq_len_KV, _ = K.size()
Q = F.pad(Q, (0, 0, 0, padding_Q), value=0)
K = F.pad(K, (0, 0, 0, padding_KV), value=0)
V = F.pad(V, (0, 0, 0, padding_KV), value=0)
if mask is not None:
if mask.size(2) == 1:
mask = F.pad(mask, pad=(0, padding_KV), value=1)
else:
mask = F.pad(mask, pad=(0, padding_Q, 0, padding_KV), value=1)
elif padding_KV:
mask = F.pad(Q.new_zeros(batch_size, 1, 1, seq_len_KV), pad=(0,
padding_KV), value=1)
return Q, K, V, mask, padding_Q
class MultiHeadLinearAttention(MultiHeadAttention):
"""Multi-Head Linear Attention
Args:
dim_model: model feature dimension
num_heads: number of attention heads
References:
Efficient Attention: Attention with Linear Complexities, Shen et al.
https://arxiv.org/abs/1812.01243
Efficient conformer-based speech recognition with linear attention, Li et al.
https://arxiv.org/abs/2104.06865
"""
def __init__(self, dim_model, num_heads):
super(MultiHeadLinearAttention, self).__init__(dim_model, num_heads)
def forward(self, Q, K, V):
batch_size = Q.size(0)
Q = self.query_layer(Q)
K = self.key_layer(K)
V = self.value_layer(V)
Q = Q.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
K = K.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
V = V.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
KV = (K / K.shape[-1] ** (1.0 / 4.0)).softmax(dim=-2).transpose(2, 3
).matmul(V)
O = (Q / Q.shape[-1] ** (1.0 / 4.0)).softmax(dim=-1).matmul(KV)
O = O.transpose(1, 2).reshape(batch_size, -1, self.dim_model)
O = self.output_layer(O)
return O, KV.detach()
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 [[], {'dim_model': 4, 'num_heads': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import 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_per_fused__softmax_div_0(in_ptr0, in_ptr1, out_ptr2, xnumel,
rnumel, XBLOCK: tl.constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
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, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 1.0
tmp4 = tmp2 * tmp3
tmp5 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK])
tmp7 = tl.where(xmask, tmp5, float('-inf'))
tmp8 = triton_helpers.max2(tmp7, 1)[:, None]
tmp9 = tmp4 - tmp8
tmp10 = tl_math.exp(tmp9)
tmp11 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK])
tmp13 = tl.where(xmask, tmp11, 0)
tmp14 = tl.sum(tmp13, 1)[:, None]
tmp15 = tmp10 / tmp14
tl.store(out_ptr2 + (r2 + 16 * x3), tmp15, xmask)
@triton.jit
def triton_poi_fused_clone_1(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel,
YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 16
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 4
y1 = yindex // 4
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 64 * y1), xmask & ymask)
tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + (x2 + 16 * y3), tmp2, xmask & ymask)
@triton.jit
def triton_poi_fused__softmax_div_2(in_ptr0, in_ptr1, out_ptr0, ynumel,
xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 64
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 16
y1 = yindex // 16
tmp0 = tl.load(in_ptr0 + (x2 + 4 * y3), xmask & ymask, eviction_policy=
'evict_last')
tmp1 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 1.0
tmp4 = tmp2 * tmp3
tmp5 = tmp4 - tmp4
tmp6 = tl_math.exp(tmp5)
tmp7 = tmp6 / tmp6
tl.store(out_ptr0 + (y0 + 16 * x2 + 64 * y1), tmp7, xmask & ymask)
@triton.jit
def triton_poi_fused_clone_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 64
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 16
y1 = yindex // 16
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 16 * x2 + 64 * y1), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_add_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x2, tmp2, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_7, (4, 4), (4, 1))
assert_size_stride(primals_8, (4,), (1,))
assert_size_stride(primals_9, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_10, (4, 4), (4, 1))
assert_size_stride(primals_11, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0)
del primals_2
buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_6, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1)
del primals_4
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_9, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), out=buf2)
del primals_7
buf5 = empty_strided_cuda((4, 4, 16, 1), (64, 16, 1, 1), torch.float32)
get_raw_stream(0)
triton_per_fused__softmax_div_0[grid(16)](buf1, primals_5, buf5, 16,
16, XBLOCK=1, num_warps=2, num_stages=1)
del primals_5
buf6 = reinterpret_tensor(buf1, (4, 4, 16, 1), (64, 16, 1, 1), 0)
del buf1
triton_poi_fused_clone_1[grid(16, 16)](buf2, primals_8, buf6, 16,
16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1)
del primals_8
buf7 = empty_strided_cuda((16, 1, 1), (1, 1, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf5, (16, 1, 16), (16, 16, 1
), 0), reinterpret_tensor(buf6, (16, 16, 1), (16, 1, 0), 0),
out=buf7)
buf8 = reinterpret_tensor(buf2, (4, 4, 16, 1), (64, 16, 1, 1), 0)
del buf2
triton_poi_fused__softmax_div_2[grid(64, 4)](buf0, primals_3, buf8,
64, 4, XBLOCK=4, YBLOCK=32, num_warps=4, num_stages=1)
del primals_3
buf9 = reinterpret_tensor(buf0, (16, 16, 1), (16, 1, 1), 0)
del buf0
extern_kernels.bmm(reinterpret_tensor(buf8, (16, 16, 1), (16, 1, 1),
0), buf7, out=buf9)
buf10 = empty_strided_cuda((4, 16, 4), (64, 4, 1), torch.float32)
triton_poi_fused_clone_3[grid(64, 4)](buf9, buf10, 64, 4, XBLOCK=4,
YBLOCK=32, num_warps=4, num_stages=1)
buf11 = reinterpret_tensor(buf9, (64, 4), (4, 1), 0)
del buf9
extern_kernels.mm(reinterpret_tensor(buf10, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_10, (4, 4), (1, 4), 0), out=buf11)
buf12 = reinterpret_tensor(buf11, (4, 16, 4), (64, 4, 1), 0)
del buf11
triton_poi_fused_add_4[grid(256)](buf12, primals_11, 256, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_11
return buf12, reinterpret_tensor(buf7, (4, 4, 1, 1), (4, 1, 1, 1), 0
), reinterpret_tensor(primals_1, (64, 4), (4, 1), 0
), reinterpret_tensor(primals_6, (64, 4), (4, 1), 0
), reinterpret_tensor(primals_9, (64, 4), (4, 1), 0
), buf5, buf8, reinterpret_tensor(buf10, (64, 4), (4, 1), 0
), primals_10, buf7, reinterpret_tensor(buf6, (16, 1, 16), (16, 1,
1), 0)
class Linear(nn.Linear):
def __init__(self, in_features, out_features, bias=True):
super(Linear, self).__init__(in_features=in_features, out_features=
out_features, bias=bias)
self.noise = None
self.vn_std = None
def init_vn(self, vn_std):
self.vn_std = vn_std
def sample_synaptic_noise(self, distributed):
self.noise = torch.normal(mean=0.0, std=1.0, size=self.weight.size(
), device=self.weight.device, dtype=self.weight.dtype)
if distributed:
torch.distributed.broadcast(self.noise, 0)
def forward(self, input):
weight = self.weight
if self.noise is not None and self.training:
weight = weight + self.vn_std * self.noise
return F.linear(input, weight, self.bias)
class MultiHeadAttention(nn.Module):
"""Mutli-Head Attention Layer
Args:
dim_model: model feature dimension
num_heads: number of attention heads
References:
Attention Is All You Need, Vaswani et al.
https://arxiv.org/abs/1706.03762
"""
def __init__(self, dim_model, num_heads):
super(MultiHeadAttention, self).__init__()
self.num_heads = num_heads
self.dim_model = dim_model
self.dim_head = dim_model // num_heads
self.query_layer = Linear(self.dim_model, self.dim_model)
self.key_layer = Linear(self.dim_model, self.dim_model)
self.value_layer = Linear(self.dim_model, self.dim_model)
self.output_layer = Linear(self.dim_model, self.dim_model)
def forward(self, Q, K, V, mask=None):
"""Scaled Dot-Product Multi-Head Attention
Args:
Q: Query of shape (B, T, D)
K: Key of shape (B, T, D)
V: Value of shape (B, T, D)
mask: Optional position mask of shape (1 or B, 1 or H, 1 or T, 1 or T)
Return:
O: Attention output of shape (B, T, D)
att_w: Attention weights of shape (B, H, T, T)
"""
batch_size = Q.size(0)
Q = self.query_layer(Q)
K = self.key_layer(K)
V = self.value_layer(V)
Q = Q.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
K = K.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
V = V.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
att_scores = Q.matmul(K.transpose(2, 3)) / K.shape[-1] ** 0.5
if mask is not None:
att_scores += mask * -1000000000.0
att_w = att_scores.softmax(dim=-1)
O = att_w.matmul(V)
O = O.transpose(1, 2).reshape(batch_size, -1, self.dim_model)
O = self.output_layer(O)
return O, att_w.detach()
def pad(self, Q, K, V, mask, chunk_size):
overflow_Q = Q.size(1) % chunk_size
overflow_KV = K.size(1) % chunk_size
padding_Q = chunk_size - overflow_Q if overflow_Q else 0
padding_KV = chunk_size - overflow_KV if overflow_KV else 0
batch_size, seq_len_KV, _ = K.size()
Q = F.pad(Q, (0, 0, 0, padding_Q), value=0)
K = F.pad(K, (0, 0, 0, padding_KV), value=0)
V = F.pad(V, (0, 0, 0, padding_KV), value=0)
if mask is not None:
if mask.size(2) == 1:
mask = F.pad(mask, pad=(0, padding_KV), value=1)
else:
mask = F.pad(mask, pad=(0, padding_Q, 0, padding_KV), value=1)
elif padding_KV:
mask = F.pad(Q.new_zeros(batch_size, 1, 1, seq_len_KV), pad=(0,
padding_KV), value=1)
return Q, K, V, mask, padding_Q
class MultiHeadLinearAttentionNew(MultiHeadAttention):
"""Multi-Head Linear Attention
Args:
dim_model: model feature dimension
num_heads: number of attention heads
References:
Efficient Attention: Attention with Linear Complexities, Shen et al.
https://arxiv.org/abs/1812.01243
Efficient conformer-based speech recognition with linear attention, Li et al.
https://arxiv.org/abs/2104.06865
"""
def __init__(self, dim_model, num_heads):
super(MultiHeadLinearAttentionNew, self).__init__(dim_model, num_heads)
def forward(self, input_0, input_1, input_2):
primals_2 = self.query_layer.weight
primals_3 = self.query_layer.bias
primals_4 = self.key_layer.weight
primals_5 = self.key_layer.bias
primals_7 = self.value_layer.weight
primals_8 = self.value_layer.bias
primals_10 = self.output_layer.weight
primals_11 = self.output_layer.bias
primals_1 = input_0
primals_6 = input_1
primals_9 = input_2
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11])
return output[0], output[1]
|
gheyret/EfficientConformer
|
MultiHeadLinearAttention
| false
| 15,438
|
[
"Apache-2.0"
] | 101
|
b28a0aaa3b182f72abaccbeb12df0402adf96097
|
https://github.com/gheyret/EfficientConformer/tree/b28a0aaa3b182f72abaccbeb12df0402adf96097
|
PowerLaw_Compressed_Loss
|
import torch
import torch.nn as nn
import torch.utils.data
class PowerLaw_Compressed_Loss(nn.Module):
def __init__(self, power=0.3, complex_loss_ratio=0.113):
super(PowerLaw_Compressed_Loss, self).__init__()
self.power = power
self.complex_loss_ratio = complex_loss_ratio
self.criterion = nn.MSELoss()
self.epsilon = 1e-16
def forward(self, prediction, target, seq_len=None, spec_phase=None):
prediction = prediction + self.epsilon
target = target + self.epsilon
prediction = torch.pow(prediction, self.power)
target = torch.pow(target, self.power)
spec_loss = self.criterion(torch.abs(target), torch.abs(prediction))
complex_loss = self.criterion(target, prediction)
loss = spec_loss + complex_loss * self.complex_loss_ratio
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, 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_add_mse_loss_mul_pow_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)
tmp6 = tl.load(in_ptr1 + r0, None)
tmp1 = 1e-16
tmp2 = tmp0 + tmp1
tmp3 = 0.3
tmp4 = libdevice.pow(tmp2, tmp3)
tmp5 = tl_math.abs(tmp4)
tmp7 = tmp6 + tmp1
tmp8 = libdevice.pow(tmp7, tmp3)
tmp9 = tl_math.abs(tmp8)
tmp10 = tmp5 - tmp9
tmp11 = tmp10 * tmp10
tmp12 = tl.broadcast_to(tmp11, [RBLOCK])
tmp14 = triton_helpers.promote_to_tensor(tl.sum(tmp12, 0))
tmp15 = tmp4 - tmp8
tmp16 = tmp15 * tmp15
tmp17 = tl.broadcast_to(tmp16, [RBLOCK])
tmp19 = triton_helpers.promote_to_tensor(tl.sum(tmp17, 0))
tmp20 = 256.0
tmp21 = tmp14 / tmp20
tmp22 = tmp19 / tmp20
tmp23 = 0.113
tmp24 = tmp22 * tmp23
tmp25 = tmp21 + tmp24
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp25, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((), (), torch.float32)
buf2 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_abs_add_mse_loss_mul_pow_0[grid(1)](buf2, arg1_1,
arg0_1, 1, 256, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
return buf2,
class PowerLaw_Compressed_LossNew(nn.Module):
def __init__(self, power=0.3, complex_loss_ratio=0.113):
super(PowerLaw_Compressed_LossNew, self).__init__()
self.power = power
self.complex_loss_ratio = complex_loss_ratio
self.criterion = nn.MSELoss()
self.epsilon = 1e-16
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
giuliacassara/VoiceSplit
|
PowerLaw_Compressed_Loss
| false
| 15,439
|
[
"Apache-2.0"
] | 84
|
1aa98dce9460db7ec6c5449eb7f92e3902f71a2a
|
https://github.com/giuliacassara/VoiceSplit/tree/1aa98dce9460db7ec6c5449eb7f92e3902f71a2a
|
AUXModule
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class AUXModule(nn.Module):
def __init__(self, in_features, out_features):
super().__init__()
self.linear = nn.Linear(in_features, out_features)
def forward(self, x):
x = F.adaptive_max_pool2d(x, output_size=(1, 1))
x = x.view(-1, x.size(1))
x = self.linear(x)
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_features': 4, 'out_features': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import 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_adaptive_max_pool2d_0(in_ptr0, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp3 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp5 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp7 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp9 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp11 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp13 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp15 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp17 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp19 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp21 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp23 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp25 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp27 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp29 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = triton_helpers.maximum(tmp5, tmp4)
tmp8 = triton_helpers.maximum(tmp7, tmp6)
tmp10 = triton_helpers.maximum(tmp9, tmp8)
tmp12 = triton_helpers.maximum(tmp11, tmp10)
tmp14 = triton_helpers.maximum(tmp13, tmp12)
tmp16 = triton_helpers.maximum(tmp15, tmp14)
tmp18 = triton_helpers.maximum(tmp17, tmp16)
tmp20 = triton_helpers.maximum(tmp19, tmp18)
tmp22 = triton_helpers.maximum(tmp21, tmp20)
tmp24 = triton_helpers.maximum(tmp23, tmp22)
tmp26 = triton_helpers.maximum(tmp25, tmp24)
tmp28 = triton_helpers.maximum(tmp27, tmp26)
tmp30 = triton_helpers.maximum(tmp29, tmp28)
tl.store(out_ptr0 + x0, tmp30, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_adaptive_max_pool2d_0[grid(16)](primals_1, buf0,
16, XBLOCK=16, num_warps=1, num_stages=1)
del primals_1
buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_3, reinterpret_tensor(buf0, (4, 4), (4,
1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), alpha
=1, beta=1, out=buf1)
del primals_2
del primals_3
return buf1, reinterpret_tensor(buf0, (4, 4), (4, 1), 0)
class AUXModuleNew(nn.Module):
def __init__(self, in_features, out_features):
super().__init__()
self.linear = nn.Linear(in_features, out_features)
def forward(self, input_0):
primals_2 = self.linear.weight
primals_3 = self.linear.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
gorogoroyasu/mlcomp
|
AUXModule
| false
| 15,440
|
[
"Apache-2.0"
] | 166
|
fc6572ca5b226b35df97f13badd4420b30468a3b
|
https://github.com/gorogoroyasu/mlcomp/tree/fc6572ca5b226b35df97f13badd4420b30468a3b
|
HuggingfaceClassifier
|
import torch
import torch.nn.functional as F
import torch.nn as nn
import torch.onnx.operators
def get_activation_fn(activation):
"""
Get activation function by name
Args:
activation: activation function name
Returns:
- activation function
"""
if activation == 'relu':
return F.relu
elif activation == 'gelu':
return F.gelu
else:
raise KeyError
class HuggingfaceClassifier(nn.Module):
"""
Classifier implemented in HuggingfaceClassificationHead style.
Args:
d_model: feature dimensionality
labels: number of classes
inner_dim: dimensionality in the inner vector space.
activation: activation function used in the feed-forward network
dropout: dropout rate
"""
def __init__(self, d_model, labels, inner_dim=None, activation='relu',
dropout=0.0):
super().__init__()
inner_dim = inner_dim or d_model * 2
self._fc1 = nn.Linear(d_model, inner_dim)
self._dropout = nn.Dropout(dropout)
self._fc2 = nn.Linear(inner_dim, labels)
self._activation = get_activation_fn(activation)
def forward(self, x):
"""
Args:
x: feature to predict labels
:math:`(*, D)`, where D is the feature dimension
Returns:
- log probability of each classes
:math: `(*, L)`, where L is the number of classes
"""
x = self._dropout(x)
x = self._fc1(x)
x = self._activation(x)
x = self._dropout(x)
x = self._fc2(x)
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'d_model': 4, 'labels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn.functional as F
import torch.nn as nn
import torch.onnx.operators
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, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (8, 4), (4, 1))
assert_size_stride(primals_3, (8,), (1,))
assert_size_stride(primals_4, (4, 8), (8, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 8), (8, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_2, (4, 8), (1, 4), 0), out=buf0)
del primals_2
buf1 = reinterpret_tensor(buf0, (4, 4, 4, 8), (128, 32, 8, 1), 0)
del buf0
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_3, buf3, 512, XBLOCK=256, num_warps=4, num_stages=1)
del primals_3
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 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_1, (64, 4), (4, 1), 0
), reinterpret_tensor(buf1, (64, 8), (8, 1), 0), primals_4, buf3
def get_activation_fn(activation):
"""
Get activation function by name
Args:
activation: activation function name
Returns:
- activation function
"""
if activation == 'relu':
return F.relu
elif activation == 'gelu':
return F.gelu
else:
raise KeyError
class HuggingfaceClassifierNew(nn.Module):
"""
Classifier implemented in HuggingfaceClassificationHead style.
Args:
d_model: feature dimensionality
labels: number of classes
inner_dim: dimensionality in the inner vector space.
activation: activation function used in the feed-forward network
dropout: dropout rate
"""
def __init__(self, d_model, labels, inner_dim=None, activation='relu',
dropout=0.0):
super().__init__()
inner_dim = inner_dim or d_model * 2
self._fc1 = nn.Linear(d_model, inner_dim)
self._dropout = nn.Dropout(dropout)
self._fc2 = nn.Linear(inner_dim, labels)
self._activation = get_activation_fn(activation)
def forward(self, input_0):
primals_2 = self._fc1.weight
primals_3 = self._fc1.bias
primals_4 = self._fc2.weight
primals_5 = self._fc2.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
godweiyang/ParaGen
|
HuggingfaceClassifier
| false
| 15,441
|
[
"Apache-2.0"
] | 50
|
9665d1244ea38a41fc06b4e0a7f6411985e2221f
|
https://github.com/godweiyang/ParaGen/tree/9665d1244ea38a41fc06b4e0a7f6411985e2221f
|
SimpleTextClassifier
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class SimpleTextClassifier(nn.Module):
"""Text Classifier with 1 hidden layer
"""
def __init__(self, num_labels, vocab_size):
super(SimpleTextClassifier, self).__init__()
self.linear1 = nn.Linear(vocab_size, 128)
self.linear2 = nn.Linear(128, num_labels)
def forward(self, feature_vec):
hidden1 = self.linear1(feature_vec).clamp(min=0)
output = self.linear2(hidden1)
return F.log_softmax(output, dim=1)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'num_labels': 4, 'vocab_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_clamp_ge_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x2 = xindex
x0 = xindex % 128
tmp0 = tl.load(in_ptr0 + x2, None)
tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = triton_helpers.maximum(tmp2, tmp3)
tmp5 = tmp2 >= tmp3
tl.store(out_ptr0 + x2, tmp4, None)
tl.store(out_ptr1 + x2, tmp5, None)
@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_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl_math.exp(tmp1)
tmp4 = tl_math.exp(tmp3)
tmp5 = tmp2 + tmp4
tmp7 = tl_math.exp(tmp6)
tmp8 = tmp5 + tmp7
tmp10 = tl_math.exp(tmp9)
tmp11 = tmp8 + tmp10
tmp12 = tl_math.log(tmp11)
tmp13 = tmp0 - tmp12
tl.store(out_ptr0 + x3, tmp13, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (128, 4), (4, 1))
assert_size_stride(primals_2, (128,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4, 128), (128, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 128), (128, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 128), (1, 4), 0), out=buf0)
del primals_1
buf1 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1),
torch.float32)
buf5 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1),
torch.bool)
get_raw_stream(0)
triton_poi_fused_clamp_ge_0[grid(8192)](buf0, primals_2, buf1, buf5,
8192, XBLOCK=256, num_warps=4, num_stages=1)
del buf0
del primals_2
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 128),
(128, 1), 0), reinterpret_tensor(primals_4, (128, 4), (1, 128),
0), alpha=1, beta=1, out=buf2)
del primals_5
buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__log_softmax_1[grid(256)](buf2, buf3, 256, XBLOCK=
256, num_warps=4, num_stages=1)
buf4 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf2
triton_poi_fused__log_softmax_2[grid(256)](buf3, buf4, 256, XBLOCK=
256, num_warps=4, num_stages=1)
del buf3
return buf4, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), reinterpret_tensor(buf1, (64, 128), (128, 1), 0
), buf4, primals_4, buf5
class SimpleTextClassifierNew(nn.Module):
"""Text Classifier with 1 hidden layer
"""
def __init__(self, num_labels, vocab_size):
super(SimpleTextClassifierNew, self).__init__()
self.linear1 = nn.Linear(vocab_size, 128)
self.linear2 = nn.Linear(128, num_labels)
def forward(self, input_0):
primals_1 = self.linear1.weight
primals_2 = self.linear1.bias
primals_4 = self.linear2.weight
primals_5 = self.linear2.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
goodmike31/pytorch_active_learning
|
SimpleTextClassifier
| false
| 15,442
|
[
"MIT"
] | 629
|
1224efad1f8022efa933cd36e30f78ed06eaaea7
|
https://github.com/goodmike31/pytorch_active_learning/tree/1224efad1f8022efa933cd36e30f78ed06eaaea7
|
LocalMultiHeadAttention
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class Linear(nn.Linear):
def __init__(self, in_features, out_features, bias=True):
super(Linear, self).__init__(in_features=in_features, out_features=
out_features, bias=bias)
self.noise = None
self.vn_std = None
def init_vn(self, vn_std):
self.vn_std = vn_std
def sample_synaptic_noise(self, distributed):
self.noise = torch.normal(mean=0.0, std=1.0, size=self.weight.size(
), device=self.weight.device, dtype=self.weight.dtype)
if distributed:
torch.distributed.broadcast(self.noise, 0)
def forward(self, input):
weight = self.weight
if self.noise is not None and self.training:
weight = weight + self.vn_std * self.noise
return F.linear(input, weight, self.bias)
class MultiHeadAttention(nn.Module):
"""Mutli-Head Attention Layer
Args:
dim_model: model feature dimension
num_heads: number of attention heads
References:
Attention Is All You Need, Vaswani et al.
https://arxiv.org/abs/1706.03762
"""
def __init__(self, dim_model, num_heads):
super(MultiHeadAttention, self).__init__()
self.num_heads = num_heads
self.dim_model = dim_model
self.dim_head = dim_model // num_heads
self.query_layer = Linear(self.dim_model, self.dim_model)
self.key_layer = Linear(self.dim_model, self.dim_model)
self.value_layer = Linear(self.dim_model, self.dim_model)
self.output_layer = Linear(self.dim_model, self.dim_model)
def forward(self, Q, K, V, mask=None):
"""Scaled Dot-Product Multi-Head Attention
Args:
Q: Query of shape (B, T, D)
K: Key of shape (B, T, D)
V: Value of shape (B, T, D)
mask: Optional position mask of shape (1 or B, 1 or H, 1 or T, 1 or T)
Return:
O: Attention output of shape (B, T, D)
att_w: Attention weights of shape (B, H, T, T)
"""
batch_size = Q.size(0)
Q = self.query_layer(Q)
K = self.key_layer(K)
V = self.value_layer(V)
Q = Q.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
K = K.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
V = V.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
att_scores = Q.matmul(K.transpose(2, 3)) / K.shape[-1] ** 0.5
if mask is not None:
att_scores += mask * -1000000000.0
att_w = att_scores.softmax(dim=-1)
O = att_w.matmul(V)
O = O.transpose(1, 2).reshape(batch_size, -1, self.dim_model)
O = self.output_layer(O)
return O, att_w.detach()
def pad(self, Q, K, V, mask, chunk_size):
overflow_Q = Q.size(1) % chunk_size
overflow_KV = K.size(1) % chunk_size
padding_Q = chunk_size - overflow_Q if overflow_Q else 0
padding_KV = chunk_size - overflow_KV if overflow_KV else 0
batch_size, seq_len_KV, _ = K.size()
Q = F.pad(Q, (0, 0, 0, padding_Q), value=0)
K = F.pad(K, (0, 0, 0, padding_KV), value=0)
V = F.pad(V, (0, 0, 0, padding_KV), value=0)
if mask is not None:
if mask.size(2) == 1:
mask = F.pad(mask, pad=(0, padding_KV), value=1)
else:
mask = F.pad(mask, pad=(0, padding_Q, 0, padding_KV), value=1)
elif padding_KV:
mask = F.pad(Q.new_zeros(batch_size, 1, 1, seq_len_KV), pad=(0,
padding_KV), value=1)
return Q, K, V, mask, padding_Q
class LocalMultiHeadAttention(MultiHeadAttention):
"""Local Multi-Head Attention Layer
Local multi-head attention restricts the attended positions to a local neighborhood
around the query position. This is achieved by segmenting the hidden sequence into
non overlapping blocks of size K and performing scaled dot-product attention in
parallel for each of these blocks.
Args:
dim_model: model feature dimension
num_heads: number of attention heads
kernel_size: attention kernel size / window
References:
Image Transformer, Parmar et al.
https://arxiv.org/abs/1802.05751
"""
def __init__(self, dim_model, num_heads, kernel_size):
super(LocalMultiHeadAttention, self).__init__(dim_model, num_heads)
self.kernel_size = kernel_size
def forward(self, Q, K, V, mask=None):
batch_size = Q.size(0)
Q = self.query_layer(Q)
K = self.key_layer(K)
V = self.value_layer(V)
Q, K, V, mask, padding = self.pad(Q, K, V, mask, chunk_size=self.
kernel_size)
Q = Q.reshape(batch_size, -1, self.kernel_size, self.num_heads,
self.dim_head).transpose(2, 3)
K = K.reshape(batch_size, -1, self.kernel_size, self.num_heads,
self.dim_head).transpose(2, 3)
V = V.reshape(batch_size, -1, self.kernel_size, self.num_heads,
self.dim_head).transpose(2, 3)
att_scores = Q.matmul(K.transpose(3, 4)) / K.shape[-1] ** 0.5
if mask is not None:
masks = []
for m in range(mask.size(-1) // self.kernel_size):
masks.append(mask[:, :, m * self.kernel_size:(m + 1) * self
.kernel_size, m * self.kernel_size:(m + 1) * self.
kernel_size])
mask = torch.stack(masks, dim=1)
att_scores = att_scores.float() - mask.float() * 1000000000.0
att_w = att_scores.softmax(dim=-1)
O = att_w.matmul(V)
O = O.transpose(2, 3).reshape(batch_size, -1, self.dim_model)
O = O[:, :O.size(1) - padding]
O = self.output_layer(O)
return O, att_w.detach()
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4]), torch.rand([4,
4, 4, 4])]
def get_init_inputs():
return [[], {'dim_model': 4, 'num_heads': 4, 'kernel_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime 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_clone_0(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel,
YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 64
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 4
y1 = yindex // 4
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + (x2 + 4 * y3), tmp2, xmask & ymask)
@triton.jit
def triton_poi_fused_clone_1(in_ptr0, in_ptr1, out_ptr0, 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
x3 = xindex // 64
x4 = xindex
tmp0 = tl.load(in_ptr0 + (x1 + 4 * x0 + 16 * x3), xmask,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + x4, tmp2, xmask)
@triton.jit
def triton_poi_fused__softmax_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
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp3 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last'
)
tmp1 = 1.0
tmp2 = tmp0 * tmp1
tmp4 = tmp3 * tmp1
tmp6 = tmp5 * tmp1
tmp7 = triton_helpers.maximum(tmp4, tmp6)
tmp9 = tmp8 * tmp1
tmp10 = triton_helpers.maximum(tmp7, tmp9)
tmp12 = tmp11 * tmp1
tmp13 = triton_helpers.maximum(tmp10, tmp12)
tmp14 = tmp2 - tmp13
tmp15 = tmp14 * tmp1
tmp16 = tl_math.exp(tmp15)
tl.store(out_ptr0 + x2, tmp16, xmask)
@triton.jit
def triton_poi_fused__softmax_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused_clone_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 64
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 4
y1 = yindex // 4
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_7, (4, 4), (4, 1))
assert_size_stride(primals_8, (4,), (1,))
assert_size_stride(primals_9, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_10, (4, 4), (4, 1))
assert_size_stride(primals_11, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0)
del primals_2
buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_6, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1)
del primals_4
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_9, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), out=buf2)
del primals_7
buf3 = empty_strided_cuda((4, 4, 4, 4, 1), (64, 16, 4, 1, 1), torch
.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(64, 4)](buf0, primals_3, buf3, 64, 4,
XBLOCK=4, YBLOCK=64, num_warps=4, num_stages=1)
del primals_3
buf4 = reinterpret_tensor(buf0, (4, 4, 4, 1, 4), (64, 16, 4, 4, 1), 0)
del buf0
triton_poi_fused_clone_1[grid(256)](buf1, primals_5, buf4, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del buf1
del primals_5
buf5 = empty_strided_cuda((64, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf3, (64, 4, 1), (4, 1, 0),
0), reinterpret_tensor(buf4, (64, 1, 4), (4, 0, 1), 0), out=buf5)
buf6 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1),
torch.float32)
triton_poi_fused__softmax_2[grid(1024)](buf5, buf6, 1024, XBLOCK=
256, num_warps=4, num_stages=1)
buf7 = reinterpret_tensor(buf5, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1), 0
)
del buf5
triton_poi_fused__softmax_3[grid(1024)](buf6, buf7, 1024, XBLOCK=
128, num_warps=4, num_stages=1)
del buf6
buf8 = empty_strided_cuda((4, 4, 4, 4, 1), (64, 16, 4, 1, 1), torch
.float32)
triton_poi_fused_clone_0[grid(64, 4)](buf2, primals_8, buf8, 64, 4,
XBLOCK=4, YBLOCK=64, num_warps=4, num_stages=1)
del primals_8
buf9 = reinterpret_tensor(buf2, (64, 4, 1), (4, 1, 1), 0)
del buf2
extern_kernels.bmm(reinterpret_tensor(buf7, (64, 4, 4), (16, 4, 1),
0), reinterpret_tensor(buf8, (64, 4, 1), (4, 1, 0), 0), out=buf9)
buf10 = empty_strided_cuda((4, 4, 4, 4, 1), (64, 16, 4, 1, 1),
torch.float32)
triton_poi_fused_clone_4[grid(64, 4)](buf9, buf10, 64, 4, XBLOCK=4,
YBLOCK=32, num_warps=4, num_stages=1)
buf11 = reinterpret_tensor(buf9, (64, 4), (4, 1), 0)
del buf9
extern_kernels.addmm(primals_11, reinterpret_tensor(buf10, (64, 4),
(4, 1), 0), reinterpret_tensor(primals_10, (4, 4), (1, 4), 0),
alpha=1, beta=1, out=buf11)
del primals_11
return reinterpret_tensor(buf11, (4, 16, 4), (64, 4, 1), 0
), buf7, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0
), reinterpret_tensor(primals_6, (16, 4), (4, 1), 0
), reinterpret_tensor(primals_9, (64, 4), (4, 1), 0
), buf7, reinterpret_tensor(buf10, (64, 4), (4, 1), 0
), primals_10, reinterpret_tensor(buf8, (64, 1, 4), (4, 1, 1), 0
), reinterpret_tensor(buf3, (64, 1, 4), (4, 1, 1), 0
), reinterpret_tensor(buf4, (64, 4, 1), (4, 1, 4), 0)
class Linear(nn.Linear):
def __init__(self, in_features, out_features, bias=True):
super(Linear, self).__init__(in_features=in_features, out_features=
out_features, bias=bias)
self.noise = None
self.vn_std = None
def init_vn(self, vn_std):
self.vn_std = vn_std
def sample_synaptic_noise(self, distributed):
self.noise = torch.normal(mean=0.0, std=1.0, size=self.weight.size(
), device=self.weight.device, dtype=self.weight.dtype)
if distributed:
torch.distributed.broadcast(self.noise, 0)
def forward(self, input):
weight = self.weight
if self.noise is not None and self.training:
weight = weight + self.vn_std * self.noise
return F.linear(input, weight, self.bias)
class MultiHeadAttention(nn.Module):
"""Mutli-Head Attention Layer
Args:
dim_model: model feature dimension
num_heads: number of attention heads
References:
Attention Is All You Need, Vaswani et al.
https://arxiv.org/abs/1706.03762
"""
def __init__(self, dim_model, num_heads):
super(MultiHeadAttention, self).__init__()
self.num_heads = num_heads
self.dim_model = dim_model
self.dim_head = dim_model // num_heads
self.query_layer = Linear(self.dim_model, self.dim_model)
self.key_layer = Linear(self.dim_model, self.dim_model)
self.value_layer = Linear(self.dim_model, self.dim_model)
self.output_layer = Linear(self.dim_model, self.dim_model)
def forward(self, Q, K, V, mask=None):
"""Scaled Dot-Product Multi-Head Attention
Args:
Q: Query of shape (B, T, D)
K: Key of shape (B, T, D)
V: Value of shape (B, T, D)
mask: Optional position mask of shape (1 or B, 1 or H, 1 or T, 1 or T)
Return:
O: Attention output of shape (B, T, D)
att_w: Attention weights of shape (B, H, T, T)
"""
batch_size = Q.size(0)
Q = self.query_layer(Q)
K = self.key_layer(K)
V = self.value_layer(V)
Q = Q.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
K = K.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
V = V.reshape(batch_size, -1, self.num_heads, self.dim_head).transpose(
1, 2)
att_scores = Q.matmul(K.transpose(2, 3)) / K.shape[-1] ** 0.5
if mask is not None:
att_scores += mask * -1000000000.0
att_w = att_scores.softmax(dim=-1)
O = att_w.matmul(V)
O = O.transpose(1, 2).reshape(batch_size, -1, self.dim_model)
O = self.output_layer(O)
return O, att_w.detach()
def pad(self, Q, K, V, mask, chunk_size):
overflow_Q = Q.size(1) % chunk_size
overflow_KV = K.size(1) % chunk_size
padding_Q = chunk_size - overflow_Q if overflow_Q else 0
padding_KV = chunk_size - overflow_KV if overflow_KV else 0
batch_size, seq_len_KV, _ = K.size()
Q = F.pad(Q, (0, 0, 0, padding_Q), value=0)
K = F.pad(K, (0, 0, 0, padding_KV), value=0)
V = F.pad(V, (0, 0, 0, padding_KV), value=0)
if mask is not None:
if mask.size(2) == 1:
mask = F.pad(mask, pad=(0, padding_KV), value=1)
else:
mask = F.pad(mask, pad=(0, padding_Q, 0, padding_KV), value=1)
elif padding_KV:
mask = F.pad(Q.new_zeros(batch_size, 1, 1, seq_len_KV), pad=(0,
padding_KV), value=1)
return Q, K, V, mask, padding_Q
class LocalMultiHeadAttentionNew(MultiHeadAttention):
"""Local Multi-Head Attention Layer
Local multi-head attention restricts the attended positions to a local neighborhood
around the query position. This is achieved by segmenting the hidden sequence into
non overlapping blocks of size K and performing scaled dot-product attention in
parallel for each of these blocks.
Args:
dim_model: model feature dimension
num_heads: number of attention heads
kernel_size: attention kernel size / window
References:
Image Transformer, Parmar et al.
https://arxiv.org/abs/1802.05751
"""
def __init__(self, dim_model, num_heads, kernel_size):
super(LocalMultiHeadAttentionNew, self).__init__(dim_model, num_heads)
self.kernel_size = kernel_size
def forward(self, input_0, input_1, input_2):
primals_2 = self.query_layer.weight
primals_3 = self.query_layer.bias
primals_4 = self.key_layer.weight
primals_5 = self.key_layer.bias
primals_7 = self.value_layer.weight
primals_8 = self.value_layer.bias
primals_10 = self.output_layer.weight
primals_11 = self.output_layer.bias
primals_1 = input_0
primals_6 = input_1
primals_9 = input_2
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11])
return output[0], output[1]
|
gheyret/EfficientConformer
|
LocalMultiHeadAttention
| false
| 15,443
|
[
"Apache-2.0"
] | 101
|
b28a0aaa3b182f72abaccbeb12df0402adf96097
|
https://github.com/gheyret/EfficientConformer/tree/b28a0aaa3b182f72abaccbeb12df0402adf96097
|
NormedMSE
|
import torch
import torch.nn as nn
import torch.utils.data
class NormedMSE(nn.MSELoss):
def forward(self, inp, tgt, *args, **kwargs):
"""
Args:
inp: (*, C)
tgt: (*, C)
Will normalize the input before the loss
"""
inp = nn.functional.normalize(inp, dim=-1, p=2)
tgt = nn.functional.normalize(tgt, dim=-1, p=2)
return super().forward(inp, tgt, *args, **kwargs)
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
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_red_fused_div_mse_loss_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel,
rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
rnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rbase = tl.arange(0, RBLOCK)[None, :]
_tmp34 = tl.full([XBLOCK, RBLOCK], 0, tl.float32)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex
r1 = rindex // 4
tmp0 = tl.load(in_ptr0 + r2, rmask, eviction_policy='evict_first',
other=0.0)
tmp1 = tl.load(in_ptr0 + 4 * r1, rmask, eviction_policy=
'evict_last', other=0.0)
tmp3 = tl.load(in_ptr0 + (1 + 4 * r1), rmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tl.load(in_ptr0 + (2 + 4 * r1), rmask, eviction_policy=
'evict_last', other=0.0)
tmp9 = tl.load(in_ptr0 + (3 + 4 * r1), rmask, eviction_policy=
'evict_last', other=0.0)
tmp16 = tl.load(in_ptr1 + r2, rmask, eviction_policy='evict_first',
other=0.0)
tmp17 = tl.load(in_ptr1 + 4 * r1, rmask, eviction_policy=
'evict_last', other=0.0)
tmp19 = tl.load(in_ptr1 + (1 + 4 * r1), rmask, eviction_policy=
'evict_last', other=0.0)
tmp22 = tl.load(in_ptr1 + (2 + 4 * r1), rmask, eviction_policy=
'evict_last', other=0.0)
tmp25 = tl.load(in_ptr1 + (3 + 4 * r1), rmask, eviction_policy=
'evict_last', other=0.0)
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = 1e-12
tmp14 = triton_helpers.maximum(tmp12, tmp13)
tmp15 = tmp0 / tmp14
tmp18 = tmp17 * tmp17
tmp20 = tmp19 * tmp19
tmp21 = tmp18 + tmp20
tmp23 = tmp22 * tmp22
tmp24 = tmp21 + tmp23
tmp26 = tmp25 * tmp25
tmp27 = tmp24 + tmp26
tmp28 = libdevice.sqrt(tmp27)
tmp29 = triton_helpers.maximum(tmp28, tmp13)
tmp30 = tmp16 / tmp29
tmp31 = tmp15 - tmp30
tmp32 = tmp31 * tmp31
tmp33 = tl.broadcast_to(tmp32, [XBLOCK, RBLOCK])
tmp35 = _tmp34 + tmp33
_tmp34 = tl.where(rmask, tmp35, _tmp34)
tmp34 = tl.sum(_tmp34, 1)[:, None]
tmp36 = 256.0
tmp37 = tmp34 / tmp36
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp37, 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((), (), torch.float32)
buf2 = buf1
del buf1
get_raw_stream(0)
triton_red_fused_div_mse_loss_0[grid(1)](buf2, arg0_1, arg1_1, 1,
256, XBLOCK=1, RBLOCK=256, num_warps=8, num_stages=1)
del arg0_1
del arg1_1
return buf2,
class NormedMSENew(nn.MSELoss):
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
gongda0e/AVT
|
NormedMSE
| false
| 15,444
|
[
"Apache-2.0"
] | 102
|
d6a7032b86416e852c76cc04a20ccabe34f111dc
|
https://github.com/gongda0e/AVT/tree/d6a7032b86416e852c76cc04a20ccabe34f111dc
|
output
|
import math
import torch
import torch.nn as nn
class output(nn.Module):
def __init__(self, scope=512):
super(output, self).__init__()
self.conv1 = nn.Conv2d(32, 1, 1)
self.sigmoid1 = nn.Sigmoid()
self.conv2 = nn.Conv2d(32, 4, 1)
self.sigmoid2 = nn.Sigmoid()
self.conv3 = nn.Conv2d(32, 1, 1)
self.sigmoid3 = nn.Sigmoid()
self.scope = 512
for m in self.modules():
if isinstance(m, nn.Conv2d):
nn.init.kaiming_normal_(m.weight, mode='fan_out',
nonlinearity='relu')
if m.bias is not None:
nn.init.constant_(m.bias, 0)
def forward(self, x):
score = self.sigmoid1(self.conv1(x))
loc = self.sigmoid2(self.conv2(x)) * self.scope
angle = (self.sigmoid3(self.conv3(x)) - 0.5) * math.pi
geo = torch.cat((loc, angle), 1)
return score, geo
def get_inputs():
return [torch.rand([4, 32, 64, 64])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_convolution_sigmoid_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)
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)
@triton.jit
def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 4096 % 4
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, None)
@triton.jit
def triton_poi_fused_convolution_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
tl.store(in_out_ptr0 + x0, tmp3, None)
@triton.jit
def triton_poi_fused_cat_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)
x1 = xindex // 4096 % 5
x0 = xindex % 4096
x2 = xindex // 20480
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 + 4096 * x1 + 16384 * x2), tmp4, other=0.0)
tmp6 = tl.sigmoid(tmp5)
tmp7 = 512.0
tmp8 = tmp6 * tmp7
tmp9 = tl.full(tmp8.shape, 0.0, tmp8.dtype)
tmp10 = tl.where(tmp4, tmp8, tmp9)
tmp11 = tmp0 >= tmp3
tl.full([1], 5, tl.int64)
tmp14 = tl.load(in_ptr1 + (x0 + 4096 * x2), tmp11, eviction_policy=
'evict_last', other=0.0)
tmp15 = tl.sigmoid(tmp14)
tmp16 = 0.5
tmp17 = tmp15 - tmp16
tmp18 = 3.141592653589793
tmp19 = tmp17 * tmp18
tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype)
tmp21 = tl.where(tmp11, tmp19, tmp20)
tmp22 = tl.where(tmp4, tmp10, tmp21)
tl.store(out_ptr0 + x3, tmp22, 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, (1, 32, 1, 1), (32, 1, 1, 1))
assert_size_stride(primals_2, (1,), (1,))
assert_size_stride(primals_3, (4, 32, 64, 64), (131072, 4096, 64, 1))
assert_size_stride(primals_4, (4, 32, 1, 1), (32, 1, 1, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (1, 32, 1, 1), (32, 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, 1, 64, 64), (4096, 4096, 64, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_sigmoid_0[grid(16384)](buf1, primals_2,
16384, XBLOCK=256, num_warps=4, num_stages=1)
del primals_2
buf2 = extern_kernels.convolution(primals_3, primals_4, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 4, 64, 64), (16384, 4096, 64, 1))
buf3 = buf2
del buf2
triton_poi_fused_convolution_1[grid(65536)](buf3, primals_5, 65536,
XBLOCK=512, num_warps=4, num_stages=1)
del primals_5
buf4 = extern_kernels.convolution(primals_3, 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_2[grid(16384)](buf5, primals_7, 16384,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_7
buf6 = empty_strided_cuda((4, 5, 64, 64), (20480, 4096, 64, 1),
torch.float32)
triton_poi_fused_cat_3[grid(81920)](buf3, buf5, buf6, 81920, XBLOCK
=512, num_warps=8, num_stages=1)
return (buf1, buf6, primals_1, primals_3, primals_4, primals_6, buf1,
buf3, buf5)
class outputNew(nn.Module):
def __init__(self, scope=512):
super(outputNew, self).__init__()
self.conv1 = nn.Conv2d(32, 1, 1)
self.sigmoid1 = nn.Sigmoid()
self.conv2 = nn.Conv2d(32, 4, 1)
self.sigmoid2 = nn.Sigmoid()
self.conv3 = nn.Conv2d(32, 1, 1)
self.sigmoid3 = nn.Sigmoid()
self.scope = 512
for m in self.modules():
if isinstance(m, nn.Conv2d):
nn.init.kaiming_normal_(m.weight, mode='fan_out',
nonlinearity='relu')
if m.bias is not None:
nn.init.constant_(m.bias, 0)
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
outputNew = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7])
return outputNew[0], outputNew[1]
|
glc12125/EAST
|
output
| false
| 15,445
|
[
"MIT"
] | 366
|
cec7ae98f9c21a475b935f74f4c3969f3a989bd4
|
https://github.com/glc12125/EAST/tree/cec7ae98f9c21a475b935f74f4c3969f3a989bd4
|
VirtualBatchNorm
|
import torch
from torch import nn
class VirtualBatchNorm(nn.Module):
"""
Applies Virtual Batch Normalization over a 4D input (a mini-batch
of 2D inputs with additional channel dimension) as described in
paper `Improved Techniques for Training GANs`:
https://arxiv.org/abs/1606.03498
.. math::
y = \\frac{x - \\mathrm{E}[x_\\text{ref}]}{ \\sqrt{\\mathrm{Var}[x_\\text{ref}] + \\epsilon}} * \\gamma + \\beta
VirtualBatchNorm requires two forward passes. First one is to
calculate mean and variance over a reference batch and second
is to calculate the actual output.
Args:
num_features: :math:`C` from an expected input of size
:math:`(N, C, H, W)`
eps: a value added to the denominator for numerical stability.
Default: 1e-5
"""
def __init__(self, num_features, eps=1e-05):
super(VirtualBatchNorm, self).__init__()
self.num_features = num_features
self.eps = eps
self.mean = None
self.var = None
self.weight = nn.parameter.Parameter(torch.Tensor(num_features))
self.bias = nn.parameter.Parameter(torch.Tensor(num_features))
self.reset_parameters()
def reset_parameters(self):
nn.init.ones_(self.weight)
nn.init.zeros_(self.bias)
def normalize(self, x):
y = (x - self.mean) / torch.sqrt(self.var + self.eps
) * self.weight.view(1, self.num_features, 1, 1) + self.bias.view(
1, self.num_features, 1, 1)
return y
def forward(self, x):
""""""
if self.mean is None and self.var is None:
self.mean = torch.mean(x, dim=0, keepdim=True)
self.var = torch.var(x, dim=0, keepdim=True)
out = self.normalize(x)
else:
out = self.normalize(x)
self.mean = None
self.var = None
return out
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
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_mean_var_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 + x0, xmask)
tmp1 = tl.load(in_ptr0 + (64 + x0), xmask)
tmp3 = tl.load(in_ptr0 + (128 + x0), xmask)
tmp5 = tl.load(in_ptr0 + (192 + x0), 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 = 3.0
tmp21 = tmp19 / tmp20
tl.store(out_ptr0 + x0, tmp8, xmask)
tl.store(out_ptr1 + x0, tmp21, xmask)
@triton.jit
def triton_poi_fused_add_div_mul_sqrt_sub_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
x3 = xindex
x4 = xindex % 64
x1 = xindex // 16 % 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')
tmp8 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 1e-05
tmp5 = tmp3 + tmp4
tmp6 = libdevice.sqrt(tmp5)
tmp7 = tmp2 / tmp6
tmp9 = tmp7 * tmp8
tmp11 = tmp9 + tmp10
tl.store(out_ptr0 + x3, tmp11, 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((1, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf1 = empty_strided_cuda((1, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_mean_var_0[grid(64)](primals_1, buf0, buf1, 64,
XBLOCK=64, num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_add_div_mul_sqrt_sub_1[grid(256)](primals_1, buf0,
buf1, primals_2, primals_3, buf2, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_2
del primals_3
return buf2, buf1, buf0, primals_1, buf0, buf1
class VirtualBatchNormNew(nn.Module):
"""
Applies Virtual Batch Normalization over a 4D input (a mini-batch
of 2D inputs with additional channel dimension) as described in
paper `Improved Techniques for Training GANs`:
https://arxiv.org/abs/1606.03498
.. math::
y = \\frac{x - \\mathrm{E}[x_\\text{ref}]}{ \\sqrt{\\mathrm{Var}[x_\\text{ref}] + \\epsilon}} * \\gamma + \\beta
VirtualBatchNorm requires two forward passes. First one is to
calculate mean and variance over a reference batch and second
is to calculate the actual output.
Args:
num_features: :math:`C` from an expected input of size
:math:`(N, C, H, W)`
eps: a value added to the denominator for numerical stability.
Default: 1e-5
"""
def __init__(self, num_features, eps=1e-05):
super(VirtualBatchNormNew, self).__init__()
self.num_features = num_features
self.eps = eps
self.mean = None
self.var = None
self.weight = nn.parameter.Parameter(torch.Tensor(num_features))
self.bias = nn.parameter.Parameter(torch.Tensor(num_features))
self.reset_parameters()
def reset_parameters(self):
nn.init.ones_(self.weight)
nn.init.zeros_(self.bias)
def normalize(self, x):
y = (x - self.mean) / torch.sqrt(self.var + self.eps
) * self.weight.view(1, self.num_features, 1, 1) + self.bias.view(
1, self.num_features, 1, 1)
return y
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]
|
goktug97/estorch
|
VirtualBatchNorm
| false
| 15,446
|
[
"MIT"
] | 53
|
aa7318b0662faadece1ac9eb241b895d028d613d
|
https://github.com/goktug97/estorch/tree/aa7318b0662faadece1ac9eb241b895d028d613d
|
SimmatModule
|
import torch
class SimmatModule(torch.nn.Module):
def __init__(self, padding=-1):
super().__init__()
self.padding = padding
self._hamming_index_loaded = None
self._hamming_index = None
def forward(self, query_embed, doc_embed, query_tok, doc_tok):
simmat = []
for a_emb, b_emb in zip(query_embed, doc_embed):
BAT, A, B = a_emb.shape[0], a_emb.shape[1], b_emb.shape[1]
a_denom = a_emb.norm(p=2, dim=2).reshape(BAT, A, 1).expand(BAT,
A, B) + 1e-09
b_denom = b_emb.norm(p=2, dim=2).reshape(BAT, 1, B).expand(BAT,
A, B) + 1e-09
perm = b_emb.permute(0, 2, 1)
sim = a_emb.bmm(perm)
sim = sim / (a_denom * b_denom)
nul = torch.zeros_like(sim)
sim = torch.where(query_tok.reshape(BAT, A, 1).expand(BAT, A, B
) == self.padding, nul, sim)
sim = torch.where(doc_tok.reshape(BAT, 1, B).expand(BAT, A, B) ==
self.padding, nul, sim)
simmat.append(sim)
return torch.stack(simmat, dim=1)
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand(
[4, 4, 1]), torch.rand([4, 1, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_add_div_mul_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel,
XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x4 = xindex // 4
x0 = xindex % 4
x2 = xindex // 16
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x4, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (1 + 4 * x4), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (2 + 4 * x4), xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr0 + (3 + 4 * x4), xmask, eviction_policy='evict_last')
tmp15 = tl.load(in_ptr1 + (4 * x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp17 = tl.load(in_ptr1 + (1 + 4 * x0 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp20 = tl.load(in_ptr1 + (2 + 4 * x0 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp23 = tl.load(in_ptr1 + (3 + 4 * x0 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = 1e-09
tmp14 = tmp12 + tmp13
tmp16 = tmp15 * tmp15
tmp18 = tmp17 * tmp17
tmp19 = tmp16 + tmp18
tmp21 = tmp20 * tmp20
tmp22 = tmp19 + tmp21
tmp24 = tmp23 * tmp23
tmp25 = tmp22 + tmp24
tmp26 = libdevice.sqrt(tmp25)
tmp27 = tmp26 + tmp13
tmp28 = tmp14 * tmp27
tmp29 = tmp0 / tmp28
tl.store(in_out_ptr0 + x3, tmp29, xmask)
@triton.jit
def triton_poi_fused_add_div_mul_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel,
XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x4 = xindex // 4
x0 = xindex % 4
x2 = xindex // 16
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (64 + 4 * x4), xmask, eviction_policy='evict_last'
)
tmp3 = tl.load(in_ptr0 + (65 + 4 * x4), xmask, eviction_policy='evict_last'
)
tmp6 = tl.load(in_ptr0 + (66 + 4 * x4), xmask, eviction_policy='evict_last'
)
tmp9 = tl.load(in_ptr0 + (67 + 4 * x4), xmask, eviction_policy='evict_last'
)
tmp15 = tl.load(in_ptr1 + (64 + 4 * x0 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp17 = tl.load(in_ptr1 + (65 + 4 * x0 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp20 = tl.load(in_ptr1 + (66 + 4 * x0 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp23 = tl.load(in_ptr1 + (67 + 4 * x0 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = 1e-09
tmp14 = tmp12 + tmp13
tmp16 = tmp15 * tmp15
tmp18 = tmp17 * tmp17
tmp19 = tmp16 + tmp18
tmp21 = tmp20 * tmp20
tmp22 = tmp19 + tmp21
tmp24 = tmp23 * tmp23
tmp25 = tmp22 + tmp24
tmp26 = libdevice.sqrt(tmp25)
tmp27 = tmp26 + tmp13
tmp28 = tmp14 * tmp27
tmp29 = tmp0 / tmp28
tl.store(in_out_ptr0 + x3, tmp29, xmask)
@triton.jit
def triton_poi_fused_add_div_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
x3 = xindex
x4 = xindex // 4
x0 = xindex % 4
x2 = xindex // 16
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (128 + 4 * x4), xmask, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (129 + 4 * x4), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (130 + 4 * x4), xmask, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr0 + (131 + 4 * x4), xmask, eviction_policy=
'evict_last')
tmp15 = tl.load(in_ptr1 + (128 + 4 * x0 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp17 = tl.load(in_ptr1 + (129 + 4 * x0 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp20 = tl.load(in_ptr1 + (130 + 4 * x0 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp23 = tl.load(in_ptr1 + (131 + 4 * x0 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = 1e-09
tmp14 = tmp12 + tmp13
tmp16 = tmp15 * tmp15
tmp18 = tmp17 * tmp17
tmp19 = tmp16 + tmp18
tmp21 = tmp20 * tmp20
tmp22 = tmp19 + tmp21
tmp24 = tmp23 * tmp23
tmp25 = tmp22 + tmp24
tmp26 = libdevice.sqrt(tmp25)
tmp27 = tmp26 + tmp13
tmp28 = tmp14 * tmp27
tmp29 = tmp0 / tmp28
tl.store(in_out_ptr0 + x3, tmp29, xmask)
@triton.jit
def triton_poi_fused_add_div_mul_3(in_out_ptr0, in_ptr0, in_ptr1, xnumel,
XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x4 = xindex // 4
x0 = xindex % 4
x2 = xindex // 16
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (192 + 4 * x4), xmask, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (193 + 4 * x4), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (194 + 4 * x4), xmask, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr0 + (195 + 4 * x4), xmask, eviction_policy=
'evict_last')
tmp15 = tl.load(in_ptr1 + (192 + 4 * x0 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp17 = tl.load(in_ptr1 + (193 + 4 * x0 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp20 = tl.load(in_ptr1 + (194 + 4 * x0 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp23 = tl.load(in_ptr1 + (195 + 4 * x0 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = 1e-09
tmp14 = tmp12 + tmp13
tmp16 = tmp15 * tmp15
tmp18 = tmp17 * tmp17
tmp19 = tmp16 + tmp18
tmp21 = tmp20 * tmp20
tmp22 = tmp19 + tmp21
tmp24 = tmp23 * tmp23
tmp25 = tmp22 + tmp24
tmp26 = libdevice.sqrt(tmp25)
tmp27 = tmp26 + tmp13
tmp28 = tmp14 * tmp27
tmp29 = tmp0 / tmp28
tl.store(in_out_ptr0 + x3, tmp29, xmask)
@triton.jit
def triton_poi_fused_stack_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
x1 = xindex // 4 % 16
x0 = xindex % 4
x2 = xindex // 64
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 4 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = -1.0
tmp7 = tmp5 == tmp6
tmp8 = tl.load(in_ptr1 + (4 * x2 + x1), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp9 = tmp8 == tmp6
tmp10 = tl.load(in_ptr2 + (x0 + 4 * x1 + 16 * x2), tmp4 & xmask, other=0.0)
tmp11 = 0.0
tmp12 = tl.where(tmp9, tmp11, tmp10)
tmp13 = tl.where(tmp7, tmp11, tmp12)
tmp14 = tl.full(tmp13.shape, 0.0, tmp13.dtype)
tmp15 = tl.where(tmp4, tmp13, tmp14)
tmp16 = tmp0 >= tmp3
tmp17 = tl.full([1], 8, tl.int64)
tmp18 = tmp0 < tmp17
tmp19 = tmp16 & tmp18
tmp20 = tl.load(in_ptr0 + (x0 + 4 * x2), tmp19 & xmask, eviction_policy
='evict_last', other=0.0)
tmp21 = tmp20 == tmp6
tmp22 = tl.load(in_ptr1 + (4 * x2 + (-4 + x1)), tmp19 & xmask,
eviction_policy='evict_last', other=0.0)
tmp23 = tmp22 == tmp6
tmp24 = tl.load(in_ptr3 + (x0 + 4 * (-4 + x1) + 16 * x2), tmp19 & xmask,
other=0.0)
tmp25 = tl.where(tmp23, tmp11, tmp24)
tmp26 = tl.where(tmp21, tmp11, tmp25)
tmp27 = tl.full(tmp26.shape, 0.0, tmp26.dtype)
tmp28 = tl.where(tmp19, tmp26, tmp27)
tmp29 = tmp0 >= tmp17
tmp30 = tl.full([1], 12, tl.int64)
tmp31 = tmp0 < tmp30
tmp32 = tmp29 & tmp31
tmp33 = tl.load(in_ptr0 + (x0 + 4 * x2), tmp32 & xmask, eviction_policy
='evict_last', other=0.0)
tmp34 = tmp33 == tmp6
tmp35 = tl.load(in_ptr1 + (4 * x2 + (-8 + x1)), tmp32 & xmask,
eviction_policy='evict_last', other=0.0)
tmp36 = tmp35 == tmp6
tmp37 = tl.load(in_ptr4 + (x0 + 4 * (-8 + x1) + 16 * x2), tmp32 & xmask,
other=0.0)
tmp38 = tl.where(tmp36, tmp11, tmp37)
tmp39 = tl.where(tmp34, tmp11, tmp38)
tmp40 = tl.full(tmp39.shape, 0.0, tmp39.dtype)
tmp41 = tl.where(tmp32, tmp39, tmp40)
tmp42 = tmp0 >= tmp30
tl.full([1], 16, tl.int64)
tmp45 = tl.load(in_ptr0 + (x0 + 4 * x2), tmp42 & xmask, eviction_policy
='evict_last', other=0.0)
tmp46 = tmp45 == tmp6
tmp47 = tl.load(in_ptr1 + (4 * x2 + (-12 + x1)), tmp42 & xmask,
eviction_policy='evict_last', other=0.0)
tmp48 = tmp47 == tmp6
tmp49 = tl.load(in_ptr5 + (x0 + 4 * (-12 + x1) + 16 * x2), tmp42 &
xmask, other=0.0)
tmp50 = tl.where(tmp48, tmp11, tmp49)
tmp51 = tl.where(tmp46, tmp11, tmp50)
tmp52 = tl.full(tmp51.shape, 0.0, tmp51.dtype)
tmp53 = tl.where(tmp42, tmp51, tmp52)
tmp54 = tl.where(tmp32, tmp41, tmp53)
tmp55 = tl.where(tmp19, tmp28, tmp54)
tmp56 = tl.where(tmp4, tmp15, tmp55)
tl.store(out_ptr0 + x3, tmp56, xmask)
def call(args):
arg0_1, arg1_1, arg2_1, arg3_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg2_1, (4, 4, 1), (4, 1, 1))
assert_size_stride(arg3_1, (4, 1, 4), (4, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(arg0_1, (4, 4, 4), (16, 4, 1),
0), reinterpret_tensor(arg1_1, (4, 4, 4), (16, 1, 4), 0), out=buf0)
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_add_div_mul_0[grid(64)](buf1, arg0_1, arg1_1, 64,
XBLOCK=64, num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(arg0_1, (4, 4, 4), (16, 4, 1),
64), reinterpret_tensor(arg1_1, (4, 4, 4), (16, 1, 4), 64), out
=buf2)
buf3 = buf2
del buf2
triton_poi_fused_add_div_mul_1[grid(64)](buf3, arg0_1, arg1_1, 64,
XBLOCK=64, num_warps=1, num_stages=1)
buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(arg0_1, (4, 4, 4), (16, 4, 1),
128), reinterpret_tensor(arg1_1, (4, 4, 4), (16, 1, 4), 128),
out=buf4)
buf5 = buf4
del buf4
triton_poi_fused_add_div_mul_2[grid(64)](buf5, arg0_1, arg1_1, 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(arg0_1, (4, 4, 4), (16, 4, 1),
192), reinterpret_tensor(arg1_1, (4, 4, 4), (16, 1, 4), 192),
out=buf6)
buf7 = buf6
del buf6
triton_poi_fused_add_div_mul_3[grid(64)](buf7, arg0_1, arg1_1, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del arg0_1
del arg1_1
buf8 = empty_strided_cuda((4, 16, 4), (64, 4, 1), torch.float32)
triton_poi_fused_stack_4[grid(256)](arg3_1, arg2_1, buf1, buf3,
buf5, buf7, buf8, 256, XBLOCK=128, num_warps=4, num_stages=1)
del arg2_1
del arg3_1
del buf1
del buf3
del buf5
del buf7
return reinterpret_tensor(buf8, (4, 4, 4, 4), (64, 16, 4, 1), 0),
class SimmatModuleNew(torch.nn.Module):
def __init__(self, padding=-1):
super().__init__()
self.padding = padding
self._hamming_index_loaded = None
self._hamming_index = None
def forward(self, input_0, input_1, input_2, input_3):
arg0_1 = input_0
arg1_1 = input_1
arg2_1 = input_2
arg3_1 = input_3
output = call([arg0_1, arg1_1, arg2_1, arg3_1])
return output[0]
|
gitter-badger/FlexNeuART
|
SimmatModule
| false
| 15,447
|
[
"Apache-2.0"
] | 101
|
f69e5421bdebe9db0d993b5470dace61872f90df
|
https://github.com/gitter-badger/FlexNeuART/tree/f69e5421bdebe9db0d993b5470dace61872f90df
|
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]
|
gist-ailab/uoais
|
NaiveGroupNorm
| false
| 15,448
|
[
"BSD-2-Clause"
] | 52
|
fb42d9a96cd54daad61c956d8d9d65dd0ebef4c7
|
https://github.com/gist-ailab/uoais/tree/fb42d9a96cd54daad61c956d8d9d65dd0ebef4c7
|
FocalLoss
|
import torch
import torch.nn as nn
class FocalLoss(nn.Module):
"""
Softmax and sigmoid focal loss.
copy from https://github.com/lonePatient/TorchBlocks
"""
def __init__(self, num_labels, activation_type='softmax', gamma=2.0,
alpha=0.25, epsilon=1e-09):
super(FocalLoss, self).__init__()
self.num_labels = num_labels
self.gamma = gamma
self.alpha = alpha
self.epsilon = epsilon
self.activation_type = activation_type
def forward(self, input, target):
"""
Args:
logits: model's output, shape of [batch_size, num_cls]
target: ground truth labels, shape of [batch_size]
Returns:
shape of [batch_size]
"""
if self.activation_type == 'softmax':
idx = target.view(-1, 1).long()
one_hot_key = torch.zeros(idx.size(0), self.num_labels, dtype=
torch.float32, device=idx.device)
one_hot_key = one_hot_key.scatter_(1, idx, 1)
logits = torch.softmax(input, dim=-1)
loss = -self.alpha * one_hot_key * torch.pow(1 - logits, self.gamma
) * (logits + self.epsilon).log()
loss = loss.sum(1)
elif self.activation_type == 'sigmoid':
multi_hot_key = target
logits = torch.sigmoid(input)
zero_hot_key = 1 - multi_hot_key
loss = -self.alpha * multi_hot_key * torch.pow(1 - logits, self
.gamma) * (logits + self.epsilon).log()
loss += -(1 - self.alpha) * zero_hot_key * torch.pow(logits,
self.gamma) * (1 - logits + self.epsilon).log()
return loss.mean()
def get_inputs():
return [torch.rand([4, 4, 256, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'num_labels': 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__softmax_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)
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, None)
tmp1 = tl.load(in_ptr0 + 4 * x1, None, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), None, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), None, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), None, 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, None)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, None)
tmp1 = tl.load(in_ptr0 + 4 * x1, None, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), None, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), None, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), None, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x2, tmp8, None)
@triton.jit
def triton_red_fused__to_copy_add_log_mean_mul_pow_rsub_scatter_sum_2(
in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr,
RBLOCK: tl.constexpr):
rnumel = 4096
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rbase = tl.arange(0, RBLOCK)[None, :]
_tmp42 = tl.full([XBLOCK, RBLOCK], 0, tl.float32)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex // 4 % 256
r0 = rindex % 4
r2 = rindex // 1024
r4 = rindex % 1024
tmp0 = tl.load(in_ptr0 + r1, rmask, eviction_policy='evict_last',
other=0.0)
tmp9 = tl.load(in_ptr1 + (r4 + 4096 * r2), rmask, eviction_policy=
'evict_first', other=0.0)
tmp17 = tl.load(in_ptr1 + (1024 + r4 + 4096 * r2), rmask,
eviction_policy='evict_first', other=0.0)
tmp25 = tl.load(in_ptr1 + (2048 + r4 + 4096 * r2), rmask,
eviction_policy='evict_first', other=0.0)
tmp33 = tl.load(in_ptr1 + (3072 + r4 + 4096 * r2), rmask,
eviction_policy='evict_first', other=0.0)
tmp1 = tmp0.to(tl.int64)
tmp2 = r0
tmp3 = tmp1 == tmp2
tmp4 = 1.0
tmp5 = 0.0
tmp6 = tl.where(tmp3, tmp4, tmp5)
tmp7 = -0.25
tmp8 = tmp6 * tmp7
tmp10 = tmp4 - tmp9
tmp11 = tmp10 * tmp10
tmp12 = tmp8 * tmp11
tmp13 = 1e-09
tmp14 = tmp9 + tmp13
tmp15 = tl_math.log(tmp14)
tmp16 = tmp12 * tmp15
tmp18 = tmp4 - tmp17
tmp19 = tmp18 * tmp18
tmp20 = tmp8 * tmp19
tmp21 = tmp17 + tmp13
tmp22 = tl_math.log(tmp21)
tmp23 = tmp20 * tmp22
tmp24 = tmp16 + tmp23
tmp26 = tmp4 - tmp25
tmp27 = tmp26 * tmp26
tmp28 = tmp8 * tmp27
tmp29 = tmp25 + tmp13
tmp30 = tl_math.log(tmp29)
tmp31 = tmp28 * tmp30
tmp32 = tmp24 + tmp31
tmp34 = tmp4 - tmp33
tmp35 = tmp34 * tmp34
tmp36 = tmp8 * tmp35
tmp37 = tmp33 + tmp13
tmp38 = tl_math.log(tmp37)
tmp39 = tmp36 * tmp38
tmp40 = tmp32 + tmp39
tmp41 = tl.broadcast_to(tmp40, [XBLOCK, RBLOCK])
tmp43 = _tmp42 + tmp41
_tmp42 = tl.where(rmask, tmp43, _tmp42)
tmp42 = tl.sum(_tmp42, 1)[:, None]
tmp44 = 4096.0
tmp45 = tmp42 / tmp44
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp45, 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, 256, 4), (4096, 1024, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 256, 4), (4096, 1024, 4, 1), torch
.float32)
get_raw_stream(0)
triton_poi_fused__softmax_0[grid(16384)](arg1_1, buf0, 16384,
XBLOCK=128, num_warps=4, num_stages=1)
del arg1_1
buf1 = empty_strided_cuda((4, 4, 256, 4), (4096, 1024, 4, 1), torch
.float32)
triton_poi_fused__softmax_1[grid(16384)](buf0, buf1, 16384, XBLOCK=
256, num_warps=4, num_stages=1)
del buf0
buf3 = empty_strided_cuda((), (), torch.float32)
buf4 = buf3
del buf3
triton_red_fused__to_copy_add_log_mean_mul_pow_rsub_scatter_sum_2[grid
(1)](buf4, arg0_1, buf1, 1, 4096, XBLOCK=1, RBLOCK=2048,
num_warps=16, num_stages=1)
del arg0_1
del buf1
return buf4,
class FocalLossNew(nn.Module):
"""
Softmax and sigmoid focal loss.
copy from https://github.com/lonePatient/TorchBlocks
"""
def __init__(self, num_labels, activation_type='softmax', gamma=2.0,
alpha=0.25, epsilon=1e-09):
super(FocalLossNew, self).__init__()
self.num_labels = num_labels
self.gamma = gamma
self.alpha = alpha
self.epsilon = epsilon
self.activation_type = activation_type
def forward(self, input_0, input_1):
arg1_1 = input_0
arg0_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
gitabtion/BertBasedCscModels
|
FocalLoss
| false
| 15,449
|
[
"Apache-2.0"
] | 158
|
1daf505d109c5922eeedb6674edbb1b73db21e45
|
https://github.com/gitabtion/BertBasedCscModels/tree/1daf505d109c5922eeedb6674edbb1b73db21e45
|
LinearClassifier
|
import logging
import random
import torch
import torch.nn.functional as F
import torch.nn as nn
from typing import List
import torch.onnx.operators
from functools import wraps
def singleton(cls):
"""
Singleton decorator
Args:
cls: singleton class
Returns:
- an instance of a singleton class
"""
instances = {}
@wraps(cls)
def getinstance(*args, **kwargs):
if cls not in instances:
instances[cls] = cls(*args, **kwargs)
return instances[cls]
return getinstance
def get_invalid_class_mask(classes: 'int', invalid_classes: 'List'):
"""
Create mask for invalid classes
Args:
classes: number of labels
invalid_classes: invalid class list
Returns:
- mask for invalid class
:math:`(1, L)` where L is the number of classes
"""
invalid_class_mask = torch.zeros(classes).bool()
if invalid_classes:
for idx in invalid_classes:
invalid_class_mask[idx] = True
invalid_class_mask = invalid_class_mask.unsqueeze(dim=0)
env = Environment()
if env.device.startswith('cuda'):
invalid_class_mask = invalid_class_mask
return invalid_class_mask
@singleton
class Environment:
"""
Environment is a running environment class.
Args:
profiling_window: profiling window size
configs: configs for running tasks
debug: running with debug information
no_warning: do not output warning informations
seed: initial seed for random and torch
device: running device
fp16: running with fp16
no_progress_bar: do not show progress bar
pb_interval: show progress bar with an interval
"""
def __init__(self, configs=None, profiling_window: 'int'=0, debug:
'bool'=False, no_warning: 'bool'=False, seed: 'int'=0, device:
'str'=None, fp16: 'bool'=False, no_progress_bar: 'bool'=False,
pb_interval: 'int'=1, custom_libs: 'str'=None):
self.profiling_window = profiling_window
self.configs = configs
self.debug = debug
self.no_warning = no_warning
self.seed = seed
self.fp16 = fp16
self.no_progress_bar = no_progress_bar
self.pb_interval = pb_interval
self.distributed_world = 1
self.rank = 0
self.local_rank = 0
if device is None:
if torch.cuda.is_available():
self.device = 'cuda'
else:
self.device = 'cpu'
else:
self.device = device
if self.device == 'cuda':
self._init_cuda()
self._init_log()
self._init_seed()
self._import_custom_lib(custom_libs)
def _init_log(self):
FORMAT = (
f"%(asctime)s | %(levelname)s | %(name)s |{f' RANK {self.rank} | ' if not self.is_master() else ' '}%(message)s"
)
logging.basicConfig(format=FORMAT, datefmt='%Y-%m-%d,%H:%M:%S',
level=logging.INFO)
if not self.is_master():
logging.disable(logging.INFO)
def _import_custom_lib(self, path):
"""
Import library manually
Args:
path: external libraries split with `,`
"""
if path:
path = path.strip('\n')
for line in path.split(','):
logger.info(f'import module from {line}')
line = line.replace('/', '.')
importlib.import_module(line)
def _init_cuda(self):
"""
Initialize cuda device
We assume that the user will not run ParaGen on more than one workers with only 1 GPU
used on each worker.
"""
if torch.cuda.device_count() > 1:
hvd.init()
torch.cuda.set_device(hvd.local_rank())
self.rank = hvd.rank()
self.local_rank = hvd.local_rank()
self.distributed_world = hvd.size()
torch.cuda.empty_cache()
def _init_seed(self):
"""
Initialize global seed
"""
random.seed(self.seed)
import torch
torch.manual_seed(self.seed)
if self.device == 'cuda':
torch.manual_seed(self.seed)
def is_master(self):
"""
check the current process is the master process
"""
return self.rank == 0
class LinearClassifier(nn.Module):
"""
Classifier with only on a linear projection.
Args:
d_model: feature dimensionality
labels: number of classes
invalid_classes (List): class that is not allowed to produce
"""
def __init__(self, d_model, labels, invalid_classes: 'List'=None):
super().__init__()
self._linear = nn.Linear(d_model, labels, bias=False)
self._invalid_class_mask = get_invalid_class_mask(labels,
invalid_classes) if invalid_classes else None
def forward(self, x):
"""
Args:
x: feature to predict labels
:math:`(*, D)`, where D is the feature dimension
Returns:
- log probability of each classes
:math: `(*, L)`, where L is the number of classes
"""
logits = self._linear(x)
if self._invalid_class_mask is not None:
logits = logits.masked_fill(self._invalid_class_mask, float('-inf')
)
logits = F.log_softmax(logits, dim=-1)
return logits
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'d_model': 4, 'labels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import logging
import random
import torch.nn as nn
from typing import List
import torch.onnx.operators
from functools import wraps
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused__log_softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused__log_softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
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 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0)
del primals_1
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__log_softmax_0[grid(256)](buf0, buf1, 256, XBLOCK=
256, num_warps=4, num_stages=1)
buf2 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf0
triton_poi_fused__log_softmax_1[grid(256)](buf1, buf2, 256, XBLOCK=
256, num_warps=4, num_stages=1)
del buf1
return buf2, reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), buf2
def singleton(cls):
"""
Singleton decorator
Args:
cls: singleton class
Returns:
- an instance of a singleton class
"""
instances = {}
@wraps(cls)
def getinstance(*args, **kwargs):
if cls not in instances:
instances[cls] = cls(*args, **kwargs)
return instances[cls]
return getinstance
def get_invalid_class_mask(classes: 'int', invalid_classes: 'List'):
"""
Create mask for invalid classes
Args:
classes: number of labels
invalid_classes: invalid class list
Returns:
- mask for invalid class
:math:`(1, L)` where L is the number of classes
"""
invalid_class_mask = torch.zeros(classes).bool()
if invalid_classes:
for idx in invalid_classes:
invalid_class_mask[idx] = True
invalid_class_mask = invalid_class_mask.unsqueeze(dim=0)
env = Environment()
if env.device.startswith('cuda'):
invalid_class_mask = invalid_class_mask
return invalid_class_mask
@singleton
class Environment:
"""
Environment is a running environment class.
Args:
profiling_window: profiling window size
configs: configs for running tasks
debug: running with debug information
no_warning: do not output warning informations
seed: initial seed for random and torch
device: running device
fp16: running with fp16
no_progress_bar: do not show progress bar
pb_interval: show progress bar with an interval
"""
def __init__(self, configs=None, profiling_window: 'int'=0, debug:
'bool'=False, no_warning: 'bool'=False, seed: 'int'=0, device:
'str'=None, fp16: 'bool'=False, no_progress_bar: 'bool'=False,
pb_interval: 'int'=1, custom_libs: 'str'=None):
self.profiling_window = profiling_window
self.configs = configs
self.debug = debug
self.no_warning = no_warning
self.seed = seed
self.fp16 = fp16
self.no_progress_bar = no_progress_bar
self.pb_interval = pb_interval
self.distributed_world = 1
self.rank = 0
self.local_rank = 0
if device is None:
if torch.cuda.is_available():
self.device = 'cuda'
else:
self.device = 'cpu'
else:
self.device = device
if self.device == 'cuda':
self._init_cuda()
self._init_log()
self._init_seed()
self._import_custom_lib(custom_libs)
def _init_log(self):
FORMAT = (
f"%(asctime)s | %(levelname)s | %(name)s |{f' RANK {self.rank} | ' if not self.is_master() else ' '}%(message)s"
)
logging.basicConfig(format=FORMAT, datefmt='%Y-%m-%d,%H:%M:%S',
level=logging.INFO)
if not self.is_master():
logging.disable(logging.INFO)
def _import_custom_lib(self, path):
"""
Import library manually
Args:
path: external libraries split with `,`
"""
if path:
path = path.strip('\n')
for line in path.split(','):
logger.info(f'import module from {line}')
line = line.replace('/', '.')
importlib.import_module(line)
def _init_cuda(self):
"""
Initialize cuda device
We assume that the user will not run ParaGen on more than one workers with only 1 GPU
used on each worker.
"""
if torch.cuda.device_count() > 1:
hvd.init()
torch.cuda.set_device(hvd.local_rank())
self.rank = hvd.rank()
self.local_rank = hvd.local_rank()
self.distributed_world = hvd.size()
torch.cuda.empty_cache()
def _init_seed(self):
"""
Initialize global seed
"""
random.seed(self.seed)
import torch
torch.manual_seed(self.seed)
if self.device == 'cuda':
torch.manual_seed(self.seed)
def is_master(self):
"""
check the current process is the master process
"""
return self.rank == 0
class LinearClassifierNew(nn.Module):
"""
Classifier with only on a linear projection.
Args:
d_model: feature dimensionality
labels: number of classes
invalid_classes (List): class that is not allowed to produce
"""
def __init__(self, d_model, labels, invalid_classes: 'List'=None):
super().__init__()
self._linear = nn.Linear(d_model, labels, bias=False)
self._invalid_class_mask = get_invalid_class_mask(labels,
invalid_classes) if invalid_classes else None
def forward(self, input_0):
primals_1 = self._linear.weight
primals_2 = input_0
output = call([primals_1, primals_2])
return output[0]
|
godweiyang/ParaGen
|
LinearClassifier
| false
| 15,450
|
[
"Apache-2.0"
] | 50
|
9665d1244ea38a41fc06b4e0a7f6411985e2221f
|
https://github.com/godweiyang/ParaGen/tree/9665d1244ea38a41fc06b4e0a7f6411985e2221f
|
ResidualConvUnit
|
import torch
from torch import nn
class ResidualConvUnit(nn.Module):
"""Residual convolution module.
"""
def __init__(self, features):
"""Init.
Args:
features (int): number of features
"""
super().__init__()
self.conv1 = nn.Conv2d(features, features, kernel_size=3, stride=1,
padding=1, bias=True)
self.conv2 = nn.Conv2d(features, features, kernel_size=3, stride=1,
padding=1, bias=True)
self.relu = nn.ReLU(inplace=True)
def forward(self, x):
"""Forward pass.
Args:
x (tensor): input
Returns:
tensor: output
"""
out = self.relu(x)
out = self.conv1(out)
out = self.relu(out)
out = self.conv2(out)
return out + x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'features': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch 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_relu_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = tl.full([1], 0, tl.int32)
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x3, tmp4, xmask)
@triton.jit
def triton_poi_fused_add_convolution_2(in_out_ptr0, in_ptr0, in_ptr1,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x3, xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tl.store(in_out_ptr0 + x3, tmp4, xmask)
tl.store(out_ptr0 + x3, tmp3, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_relu_0[grid(256)](primals_1, buf0, 256, XBLOCK=128,
num_warps=4, num_stages=1)
buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1))
buf2 = buf1
del buf1
triton_poi_fused_convolution_relu_1[grid(256)](buf2, primals_3, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_3
buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf3, (4, 4, 4, 4), (64, 16, 4, 1))
buf4 = buf3
del buf3
triton_poi_fused_add_convolution_2[grid(256)](buf4, primals_5, buf0,
primals_1, 256, XBLOCK=128, num_warps=4, num_stages=1)
del primals_1
del primals_5
return buf4, primals_2, primals_4, buf0, buf2
class ResidualConvUnitNew(nn.Module):
"""Residual convolution module.
"""
def __init__(self, features):
"""Init.
Args:
features (int): number of features
"""
super().__init__()
self.conv1 = nn.Conv2d(features, features, kernel_size=3, stride=1,
padding=1, bias=True)
self.conv2 = nn.Conv2d(features, features, kernel_size=3, stride=1,
padding=1, bias=True)
self.relu = nn.ReLU(inplace=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]
|
google/dynamic-video-depth
|
ResidualConvUnit
| false
| 15,451
|
[
"Apache-2.0"
] | 144
|
7dab8f9e156fa35735301695ea020aee7221fb31
|
https://github.com/google/dynamic-video-depth/tree/7dab8f9e156fa35735301695ea020aee7221fb31
|
DownsampleB
|
import torch
import torch.nn
from torch import nn
class DownsampleB(nn.Module):
def __init__(self, nIn, nOut, stride):
super(DownsampleB, self).__init__()
self.avg = nn.AvgPool2d(stride)
self.expand_ratio = nOut // nIn
def forward(self, x):
x = self.avg(x)
return torch.cat([x] + [x.mul(0)] * (self.expand_ratio - 1), 1)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'nIn': 4, 'nOut': 4, 'stride': 1}]
|
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
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_avg_pool2d_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_avg_pool2d_0[grid(256)](arg0_1, buf0, 256, XBLOCK=
128, num_warps=4, num_stages=1)
del arg0_1
return buf0,
class DownsampleBNew(nn.Module):
def __init__(self, nIn, nOut, stride):
super(DownsampleBNew, self).__init__()
self.avg = nn.AvgPool2d(stride)
self.expand_ratio = nOut // nIn
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
gpleiss/aum
|
DownsampleB
| false
| 15,452
|
[
"MIT"
] | 45
|
3c710662d74cdad9b299f541170070c0cb292042
|
https://github.com/gpleiss/aum/tree/3c710662d74cdad9b299f541170070c0cb292042
|
Conv2dBlock
|
import torch
from torch import nn
class Conv2dBlock(nn.Module):
def __init__(self, input_dim, output_dim, kernel_size, stride, padding=
0, dilation=1, norm='weight', activation='relu', pad_type='zero',
use_bias=True, *args, **karg):
super(Conv2dBlock, self).__init__()
self.conv = nn.Conv2d(input_dim, output_dim, kernel_size, stride,
padding=0, dilation=dilation, bias=use_bias)
if pad_type == 'reflect':
self.pad = nn.ReflectionPad2d(padding)
elif pad_type == 'zero':
self.pad = nn.ZeroPad2d(padding)
else:
assert 0, 'Unsupported padding type: {}'.format(pad_type)
norm_dim = output_dim
if norm == 'batch':
self.norm = nn.BatchNorm2d(norm_dim)
elif norm == 'inst':
self.norm = nn.InstanceNorm2d(norm_dim, track_running_stats=False)
elif norm == 'ln':
self.norm = nn.LayerNorm(norm_dim)
elif norm == 'none':
self.norm = nn.Identity()
elif norm == 'weight':
self.conv = nn.utils.weight_norm(self.conv)
self.norm = nn.Identity()
else:
assert 0, 'Unsupported normalization: {}'.format(norm)
if activation == 'relu':
self.activation = nn.ReLU(inplace=True)
elif activation == 'lrelu':
self.activation = nn.LeakyReLU(0.2, inplace=True)
elif activation == 'prelu':
self.activation = nn.PReLU()
elif activation == 'selu':
self.activation = nn.SELU(inplace=True)
elif activation == 'tanh':
self.activation = nn.Tanh()
elif activation == 'none':
self.activation = nn.Identity()
else:
assert 0, 'Unsupported activation: {}'.format(activation)
def forward(self, x):
x = self.conv(self.pad(x))
x = self.norm(x)
x = self.activation(x)
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'input_dim': 4, 'output_dim': 4, 'kernel_size': 4,
'stride': 1}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_per_fused__weight_norm_interface_0(in_out_ptr0, in_ptr0, in_ptr1,
out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 4
RBLOCK: tl.constexpr = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0)
tmp7 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp1 = tmp0 * tmp0
tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp4 = tl.where(xmask, tmp2, 0)
tmp5 = tl.sum(tmp4, 1)[:, None]
tmp6 = libdevice.sqrt(tmp5)
tmp8 = tmp7 / tmp6
tmp9 = tmp0 * tmp8
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp6, xmask)
tl.store(out_ptr0 + (r1 + 64 * x0), tmp9, xmask)
@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_1(in_out_ptr0,
in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x2, tmp4, xmask)
tl.store(out_ptr0 + x2, tmp6, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 1, 1, 1), (1, 1, 1, 1))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32)
buf1 = reinterpret_tensor(buf0, (4, 1, 1, 1), (1, 1, 1, 1), 0)
del buf0
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_per_fused__weight_norm_interface_0[grid(4)](buf1, primals_3,
primals_2, buf2, 4, 64, XBLOCK=1, num_warps=2, num_stages=1)
buf3 = extern_kernels.convolution(primals_1, buf2, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf3, (4, 4, 1, 1), (4, 1, 1, 1))
buf4 = buf3
del buf3
buf5 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.bool)
triton_poi_fused_convolution_relu_threshold_backward_1[grid(16)](buf4,
primals_4, buf5, 16, XBLOCK=16, num_warps=1, num_stages=1)
del primals_4
return buf4, buf2, primals_1, primals_2, primals_3, buf1, buf2, buf5
class Conv2dBlockNew(nn.Module):
def __init__(self, input_dim, output_dim, kernel_size, stride, padding=
0, dilation=1, norm='weight', activation='relu', pad_type='zero',
use_bias=True, *args, **karg):
super(Conv2dBlockNew, self).__init__()
self.conv = nn.Conv2d(input_dim, output_dim, kernel_size, stride,
padding=0, dilation=dilation, bias=use_bias)
if pad_type == 'reflect':
self.pad = nn.ReflectionPad2d(padding)
elif pad_type == 'zero':
self.pad = nn.ZeroPad2d(padding)
else:
assert 0, 'Unsupported padding type: {}'.format(pad_type)
norm_dim = output_dim
if norm == 'batch':
self.norm = nn.BatchNorm2d(norm_dim)
elif norm == 'inst':
self.norm = nn.InstanceNorm2d(norm_dim, track_running_stats=False)
elif norm == 'ln':
self.norm = nn.LayerNorm(norm_dim)
elif norm == 'none':
self.norm = nn.Identity()
elif norm == 'weight':
self.conv = nn.utils.weight_norm(self.conv)
self.norm = nn.Identity()
else:
assert 0, 'Unsupported normalization: {}'.format(norm)
if activation == 'relu':
self.activation = nn.ReLU(inplace=True)
elif activation == 'lrelu':
self.activation = nn.LeakyReLU(0.2, inplace=True)
elif activation == 'prelu':
self.activation = nn.PReLU()
elif activation == 'selu':
self.activation = nn.SELU(inplace=True)
elif activation == 'tanh':
self.activation = nn.Tanh()
elif activation == 'none':
self.activation = nn.Identity()
else:
assert 0, 'Unsupported activation: {}'.format(activation)
def forward(self, input_0):
primals_4 = self.conv.bias
primals_2 = self.conv.weight_g
primals_1 = self.conv.weight_v
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
google/dynamic-video-depth
|
Conv2dBlock
| false
| 15,453
|
[
"Apache-2.0"
] | 144
|
7dab8f9e156fa35735301695ea020aee7221fb31
|
https://github.com/google/dynamic-video-depth/tree/7dab8f9e156fa35735301695ea020aee7221fb31
|
CenterIntersection
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class CenterIntersection(nn.Module):
def __init__(self, dim):
super(CenterIntersection, self).__init__()
self.dim = dim
self.layers = nn.Parameter(torch.zeros(self.dim * 2 + 2, self.dim))
nn.init.xavier_uniform_(self.layers[:self.dim * 2, :])
def forward(self, embeddings):
w1, w2, b1, b2 = torch.split(self.layers, [self.dim, self.dim, 1, 1
], dim=0)
layer1_act = F.relu(F.linear(embeddings, w1, b1.view(-1)))
attention = F.softmax(F.linear(layer1_act, w2, b2.view(-1)), dim=0)
embedding = torch.sum(attention * embeddings, dim=0)
return embedding
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'dim': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
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 = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + (32 + x0), xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x2, tmp4, xmask)
tl.store(out_ptr0 + x2, tmp6, xmask)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 64
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (64 + x0), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (128 + x0), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (192 + x0), xmask, eviction_policy='evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x2, tmp9, xmask)
@triton.jit
def triton_poi_fused__softmax_mul_sum_2(in_ptr0, in_ptr1, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + (64 + x0), xmask)
tmp3 = tl.load(in_ptr0 + (128 + x0), xmask)
tmp5 = tl.load(in_ptr0 + (192 + x0), xmask)
tmp8 = tl.load(in_ptr1 + x0, xmask)
tmp11 = tl.load(in_ptr1 + (64 + x0), xmask)
tmp15 = tl.load(in_ptr1 + (128 + x0), xmask)
tmp19 = tl.load(in_ptr1 + (192 + x0), xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp7 = tmp0 / tmp6
tmp9 = tmp7 * tmp8
tmp10 = tmp1 / tmp6
tmp12 = tmp10 * tmp11
tmp13 = tmp9 + tmp12
tmp14 = tmp3 / tmp6
tmp16 = tmp14 * tmp15
tmp17 = tmp13 + tmp16
tmp18 = tmp5 / tmp6
tmp20 = tmp18 * tmp19
tmp21 = tmp17 + tmp20
tl.store(out_ptr0 + x0, tmp21, xmask)
def call(args):
primals_1, primals_2 = args
args.clear()
assert_size_stride(primals_1, (10, 4), (4, 1))
assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0)
buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf0
buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
get_raw_stream(0)
triton_poi_fused_relu_threshold_backward_0[grid(256)](buf1,
primals_1, buf5, 256, XBLOCK=256, num_warps=4, num_stages=1)
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(reinterpret_tensor(primals_1, (4,), (1,), 36),
reinterpret_tensor(buf1, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 4), (1, 4), 16), alpha=1,
beta=1, out=buf2)
buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__softmax_1[grid(256)](buf2, buf3, 256, XBLOCK=128,
num_warps=4, num_stages=1)
buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_mul_sum_2[grid(64)](buf3, primals_2, buf4,
64, XBLOCK=64, num_warps=1, num_stages=1)
del buf3
return buf4, primals_2, reinterpret_tensor(buf1, (64, 4), (4, 1), 0
), buf2, reinterpret_tensor(primals_1, (4, 4), (4, 1), 16), buf5
class CenterIntersectionNew(nn.Module):
def __init__(self, dim):
super(CenterIntersectionNew, self).__init__()
self.dim = dim
self.layers = nn.Parameter(torch.zeros(self.dim * 2 + 2, self.dim))
nn.init.xavier_uniform_(self.layers[:self.dim * 2, :])
def forward(self, input_0):
primals_1 = self.layers
primals_2 = input_0
output = call([primals_1, primals_2])
return output[0]
|
google-research/smore
|
CenterIntersection
| false
| 15,454
|
[
"Apache-2.0"
] | 78
|
e4ba95a7466ef7d018987bce7688b77bf2ea7e4f
|
https://github.com/google-research/smore/tree/e4ba95a7466ef7d018987bce7688b77bf2ea7e4f
|
ConvLayer
|
import torch
class ConvLayer(torch.nn.Module):
"""
A small wrapper around nn.Conv2d, so as to make the code cleaner and allow for experimentation with padding
"""
def __init__(self, in_channels, out_channels, kernel_size, stride):
super().__init__()
self.conv2d = torch.nn.Conv2d(in_channels, out_channels,
kernel_size, stride, padding=kernel_size // 2, padding_mode=
'reflect')
def forward(self, x):
return self.conv2d(x)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4,
'stride': 1}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language 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
@triton.jit
def triton_poi_fused_reflection_pad2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 8
x1 = xindex // 8 % 8
x2 = xindex // 64
x3 = xindex
tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-2 +
x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-2 + x1)) + 16 * x2),
xmask, eviction_policy='evict_last')
tl.store(out_ptr0 + x3, tmp0, xmask)
@triton.jit
def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 400
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 25 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_reflection_pad2d_0[grid(1024)](primals_3, buf0,
1024, XBLOCK=128, 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, 5, 5), (100, 25, 5, 1))
buf2 = buf1
del buf1
triton_poi_fused_convolution_1[grid(400)](buf2, primals_2, 400,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_2
return buf2, primals_1, buf0
class ConvLayerNew(torch.nn.Module):
"""
A small wrapper around nn.Conv2d, so as to make the code cleaner and allow for experimentation with padding
"""
def __init__(self, in_channels, out_channels, kernel_size, stride):
super().__init__()
self.conv2d = torch.nn.Conv2d(in_channels, out_channels,
kernel_size, stride, padding=kernel_size // 2, padding_mode=
'reflect')
def forward(self, input_0):
primals_1 = self.conv2d.weight
primals_2 = self.conv2d.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
gordicaleksa/pytorch-nst-feedforward
|
ConvLayer
| false
| 15,455
|
[
"MIT"
] | 50
|
00c96e8e3f1b0b7fb4c14254fd0c6f1281a29598
|
https://github.com/gordicaleksa/pytorch-nst-feedforward/tree/00c96e8e3f1b0b7fb4c14254fd0c6f1281a29598
|
RingLoss
|
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.parameter import Parameter
from torch.nn.modules.loss import CrossEntropyLoss
class RingLoss(nn.Module):
def __init__(self, type='auto', loss_weight=1.0, softmax_loss_weight=1.0):
"""
:param type: type of loss ('l1', 'l2', 'auto')
:param loss_weight: weight of loss, for 'l1' and 'l2', try with 0.01.
For 'auto', try with 1.0.
Source: https://github.com/Paralysis/ringloss
"""
super().__init__()
self.radius = Parameter(torch.Tensor(1))
self.radius.data.fill_(-1)
self.loss_weight = loss_weight
self.type = type
self.softmax = CrossEntropyLoss()
self.softmax_loss_weight = softmax_loss_weight
def forward(self, x, y):
softmax = self.softmax(x, y).mul_(self.softmax_loss_weight)
x = x.pow(2).sum(dim=1).pow(0.5)
if self.radius.data[0] < 0:
self.radius.data.fill_(x.mean().data)
if self.type == 'l1':
loss1 = F.smooth_l1_loss(x, self.radius.expand_as(x)).mul_(self
.loss_weight)
loss2 = F.smooth_l1_loss(self.radius.expand_as(x), x).mul_(self
.loss_weight)
ringloss = loss1 + loss2
elif self.type == 'auto':
diff = x.sub(self.radius.expand_as(x)) / x.mean().detach().clamp(
min=0.5)
diff_sq = torch.pow(torch.abs(diff), 2).mean()
ringloss = diff_sq.mul_(self.loss_weight)
else:
diff = x.sub(self.radius.expand_as(x))
diff_sq = torch.pow(torch.abs(diff), 2).mean()
ringloss = diff_sq.mul_(self.loss_weight)
return softmax + ringloss
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
import torch.nn as nn
from torch.nn.parameter import Parameter
from torch.nn.modules.loss import CrossEntropyLoss
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
tmp22 = 1.0
tmp23 = tmp21 * tmp22
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp23, None)
@triton.jit
def triton_poi_fused_pow_sum_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 16
x1 = xindex // 16
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask)
tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask)
tmp5 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask)
tmp8 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask)
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 + x2, tmp11, xmask)
@triton.jit
def triton_poi_fused_lt_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
tmp0 = tl.load(in_ptr0 + 0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
tmp2 = 0.0
tmp3 = tmp1 < tmp2
tl.store(out_ptr0 + tl.full([XBLOCK], 0, tl.int32), tmp3, 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, (1,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__log_softmax_0[grid(256)](arg1_1, buf0, 256,
XBLOCK=128, num_warps=4, num_stages=1)
buf1 = empty_strided_cuda((), (), torch.float32)
buf3 = buf1
del buf1
triton_per_fused__log_softmax_div_mul_neg_sum_1[grid(1)](buf3, buf0,
arg0_1, 1, 256, num_warps=2, num_stages=1)
del arg0_1
del buf0
buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_pow_sum_2[grid(64)](arg1_1, buf2, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del arg1_1
buf4 = empty_strided_cuda((), (), torch.bool)
triton_poi_fused_lt_3[grid(1)](arg2_1, buf4, 1, XBLOCK=1, num_warps
=1, num_stages=1)
del arg2_1
return buf3, buf2, buf4
class RingLossNew(nn.Module):
def __init__(self, type='auto', loss_weight=1.0, softmax_loss_weight=1.0):
"""
:param type: type of loss ('l1', 'l2', 'auto')
:param loss_weight: weight of loss, for 'l1' and 'l2', try with 0.01.
For 'auto', try with 1.0.
Source: https://github.com/Paralysis/ringloss
"""
super().__init__()
self.radius = Parameter(torch.Tensor(1))
self.radius.data.fill_(-1)
self.loss_weight = loss_weight
self.type = type
self.softmax = CrossEntropyLoss()
self.softmax_loss_weight = softmax_loss_weight
def forward(self, input_0, input_1):
arg2_1 = self.radius
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1, arg2_1])
return output[0]
|
gorogoroyasu/mlcomp
|
RingLoss
| false
| 15,456
|
[
"Apache-2.0"
] | 166
|
fc6572ca5b226b35df97f13badd4420b30468a3b
|
https://github.com/gorogoroyasu/mlcomp/tree/fc6572ca5b226b35df97f13badd4420b30468a3b
|
ClipL1
|
import torch
import torch.nn as nn
class ClipL1(nn.Module):
""" Clip L1 loss
From: https://github.com/HolmesShuan/AIM2020-Real-Super-Resolution/
ClipL1 Loss combines Clip function and L1 loss. self.clip_min sets the
gradients of well-trained pixels to zeros and clip_max works as a noise filter.
data range [0, 255]: (clip_min=0.0, clip_max=10.0),
for [0,1] set clip_min to 1/255=0.003921.
"""
def __init__(self, clip_min=0.0, clip_max=10.0):
super(ClipL1, self).__init__()
self.clip_max = clip_max
self.clip_min = clip_min
def forward(self, x: 'torch.Tensor', y: 'torch.Tensor') ->torch.Tensor:
loss = torch.mean(torch.clamp(torch.abs(x - y), self.clip_min, self
.clip_max))
return loss
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_abs_clamp_mean_sub_0(in_out_ptr0, in_ptr0, in_ptr1,
xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp1 = tl.load(in_ptr1 + r0, None)
tmp2 = tmp0 - tmp1
tmp3 = tl_math.abs(tmp2)
tmp4 = 0.0
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp6 = 10.0
tmp7 = triton_helpers.minimum(tmp5, tmp6)
tmp8 = tl.broadcast_to(tmp7, [RBLOCK])
tmp10 = triton_helpers.promote_to_tensor(tl.sum(tmp8, 0))
tmp11 = 256.0
tmp12 = tmp10 / tmp11
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp12, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((), (), torch.float32)
buf1 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_abs_clamp_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 ClipL1New(nn.Module):
""" Clip L1 loss
From: https://github.com/HolmesShuan/AIM2020-Real-Super-Resolution/
ClipL1 Loss combines Clip function and L1 loss. self.clip_min sets the
gradients of well-trained pixels to zeros and clip_max works as a noise filter.
data range [0, 255]: (clip_min=0.0, clip_max=10.0),
for [0,1] set clip_min to 1/255=0.003921.
"""
def __init__(self, clip_min=0.0, clip_max=10.0):
super(ClipL1New, self).__init__()
self.clip_max = clip_max
self.clip_min = clip_min
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
grofit/traiNNer
|
ClipL1
| false
| 15,457
|
[
"Apache-2.0"
] | 78
|
12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
https://github.com/grofit/traiNNer/tree/12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
CharbonnierLoss
|
import torch
import torch.nn as nn
def get_outnorm(x: 'torch.Tensor', out_norm: 'str'='') ->torch.Tensor:
""" Common function to get a loss normalization value. Can
normalize by either the batch size ('b'), the number of
channels ('c'), the image size ('i') or combinations
('bi', 'bci', etc)
"""
img_shape = x.shape
if not out_norm:
return 1
norm = 1
if 'b' in out_norm:
norm /= img_shape[0]
if 'c' in out_norm:
norm /= img_shape[-3]
if 'i' in out_norm:
norm /= img_shape[-1] * img_shape[-2]
return norm
class CharbonnierLoss(nn.Module):
"""Charbonnier Loss (L1)"""
def __init__(self, eps=1e-06, out_norm: 'str'='bci'):
super(CharbonnierLoss, self).__init__()
self.eps = eps
self.out_norm = out_norm
def forward(self, x, y):
norm = get_outnorm(x, self.out_norm)
loss = torch.sum(torch.sqrt((x - y).pow(2) + self.eps ** 2))
return loss * norm
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
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_pow_sqrt_sub_sum_0(in_out_ptr0, in_ptr0,
in_ptr1, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp1 = tl.load(in_ptr1 + r0, None)
tmp2 = tmp0 - tmp1
tmp3 = tmp2 * tmp2
tmp4 = 1e-12
tmp5 = tmp3 + tmp4
tmp6 = libdevice.sqrt(tmp5)
tmp7 = tl.broadcast_to(tmp6, [RBLOCK])
tmp9 = triton_helpers.promote_to_tensor(tl.sum(tmp7, 0))
tmp10 = 0.00390625
tmp11 = tmp9 * tmp10
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp11, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((), (), torch.float32)
buf1 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_add_mul_pow_sqrt_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,
def get_outnorm(x: 'torch.Tensor', out_norm: 'str'='') ->torch.Tensor:
""" Common function to get a loss normalization value. Can
normalize by either the batch size ('b'), the number of
channels ('c'), the image size ('i') or combinations
('bi', 'bci', etc)
"""
img_shape = x.shape
if not out_norm:
return 1
norm = 1
if 'b' in out_norm:
norm /= img_shape[0]
if 'c' in out_norm:
norm /= img_shape[-3]
if 'i' in out_norm:
norm /= img_shape[-1] * img_shape[-2]
return norm
class CharbonnierLossNew(nn.Module):
"""Charbonnier Loss (L1)"""
def __init__(self, eps=1e-06, out_norm: 'str'='bci'):
super(CharbonnierLossNew, self).__init__()
self.eps = eps
self.out_norm = out_norm
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
grofit/traiNNer
|
CharbonnierLoss
| false
| 15,458
|
[
"Apache-2.0"
] | 78
|
12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
https://github.com/grofit/traiNNer/tree/12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
GramMatrix
|
import torch
import torch.nn as nn
def get_outnorm(x: 'torch.Tensor', out_norm: 'str'='') ->torch.Tensor:
""" Common function to get a loss normalization value. Can
normalize by either the batch size ('b'), the number of
channels ('c'), the image size ('i') or combinations
('bi', 'bci', etc)
"""
img_shape = x.shape
if not out_norm:
return 1
norm = 1
if 'b' in out_norm:
norm /= img_shape[0]
if 'c' in out_norm:
norm /= img_shape[-3]
if 'i' in out_norm:
norm /= img_shape[-1] * img_shape[-2]
return norm
class GramMatrix(nn.Module):
def __init__(self, out_norm: 'str'='ci'):
""" Gram Matrix calculation.
Args:
out_norm: normalizes the Gram matrix. It depends on the
implementation, according to:
- the number of elements in each feature map channel ('i')
- Johnson et al. (2016): the total number of elements ('ci')
- Gatys et al. (2015): not normalizing ('')
"""
super().__init__()
self.out_norm = out_norm
def forward(self, x: 'torch.Tensor') ->torch.Tensor:
"""Calculate Gram matrix (x * x.T).
Args:
x: Tensor with shape of (b, c, h, w).
Returns:
Gram matrix of the tensor.
"""
norm = get_outnorm(x, self.out_norm)
mat = x.flatten(-2)
gram = mat @ mat.transpose(-2, -1)
return gram * norm
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_mul_0(in_out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = 0.015625
tmp2 = tmp0 * tmp1
tl.store(in_out_ptr0 + x0, tmp2, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(arg0_1, (4, 4, 16), (64, 16,
1), 0), reinterpret_tensor(arg0_1, (4, 16, 4), (64, 1, 16), 0),
out=buf0)
del arg0_1
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_mul_0[grid(64)](buf1, 64, XBLOCK=64, num_warps=1,
num_stages=1)
return buf1,
def get_outnorm(x: 'torch.Tensor', out_norm: 'str'='') ->torch.Tensor:
""" Common function to get a loss normalization value. Can
normalize by either the batch size ('b'), the number of
channels ('c'), the image size ('i') or combinations
('bi', 'bci', etc)
"""
img_shape = x.shape
if not out_norm:
return 1
norm = 1
if 'b' in out_norm:
norm /= img_shape[0]
if 'c' in out_norm:
norm /= img_shape[-3]
if 'i' in out_norm:
norm /= img_shape[-1] * img_shape[-2]
return norm
class GramMatrixNew(nn.Module):
def __init__(self, out_norm: 'str'='ci'):
""" Gram Matrix calculation.
Args:
out_norm: normalizes the Gram matrix. It depends on the
implementation, according to:
- the number of elements in each feature map channel ('i')
- Johnson et al. (2016): the total number of elements ('ci')
- Gatys et al. (2015): not normalizing ('')
"""
super().__init__()
self.out_norm = out_norm
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
grofit/traiNNer
|
GramMatrix
| false
| 15,459
|
[
"Apache-2.0"
] | 78
|
12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
https://github.com/grofit/traiNNer/tree/12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
BoxOffsetIntersection
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class BoxOffsetIntersection(nn.Module):
def __init__(self, dim):
super(BoxOffsetIntersection, self).__init__()
self.dim = dim
self.layers = nn.Parameter(torch.zeros(self.dim * 2 + 2, self.dim))
nn.init.xavier_uniform_(self.layers[:self.dim * 2, :])
def forward(self, embeddings):
w1, w2, b1, b2 = torch.split(self.layers, [self.dim, self.dim, 1, 1
], dim=0)
layer1_act = F.relu(F.linear(embeddings, w1, b1.view(-1)))
layer1_mean = torch.mean(layer1_act, dim=0)
gate = torch.sigmoid(F.linear(layer1_mean, w2, b2.view(-1)))
offset, _ = torch.min(embeddings, dim=0)
return offset * gate
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'dim': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_mean_relu_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + (32 + x0), xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (64 + x2), xmask)
tmp9 = tl.load(in_ptr0 + (128 + x2), xmask)
tmp13 = tl.load(in_ptr0 + (192 + x2), xmask)
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = tmp5 + tmp1
tmp7 = triton_helpers.maximum(tmp3, tmp6)
tmp8 = tmp4 + tmp7
tmp10 = tmp9 + tmp1
tmp11 = triton_helpers.maximum(tmp3, tmp10)
tmp12 = tmp8 + tmp11
tmp14 = tmp13 + tmp1
tmp15 = triton_helpers.maximum(tmp3, tmp14)
tmp16 = tmp12 + tmp15
tmp17 = 4.0
tmp18 = tmp16 / tmp17
tl.store(out_ptr0 + x2, tmp18, xmask)
@triton.jit
def triton_poi_fused_min_mul_sigmoid_1(in_ptr0, in_ptr1, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + (64 + x0), xmask)
tmp3 = tl.load(in_ptr0 + (128 + x0), xmask)
tmp5 = tl.load(in_ptr0 + (192 + x0), xmask)
tmp7 = tl.load(in_ptr1 + x0, xmask)
tmp2 = triton_helpers.minimum(tmp0, tmp1)
tmp4 = triton_helpers.minimum(tmp2, tmp3)
tmp6 = triton_helpers.minimum(tmp4, tmp5)
tmp8 = tl.sigmoid(tmp7)
tmp9 = tmp6 * tmp8
tl.store(out_ptr0 + x0, tmp9, xmask)
@triton.jit
def triton_poi_fused_relu_threshold_backward_2(in_ptr0, in_ptr1, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + (32 + x0), xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(out_ptr0 + x2, tmp6, xmask)
def call(args):
primals_1, primals_2 = args
args.clear()
assert_size_stride(primals_1, (10, 4), (4, 1))
assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0)
buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_mean_relu_0[grid(64)](buf0, primals_1, buf1, 64,
XBLOCK=64, num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.addmm(reinterpret_tensor(primals_1, (4,), (1,), 36),
reinterpret_tensor(buf1, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 4), (1, 4), 16), alpha=1,
beta=1, out=buf2)
buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_min_mul_sigmoid_1[grid(64)](primals_2, buf2, buf3,
64, XBLOCK=64, num_warps=1, num_stages=1)
buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_2[grid(256)](buf0,
primals_1, buf4, 256, XBLOCK=256, num_warps=4, num_stages=1)
del buf0
return buf3, primals_2, reinterpret_tensor(buf1, (16, 4), (4, 1), 0
), buf2, reinterpret_tensor(primals_1, (4, 4), (4, 1), 16), buf4
class BoxOffsetIntersectionNew(nn.Module):
def __init__(self, dim):
super(BoxOffsetIntersectionNew, self).__init__()
self.dim = dim
self.layers = nn.Parameter(torch.zeros(self.dim * 2 + 2, self.dim))
nn.init.xavier_uniform_(self.layers[:self.dim * 2, :])
def forward(self, input_0):
primals_1 = self.layers
primals_2 = input_0
output = call([primals_1, primals_2])
return output[0]
|
google-research/smore
|
BoxOffsetIntersection
| false
| 15,460
|
[
"Apache-2.0"
] | 78
|
e4ba95a7466ef7d018987bce7688b77bf2ea7e4f
|
https://github.com/google-research/smore/tree/e4ba95a7466ef7d018987bce7688b77bf2ea7e4f
|
AttentionBranch
|
import torch
import torch.nn as nn
class AttentionBranch(nn.Module):
"""Attention Branch."""
def __init__(self, nf, k_size=3):
super(AttentionBranch, self).__init__()
self.k1 = nn.Conv2d(nf, nf, kernel_size=k_size, padding=(k_size - 1
) // 2, bias=False)
self.lrelu = nn.LeakyReLU(negative_slope=0.2, inplace=True)
self.k2 = nn.Conv2d(nf, nf, 1)
self.sigmoid = nn.Sigmoid()
self.k3 = nn.Conv2d(nf, nf, kernel_size=k_size, padding=(k_size - 1
) // 2, bias=False)
self.k4 = nn.Conv2d(nf, nf, kernel_size=k_size, padding=(k_size - 1
) // 2, bias=False)
def forward(self, x):
y = self.k1(x)
y = self.lrelu(y)
y = self.k2(y)
y = self.sigmoid(y)
out = torch.mul(self.k3(x), y)
out = self.k4(out)
return out
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'nf': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_leaky_relu_0(in_out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = 0.0
tmp2 = tmp0 > tmp1
tmp3 = 0.2
tmp4 = tmp0 * tmp3
tmp5 = tl.where(tmp2, tmp0, tmp4)
tl.store(in_out_ptr0 + x0, tmp5, xmask)
@triton.jit
def triton_poi_fused_convolution_mul_sigmoid_1(in_out_ptr0, in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x3, xmask)
tmp2 = tmp0 + tmp1
tmp4 = tl.sigmoid(tmp2)
tmp5 = tmp3 * tmp4
tl.store(in_out_ptr0 + x3, tmp2, xmask)
tl.store(out_ptr0 + x3, tmp5, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = 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))
assert_size_stride(primals_3, (4, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_4, (4,), (1,))
assert_size_stride(primals_5, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_6, (4, 4, 3, 3), (36, 9, 3, 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 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_leaky_relu_0[grid(256)](buf1, 256, XBLOCK=256,
num_warps=4, num_stages=1)
buf2 = extern_kernels.convolution(buf1, primals_3, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 4, 4, 4), (64, 16, 4, 1))
buf4 = extern_kernels.convolution(primals_2, primals_5, 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))
buf3 = buf2
del buf2
buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_convolution_mul_sigmoid_1[grid(256)](buf3,
primals_4, buf4, buf5, 256, XBLOCK=256, num_warps=4, num_stages=1)
del primals_4
buf6 = extern_kernels.convolution(buf5, primals_6, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf6, (4, 4, 4, 4), (64, 16, 4, 1))
return (buf6, primals_1, primals_2, primals_3, primals_5, primals_6,
buf1, buf3, buf4, buf5)
class AttentionBranchNew(nn.Module):
"""Attention Branch."""
def __init__(self, nf, k_size=3):
super(AttentionBranchNew, self).__init__()
self.k1 = nn.Conv2d(nf, nf, kernel_size=k_size, padding=(k_size - 1
) // 2, bias=False)
self.lrelu = nn.LeakyReLU(negative_slope=0.2, inplace=True)
self.k2 = nn.Conv2d(nf, nf, 1)
self.sigmoid = nn.Sigmoid()
self.k3 = nn.Conv2d(nf, nf, kernel_size=k_size, padding=(k_size - 1
) // 2, bias=False)
self.k4 = nn.Conv2d(nf, nf, kernel_size=k_size, padding=(k_size - 1
) // 2, bias=False)
def forward(self, input_0):
primals_1 = self.k1.weight
primals_3 = self.k2.weight
primals_4 = self.k2.bias
primals_5 = self.k3.weight
primals_6 = self.k4.weight
primals_2 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6])
return output[0]
|
grofit/traiNNer
|
AttentionBranch
| false
| 15,461
|
[
"Apache-2.0"
] | 78
|
12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
https://github.com/grofit/traiNNer/tree/12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
VisErrorLossV13
|
import torch
import torch.nn.functional as F
from torch import nn
class VisErrorLossV13(nn.Module):
def __init__(self):
super(VisErrorLossV13, self).__init__()
def compute_l1_weighted_loss(self, hm_targets, hm_preds, vismap, ohem=1.0):
"""
:param hm_targets: [batch size, keypoint number, h, w]
:param hm_preds: [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
epsilon = 0.0001
hm_preds = F.relu(hm_preds, False)
amplitude = torch.max(hm_targets)
b, k, h, w = hm_targets.size()
hm_targets = hm_targets.view(b, k, -1)
hm_preds = hm_preds.view(b, k, -1)
vismap = vismap.view(b, k, 1).repeat(1, 1, h * w)
pos_ids = (hm_targets > amplitude / 10) & (vismap == 1)
neg_ids = (hm_targets <= amplitude / 10) & (vismap == 1)
diff = (hm_targets - hm_preds).abs()
pos_loss = (diff * pos_ids.float()).sum(2).sum(0) / (pos_ids.float(
).sum(2).sum(0) + epsilon)
neg_loss = (diff * neg_ids.float()).sum(2).sum(0) / (neg_ids.float(
).sum(2).sum(0) + epsilon)
total_loss = 0.5 * pos_loss + 0.5 * neg_loss
if ohem < 1:
k = int(total_loss.size(0) * ohem)
total_loss, _ = total_loss.topk(k)
return total_loss.mean()
def compute_l2_loss(self, hm_targets, hm_preds, vismap, ohem=1.0):
"""
:param hm_targets: [batch size, keypoint number, h, w]
:param hm_preds: [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
epsilon = 0.0001
hm_preds = F.relu(hm_preds, False)
b, k, h, w = hm_targets.size()
hm_targets = hm_targets.view(b, k, -1)
hm_preds = hm_preds.view(b, k, -1)
vismap = vismap.view(b, k, 1).repeat(1, 1, h * w)
ids = vismap == 1
diff = (hm_targets - hm_preds) ** 2
total_loss = (diff * ids.float()).sum(2).sum(0) / (ids.float().sum(
2).sum(0) + epsilon)
if ohem < 1:
k = int(total_loss.size(0) * ohem)
total_loss, _ = total_loss.topk(k)
return total_loss.mean()
def forward(self, hm_targets, hm_preds1, hm_preds2, vismap):
"""
:param hm_targets: list of 4 elements, each is [batch size, keypoint number, h, w]
:param hm_preds1: list of 4 elements, each is [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
loss1 = 0
for p in hm_preds1:
loss1 += self.compute_l1_weighted_loss(hm_targets, p, vismap)
loss1 /= 4.0
loss2 = self.compute_l1_weighted_loss(hm_targets, hm_preds2, vismap,
ohem=0.5)
return loss1 + loss2, loss1, loss2
def get_inputs():
return [torch.rand([4, 4, 16, 4]), torch.rand([4, 4, 4]), torch.rand([4,
4, 64]), torch.rand([4, 4, 1])]
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.functional as F
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_max_0(in_ptr0, out_ptr0, out_ptr1, out_ptr2, out_ptr3,
out_ptr4, 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)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
tmp3 = triton_helpers.promote_to_tensor(triton_helpers.max2(tmp1, 0))
tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp3, None)
tl.store(out_ptr1 + tl.full([1], 0, tl.int32), tmp3, None)
tl.store(out_ptr2 + tl.full([1], 0, tl.int32), tmp3, None)
tl.store(out_ptr3 + tl.full([1], 0, tl.int32), tmp3, None)
tl.store(out_ptr4 + tl.full([1], 0, tl.int32), tmp3, None)
@triton.jit
def triton_per_fused__to_copy_abs_bitwise_and_div_eq_gt_le_mul_relu_repeat_sub_sum_view_1(
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, out_ptr8, out_ptr9, out_ptr10, out_ptr11, out_ptr12,
out_ptr13, out_ptr14, out_ptr15, out_ptr16, out_ptr17, out_ptr18,
out_ptr19, xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0)
tmp1 = tl.load(in_ptr1 + (r1 + 64 * x0), xmask, other=0.0)
tmp6 = tl.load(in_ptr2 + 0)
tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
tmp11 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
tmp37 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
tmp41 = tl.load(in_ptr5 + 0)
tmp42 = tl.broadcast_to(tmp41, [XBLOCK, RBLOCK])
tmp68 = tl.load(in_ptr4 + (16 + x0), xmask, eviction_policy='evict_last')
tmp72 = tl.load(in_ptr6 + 0)
tmp73 = tl.broadcast_to(tmp72, [XBLOCK, RBLOCK])
tmp99 = tl.load(in_ptr4 + (32 + x0), xmask, eviction_policy='evict_last')
tmp103 = tl.load(in_ptr7 + 0)
tmp104 = tl.broadcast_to(tmp103, [XBLOCK, RBLOCK])
tmp130 = tl.load(in_ptr4 + (48 + x0), xmask, eviction_policy='evict_last')
tmp134 = tl.load(in_ptr8 + 0)
tmp135 = tl.broadcast_to(tmp134, [XBLOCK, RBLOCK])
tmp2 = tl.full([1, 1], 0, tl.int32)
tmp3 = triton_helpers.maximum(tmp2, tmp1)
tmp4 = tmp0 - tmp3
tmp5 = tl_math.abs(tmp4)
tmp8 = 0.1
tmp9 = tmp7 * tmp8
tmp10 = tmp0 > tmp9
tmp12 = 1.0
tmp13 = tmp11 == tmp12
tmp14 = tmp10 & tmp13
tmp15 = tmp14.to(tl.float32)
tmp16 = tmp5 * tmp15
tmp17 = tl.broadcast_to(tmp16, [XBLOCK, RBLOCK])
tmp19 = tl.where(xmask, tmp17, 0)
tmp20 = tl.sum(tmp19, 1)[:, None]
tmp21 = tmp0 <= tmp9
tmp22 = tmp21 & tmp13
tmp23 = tmp22.to(tl.float32)
tmp24 = tmp5 * tmp23
tmp25 = tl.broadcast_to(tmp24, [XBLOCK, RBLOCK])
tmp27 = tl.where(xmask, tmp25, 0)
tmp28 = tl.sum(tmp27, 1)[:, None]
tmp29 = tl.broadcast_to(tmp15, [XBLOCK, RBLOCK])
tmp31 = tl.where(xmask, tmp29, 0)
tmp32 = tl.sum(tmp31, 1)[:, None]
tmp33 = tl.broadcast_to(tmp23, [XBLOCK, RBLOCK])
tmp35 = tl.where(xmask, tmp33, 0)
tmp36 = tl.sum(tmp35, 1)[:, None]
tmp38 = triton_helpers.maximum(tmp2, tmp37)
tmp39 = tmp0 - tmp38
tmp40 = tl_math.abs(tmp39)
tmp43 = tmp42 * tmp8
tmp44 = tmp0 > tmp43
tmp45 = tmp44 & tmp13
tmp46 = tmp45.to(tl.float32)
tmp47 = tmp40 * tmp46
tmp48 = tl.broadcast_to(tmp47, [XBLOCK, RBLOCK])
tmp50 = tl.where(xmask, tmp48, 0)
tmp51 = tl.sum(tmp50, 1)[:, None]
tmp52 = tmp0 <= tmp43
tmp53 = tmp52 & tmp13
tmp54 = tmp53.to(tl.float32)
tmp55 = tmp40 * tmp54
tmp56 = tl.broadcast_to(tmp55, [XBLOCK, RBLOCK])
tmp58 = tl.where(xmask, tmp56, 0)
tmp59 = tl.sum(tmp58, 1)[:, None]
tmp60 = tl.broadcast_to(tmp46, [XBLOCK, RBLOCK])
tmp62 = tl.where(xmask, tmp60, 0)
tmp63 = tl.sum(tmp62, 1)[:, None]
tmp64 = tl.broadcast_to(tmp54, [XBLOCK, RBLOCK])
tmp66 = tl.where(xmask, tmp64, 0)
tmp67 = tl.sum(tmp66, 1)[:, None]
tmp69 = triton_helpers.maximum(tmp2, tmp68)
tmp70 = tmp0 - tmp69
tmp71 = tl_math.abs(tmp70)
tmp74 = tmp73 * tmp8
tmp75 = tmp0 > tmp74
tmp76 = tmp75 & tmp13
tmp77 = tmp76.to(tl.float32)
tmp78 = tmp71 * tmp77
tmp79 = tl.broadcast_to(tmp78, [XBLOCK, RBLOCK])
tmp81 = tl.where(xmask, tmp79, 0)
tmp82 = tl.sum(tmp81, 1)[:, None]
tmp83 = tmp0 <= tmp74
tmp84 = tmp83 & tmp13
tmp85 = tmp84.to(tl.float32)
tmp86 = tmp71 * tmp85
tmp87 = tl.broadcast_to(tmp86, [XBLOCK, RBLOCK])
tmp89 = tl.where(xmask, tmp87, 0)
tmp90 = tl.sum(tmp89, 1)[:, None]
tmp91 = tl.broadcast_to(tmp77, [XBLOCK, RBLOCK])
tmp93 = tl.where(xmask, tmp91, 0)
tmp94 = tl.sum(tmp93, 1)[:, None]
tmp95 = tl.broadcast_to(tmp85, [XBLOCK, RBLOCK])
tmp97 = tl.where(xmask, tmp95, 0)
tmp98 = tl.sum(tmp97, 1)[:, None]
tmp100 = triton_helpers.maximum(tmp2, tmp99)
tmp101 = tmp0 - tmp100
tmp102 = tl_math.abs(tmp101)
tmp105 = tmp104 * tmp8
tmp106 = tmp0 > tmp105
tmp107 = tmp106 & tmp13
tmp108 = tmp107.to(tl.float32)
tmp109 = tmp102 * tmp108
tmp110 = tl.broadcast_to(tmp109, [XBLOCK, RBLOCK])
tmp112 = tl.where(xmask, tmp110, 0)
tmp113 = tl.sum(tmp112, 1)[:, None]
tmp114 = tmp0 <= tmp105
tmp115 = tmp114 & tmp13
tmp116 = tmp115.to(tl.float32)
tmp117 = tmp102 * tmp116
tmp118 = tl.broadcast_to(tmp117, [XBLOCK, RBLOCK])
tmp120 = tl.where(xmask, tmp118, 0)
tmp121 = tl.sum(tmp120, 1)[:, None]
tmp122 = tl.broadcast_to(tmp108, [XBLOCK, RBLOCK])
tmp124 = tl.where(xmask, tmp122, 0)
tmp125 = tl.sum(tmp124, 1)[:, None]
tmp126 = tl.broadcast_to(tmp116, [XBLOCK, RBLOCK])
tmp128 = tl.where(xmask, tmp126, 0)
tmp129 = tl.sum(tmp128, 1)[:, None]
tmp131 = triton_helpers.maximum(tmp2, tmp130)
tmp132 = tmp0 - tmp131
tmp133 = tl_math.abs(tmp132)
tmp136 = tmp135 * tmp8
tmp137 = tmp0 > tmp136
tmp138 = tmp137 & tmp13
tmp139 = tmp138.to(tl.float32)
tmp140 = tmp133 * tmp139
tmp141 = tl.broadcast_to(tmp140, [XBLOCK, RBLOCK])
tmp143 = tl.where(xmask, tmp141, 0)
tmp144 = tl.sum(tmp143, 1)[:, None]
tmp145 = tmp0 <= tmp136
tmp146 = tmp145 & tmp13
tmp147 = tmp146.to(tl.float32)
tmp148 = tmp133 * tmp147
tmp149 = tl.broadcast_to(tmp148, [XBLOCK, RBLOCK])
tmp151 = tl.where(xmask, tmp149, 0)
tmp152 = tl.sum(tmp151, 1)[:, None]
tmp153 = tl.broadcast_to(tmp139, [XBLOCK, RBLOCK])
tmp155 = tl.where(xmask, tmp153, 0)
tmp156 = tl.sum(tmp155, 1)[:, None]
tmp157 = tl.broadcast_to(tmp147, [XBLOCK, RBLOCK])
tmp159 = tl.where(xmask, tmp157, 0)
tmp160 = tl.sum(tmp159, 1)[:, None]
tl.store(out_ptr0 + x0, tmp20, xmask)
tl.store(out_ptr1 + x0, tmp28, xmask)
tl.store(out_ptr2 + x0, tmp32, xmask)
tl.store(out_ptr3 + x0, tmp36, xmask)
tl.store(out_ptr4 + x0, tmp51, xmask)
tl.store(out_ptr5 + x0, tmp59, xmask)
tl.store(out_ptr6 + x0, tmp63, xmask)
tl.store(out_ptr7 + x0, tmp67, xmask)
tl.store(out_ptr8 + x0, tmp82, xmask)
tl.store(out_ptr9 + x0, tmp90, xmask)
tl.store(out_ptr10 + x0, tmp94, xmask)
tl.store(out_ptr11 + x0, tmp98, xmask)
tl.store(out_ptr12 + x0, tmp113, xmask)
tl.store(out_ptr13 + x0, tmp121, xmask)
tl.store(out_ptr14 + x0, tmp125, xmask)
tl.store(out_ptr15 + x0, tmp129, xmask)
tl.store(out_ptr16 + x0, tmp144, xmask)
tl.store(out_ptr17 + x0, tmp152, xmask)
tl.store(out_ptr18 + x0, tmp156, xmask)
tl.store(out_ptr19 + x0, tmp160, xmask)
@triton.jit
def triton_poi_fused_add_div_mul_sum_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + (4 + x0), xmask)
tmp3 = tl.load(in_ptr0 + (8 + x0), xmask)
tmp5 = tl.load(in_ptr0 + (12 + x0), xmask)
tmp7 = tl.load(in_ptr1 + x0, xmask)
tmp8 = tl.load(in_ptr1 + (4 + x0), xmask)
tmp10 = tl.load(in_ptr1 + (8 + x0), xmask)
tmp12 = tl.load(in_ptr1 + (12 + x0), xmask)
tmp19 = tl.load(in_ptr2 + x0, xmask)
tmp20 = tl.load(in_ptr2 + (4 + x0), xmask)
tmp22 = tl.load(in_ptr2 + (8 + x0), xmask)
tmp24 = tl.load(in_ptr2 + (12 + x0), xmask)
tmp26 = tl.load(in_ptr3 + x0, xmask)
tmp27 = tl.load(in_ptr3 + (4 + x0), xmask)
tmp29 = tl.load(in_ptr3 + (8 + x0), xmask)
tmp31 = tl.load(in_ptr3 + (12 + x0), xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp9 = tmp7 + tmp8
tmp11 = tmp9 + tmp10
tmp13 = tmp11 + tmp12
tmp14 = 0.0001
tmp15 = tmp13 + tmp14
tmp16 = tmp6 / tmp15
tmp17 = 0.5
tmp18 = tmp16 * tmp17
tmp21 = tmp19 + tmp20
tmp23 = tmp21 + tmp22
tmp25 = tmp23 + tmp24
tmp28 = tmp26 + tmp27
tmp30 = tmp28 + tmp29
tmp32 = tmp30 + tmp31
tmp33 = tmp32 + tmp14
tmp34 = tmp25 / tmp33
tmp35 = tmp34 * tmp17
tmp36 = tmp18 + tmp35
tl.store(out_ptr0 + x0, tmp36, xmask)
@triton.jit
def triton_per_fused_mean_3(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl.
constexpr):
RBLOCK: tl.constexpr = 2
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.sum(tmp1, 1)[:, None]
tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp3, None)
@triton.jit
def triton_per_fused_add_div_mean_mul_sum_4(in_out_ptr0, in_out_ptr1,
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, in_ptr13, in_ptr14,
in_ptr15, out_ptr7, 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)
tmp7 = tl.load(in_ptr1 + r0, None)
tmp8 = tl.load(in_ptr1 + (4 + r0), None)
tmp10 = tl.load(in_ptr1 + (8 + r0), None)
tmp12 = tl.load(in_ptr1 + (12 + r0), None)
tmp19 = tl.load(in_ptr2 + r0, None)
tmp20 = tl.load(in_ptr2 + (4 + r0), None)
tmp22 = tl.load(in_ptr2 + (8 + r0), None)
tmp24 = tl.load(in_ptr2 + (12 + r0), None)
tmp26 = tl.load(in_ptr3 + r0, None)
tmp27 = tl.load(in_ptr3 + (4 + r0), None)
tmp29 = tl.load(in_ptr3 + (8 + r0), None)
tmp31 = tl.load(in_ptr3 + (12 + r0), None)
tmp40 = tl.load(in_ptr4 + r0, None)
tmp41 = tl.load(in_ptr4 + (4 + r0), None)
tmp43 = tl.load(in_ptr4 + (8 + r0), None)
tmp45 = tl.load(in_ptr4 + (12 + r0), None)
tmp47 = tl.load(in_ptr5 + r0, None)
tmp48 = tl.load(in_ptr5 + (4 + r0), None)
tmp50 = tl.load(in_ptr5 + (8 + r0), None)
tmp52 = tl.load(in_ptr5 + (12 + r0), None)
tmp57 = tl.load(in_ptr6 + r0, None)
tmp58 = tl.load(in_ptr6 + (4 + r0), None)
tmp60 = tl.load(in_ptr6 + (8 + r0), None)
tmp62 = tl.load(in_ptr6 + (12 + r0), None)
tmp64 = tl.load(in_ptr7 + r0, None)
tmp65 = tl.load(in_ptr7 + (4 + r0), None)
tmp67 = tl.load(in_ptr7 + (8 + r0), None)
tmp69 = tl.load(in_ptr7 + (12 + r0), None)
tmp78 = tl.load(in_ptr8 + r0, None)
tmp79 = tl.load(in_ptr8 + (4 + r0), None)
tmp81 = tl.load(in_ptr8 + (8 + r0), None)
tmp83 = tl.load(in_ptr8 + (12 + r0), None)
tmp85 = tl.load(in_ptr9 + r0, None)
tmp86 = tl.load(in_ptr9 + (4 + r0), None)
tmp88 = tl.load(in_ptr9 + (8 + r0), None)
tmp90 = tl.load(in_ptr9 + (12 + r0), None)
tmp95 = tl.load(in_ptr10 + r0, None)
tmp96 = tl.load(in_ptr10 + (4 + r0), None)
tmp98 = tl.load(in_ptr10 + (8 + r0), None)
tmp100 = tl.load(in_ptr10 + (12 + r0), None)
tmp102 = tl.load(in_ptr11 + r0, None)
tmp103 = tl.load(in_ptr11 + (4 + r0), None)
tmp105 = tl.load(in_ptr11 + (8 + r0), None)
tmp107 = tl.load(in_ptr11 + (12 + r0), None)
tmp116 = tl.load(in_ptr12 + r0, None)
tmp117 = tl.load(in_ptr12 + (4 + r0), None)
tmp119 = tl.load(in_ptr12 + (8 + r0), None)
tmp121 = tl.load(in_ptr12 + (12 + r0), None)
tmp123 = tl.load(in_ptr13 + r0, None)
tmp124 = tl.load(in_ptr13 + (4 + r0), None)
tmp126 = tl.load(in_ptr13 + (8 + r0), None)
tmp128 = tl.load(in_ptr13 + (12 + r0), None)
tmp133 = tl.load(in_ptr14 + r0, None)
tmp134 = tl.load(in_ptr14 + (4 + r0), None)
tmp136 = tl.load(in_ptr14 + (8 + r0), None)
tmp138 = tl.load(in_ptr14 + (12 + r0), None)
tmp140 = tl.load(in_ptr15 + r0, None)
tmp141 = tl.load(in_ptr15 + (4 + r0), None)
tmp143 = tl.load(in_ptr15 + (8 + r0), None)
tmp145 = tl.load(in_ptr15 + (12 + r0), None)
tmp166 = tl.load(in_out_ptr1 + 0)
tmp167 = tl.broadcast_to(tmp166, [XBLOCK, 1])
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp9 = tmp7 + tmp8
tmp11 = tmp9 + tmp10
tmp13 = tmp11 + tmp12
tmp14 = 0.0001
tmp15 = tmp13 + tmp14
tmp16 = tmp6 / tmp15
tmp17 = 0.5
tmp18 = tmp16 * tmp17
tmp21 = tmp19 + tmp20
tmp23 = tmp21 + tmp22
tmp25 = tmp23 + tmp24
tmp28 = tmp26 + tmp27
tmp30 = tmp28 + tmp29
tmp32 = tmp30 + tmp31
tmp33 = tmp32 + tmp14
tmp34 = tmp25 / tmp33
tmp35 = tmp34 * tmp17
tmp36 = tmp18 + tmp35
tmp37 = tl.broadcast_to(tmp36, [XBLOCK, RBLOCK])
tmp39 = tl.sum(tmp37, 1)[:, None]
tmp42 = tmp40 + tmp41
tmp44 = tmp42 + tmp43
tmp46 = tmp44 + tmp45
tmp49 = tmp47 + tmp48
tmp51 = tmp49 + tmp50
tmp53 = tmp51 + tmp52
tmp54 = tmp53 + tmp14
tmp55 = tmp46 / tmp54
tmp56 = tmp55 * tmp17
tmp59 = tmp57 + tmp58
tmp61 = tmp59 + tmp60
tmp63 = tmp61 + tmp62
tmp66 = tmp64 + tmp65
tmp68 = tmp66 + tmp67
tmp70 = tmp68 + tmp69
tmp71 = tmp70 + tmp14
tmp72 = tmp63 / tmp71
tmp73 = tmp72 * tmp17
tmp74 = tmp56 + tmp73
tmp75 = tl.broadcast_to(tmp74, [XBLOCK, RBLOCK])
tmp77 = tl.sum(tmp75, 1)[:, None]
tmp80 = tmp78 + tmp79
tmp82 = tmp80 + tmp81
tmp84 = tmp82 + tmp83
tmp87 = tmp85 + tmp86
tmp89 = tmp87 + tmp88
tmp91 = tmp89 + tmp90
tmp92 = tmp91 + tmp14
tmp93 = tmp84 / tmp92
tmp94 = tmp93 * tmp17
tmp97 = tmp95 + tmp96
tmp99 = tmp97 + tmp98
tmp101 = tmp99 + tmp100
tmp104 = tmp102 + tmp103
tmp106 = tmp104 + tmp105
tmp108 = tmp106 + tmp107
tmp109 = tmp108 + tmp14
tmp110 = tmp101 / tmp109
tmp111 = tmp110 * tmp17
tmp112 = tmp94 + tmp111
tmp113 = tl.broadcast_to(tmp112, [XBLOCK, RBLOCK])
tmp115 = tl.sum(tmp113, 1)[:, None]
tmp118 = tmp116 + tmp117
tmp120 = tmp118 + tmp119
tmp122 = tmp120 + tmp121
tmp125 = tmp123 + tmp124
tmp127 = tmp125 + tmp126
tmp129 = tmp127 + tmp128
tmp130 = tmp129 + tmp14
tmp131 = tmp122 / tmp130
tmp132 = tmp131 * tmp17
tmp135 = tmp133 + tmp134
tmp137 = tmp135 + tmp136
tmp139 = tmp137 + tmp138
tmp142 = tmp140 + tmp141
tmp144 = tmp142 + tmp143
tmp146 = tmp144 + tmp145
tmp147 = tmp146 + tmp14
tmp148 = tmp139 / tmp147
tmp149 = tmp148 * tmp17
tmp150 = tmp132 + tmp149
tmp151 = tl.broadcast_to(tmp150, [XBLOCK, RBLOCK])
tmp153 = tl.sum(tmp151, 1)[:, None]
tmp154 = 4.0
tmp155 = tmp39 / tmp154
tmp156 = 0.0
tmp157 = tmp155 + tmp156
tmp158 = tmp77 / tmp154
tmp159 = tmp157 + tmp158
tmp160 = tmp115 / tmp154
tmp161 = tmp159 + tmp160
tmp162 = tmp153 / tmp154
tmp163 = tmp161 + tmp162
tmp164 = 0.25
tmp165 = tmp163 * tmp164
tmp168 = 2.0
tmp169 = tmp167 / tmp168
tmp170 = tmp165 + tmp169
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp165, None)
tl.debug_barrier()
tl.store(in_out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp169, None)
tl.store(out_ptr7 + tl.full([XBLOCK, 1], 0, tl.int32), tmp170, None)
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, 16, 4), (256, 64, 4, 1))
assert_size_stride(arg2_1, (4, 4, 1), (4, 1, 1))
assert_size_stride(arg3_1, (4, 4, 64), (256, 64, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((), (), torch.float32)
buf9 = empty_strided_cuda((), (), torch.float32)
buf16 = empty_strided_cuda((), (), torch.float32)
buf23 = empty_strided_cuda((), (), torch.float32)
buf30 = empty_strided_cuda((), (), torch.float32)
get_raw_stream(0)
triton_per_fused_max_0[grid(1)](arg1_1, buf0, buf9, buf16, buf23,
buf30, 1, 1024, num_warps=8, num_stages=1)
buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf10 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf12 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf11 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf13 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf17 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf19 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf18 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf20 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf24 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf26 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf25 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf27 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf31 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf33 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf32 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf34 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_per_fused__to_copy_abs_bitwise_and_div_eq_gt_le_mul_relu_repeat_sub_sum_view_1[
grid(16)](arg1_1, arg3_1, buf0, arg2_1, arg0_1, buf9, buf16,
buf23, buf30, buf1, buf3, buf2, buf4, buf10, buf12, buf11,
buf13, buf17, buf19, buf18, buf20, buf24, buf26, buf25, buf27,
buf31, buf33, buf32, buf34, 16, 64, XBLOCK=8, num_warps=4,
num_stages=1)
del arg0_1
del arg1_1
del arg2_1
del arg3_1
del buf0
del buf16
buf5 = empty_strided_cuda((4,), (1,), torch.float32)
triton_poi_fused_add_div_mul_sum_2[grid(4)](buf1, buf2, buf3, buf4,
buf5, 4, XBLOCK=4, num_warps=1, num_stages=1)
del buf1
del buf2
del buf3
del buf4
buf6 = torch.ops.aten.topk.default(buf5, 2)
del buf5
buf7 = buf6[0]
del buf6
buf38 = buf9
del buf9
triton_per_fused_mean_3[grid(1)](buf7, buf38, 1, 2, XBLOCK=1,
num_warps=2, num_stages=1)
del buf7
buf15 = buf30
del buf30
buf37 = buf15
del buf15
buf39 = buf38
del buf38
buf40 = buf23
del buf23
triton_per_fused_add_div_mean_mul_sum_4[grid(1)](buf37, buf39,
buf10, buf11, buf12, buf13, buf17, buf18, buf19, buf20, buf24,
buf25, buf26, buf27, buf31, buf32, buf33, buf34, buf40, 1, 4,
XBLOCK=1, num_warps=2, num_stages=1)
del buf10
del buf11
del buf12
del buf13
del buf17
del buf18
del buf19
del buf20
del buf24
del buf25
del buf26
del buf27
del buf31
del buf32
del buf33
del buf34
return buf40, buf37, buf39
class VisErrorLossV13New(nn.Module):
def __init__(self):
super(VisErrorLossV13New, self).__init__()
def compute_l1_weighted_loss(self, hm_targets, hm_preds, vismap, ohem=1.0):
"""
:param hm_targets: [batch size, keypoint number, h, w]
:param hm_preds: [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
epsilon = 0.0001
hm_preds = F.relu(hm_preds, False)
amplitude = torch.max(hm_targets)
b, k, h, w = hm_targets.size()
hm_targets = hm_targets.view(b, k, -1)
hm_preds = hm_preds.view(b, k, -1)
vismap = vismap.view(b, k, 1).repeat(1, 1, h * w)
pos_ids = (hm_targets > amplitude / 10) & (vismap == 1)
neg_ids = (hm_targets <= amplitude / 10) & (vismap == 1)
diff = (hm_targets - hm_preds).abs()
pos_loss = (diff * pos_ids.float()).sum(2).sum(0) / (pos_ids.float(
).sum(2).sum(0) + epsilon)
neg_loss = (diff * neg_ids.float()).sum(2).sum(0) / (neg_ids.float(
).sum(2).sum(0) + epsilon)
total_loss = 0.5 * pos_loss + 0.5 * neg_loss
if ohem < 1:
k = int(total_loss.size(0) * ohem)
total_loss, _ = total_loss.topk(k)
return total_loss.mean()
def compute_l2_loss(self, hm_targets, hm_preds, vismap, ohem=1.0):
"""
:param hm_targets: [batch size, keypoint number, h, w]
:param hm_preds: [batch size, keypoint number, h, w]
:param vismap: [batch size, keypoint number]
:return:
"""
epsilon = 0.0001
hm_preds = F.relu(hm_preds, False)
b, k, h, w = hm_targets.size()
hm_targets = hm_targets.view(b, k, -1)
hm_preds = hm_preds.view(b, k, -1)
vismap = vismap.view(b, k, 1).repeat(1, 1, h * w)
ids = vismap == 1
diff = (hm_targets - hm_preds) ** 2
total_loss = (diff * ids.float()).sum(2).sum(0) / (ids.float().sum(
2).sum(0) + epsilon)
if ohem < 1:
k = int(total_loss.size(0) * ohem)
total_loss, _ = total_loss.topk(k)
return total_loss.mean()
def forward(self, input_0, input_1, input_2, input_3):
arg1_1 = input_0
arg0_1 = input_1
arg3_1 = input_2
arg2_1 = input_3
output = call([arg0_1, arg1_1, arg2_1, arg3_1])
return output[0], output[1], output[2]
|
gathierry/FashionAI-KeyPointsDetectionOfApparel
|
VisErrorLossV13
| false
| 15,462
|
[
"Apache-2.0"
] | 174
|
2e0942b42b4a9cd974cdddc151675738dc8a8cb4
|
https://github.com/gathierry/FashionAI-KeyPointsDetectionOfApparel/tree/2e0942b42b4a9cd974cdddc151675738dc8a8cb4
|
DistmultCenterSet
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class DistmultCenterSet(nn.Module):
def __init__(self, dim, aggr=torch.max, nonlinear=True):
super(DistmultCenterSet, self).__init__()
self.dim = dim
self.layers = nn.Parameter(torch.zeros(self.dim * 4 + 4, self.dim))
nn.init.xavier_uniform_(self.layers[:self.dim * 4, :])
self.aggr = aggr
self.nonlinear = nonlinear
def forward(self, embeddings):
w1, w2, w3, w4, b1, b2, b3, b4 = torch.split(self.layers, [self.dim
] * 4 + [1] * 4, dim=0)
x = F.relu(F.linear(embeddings, w1, b1.view(-1)))
x = F.linear(x, w2, b2.view(-1))
if self.nonlinear:
x = F.relu(x)
if self.aggr in [torch.max, torch.min]:
x = self.aggr(x, dim=0)[0]
elif self.aggr in [torch.mean, torch.sum]:
x = self.aggr(x, dim=0)
x = F.relu(F.linear(x, w3, b3.view(-1)))
x = F.linear(x, w4, b4.view(-1))
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'dim': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._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 = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + (64 + 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_max_relu_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)
tmp3 = tl.load(in_ptr0 + (64 + x0), xmask)
tmp6 = tl.load(in_ptr0 + (128 + x0), xmask)
tmp9 = tl.load(in_ptr0 + (192 + x0), xmask)
tmp1 = tl.full([1], 0, tl.int32)
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp4 = triton_helpers.maximum(tmp1, tmp3)
tmp5 = triton_helpers.maximum(tmp2, tmp4)
tmp7 = triton_helpers.maximum(tmp1, tmp6)
tmp8 = triton_helpers.maximum(tmp5, tmp7)
tmp10 = triton_helpers.maximum(tmp1, tmp9)
tmp11 = triton_helpers.maximum(tmp8, tmp10)
tl.store(out_ptr0 + x0, tmp11, xmask)
@triton.jit
def triton_poi_fused_relu_threshold_backward_2(in_out_ptr0, in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + (72 + 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 = args
args.clear()
assert_size_stride(primals_1, (20, 4), (4, 1))
assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0)
buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf0
buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
get_raw_stream(0)
triton_poi_fused_relu_threshold_backward_0[grid(256)](buf1,
primals_1, buf8, 256, XBLOCK=128, num_warps=4, num_stages=1)
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(reinterpret_tensor(primals_1, (4,), (1,), 68),
reinterpret_tensor(buf1, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 4), (1, 4), 16), alpha=1,
beta=1, out=buf2)
buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_max_relu_1[grid(64)](buf2, buf3, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf4 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf3, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 4), (1, 4), 32), out=buf4)
buf5 = reinterpret_tensor(buf4, (4, 4, 4), (16, 4, 1), 0)
del buf4
buf7 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_2[grid(64)](buf5,
primals_1, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf6 = reinterpret_tensor(buf3, (16, 4), (4, 1), 0)
del buf3
extern_kernels.addmm(reinterpret_tensor(primals_1, (4,), (1,), 76),
reinterpret_tensor(buf5, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 4), (1, 4), 48), alpha=1,
beta=1, out=buf6)
return reinterpret_tensor(buf6, (4, 4, 4), (16, 4, 1), 0
), reinterpret_tensor(primals_2, (64, 4), (4, 1), 0
), reinterpret_tensor(buf1, (64, 4), (4, 1), 0
), buf2, reinterpret_tensor(buf5, (16, 4), (4, 1), 0
), reinterpret_tensor(primals_1, (4, 4), (4, 1), 48
), buf7, reinterpret_tensor(primals_1, (4, 4), (4, 1), 32
), reinterpret_tensor(primals_1, (4, 4), (4, 1), 16), buf8
class DistmultCenterSetNew(nn.Module):
def __init__(self, dim, aggr=torch.max, nonlinear=True):
super(DistmultCenterSetNew, self).__init__()
self.dim = dim
self.layers = nn.Parameter(torch.zeros(self.dim * 4 + 4, self.dim))
nn.init.xavier_uniform_(self.layers[:self.dim * 4, :])
self.aggr = aggr
self.nonlinear = nonlinear
def forward(self, input_0):
primals_1 = self.layers
primals_2 = input_0
output = call([primals_1, primals_2])
return output[0]
|
google-research/smore
|
DistmultCenterSet
| false
| 15,463
|
[
"Apache-2.0"
] | 78
|
e4ba95a7466ef7d018987bce7688b77bf2ea7e4f
|
https://github.com/google-research/smore/tree/e4ba95a7466ef7d018987bce7688b77bf2ea7e4f
|
AngleSimpleLinear
|
import torch
import torch.nn.functional as F
import torch.nn as nn
from torch.nn import Parameter
class AngleSimpleLinear(nn.Module):
"""Computes cos of angles between input vectors and weights vectors"""
def __init__(self, in_features, out_features):
super(AngleSimpleLinear, self).__init__()
self.in_features = in_features
self.out_features = out_features
self.weight = Parameter(torch.Tensor(in_features, out_features))
self.weight.data.uniform_(-1, 1).renorm_(2, 1, 1e-05).mul_(100000.0)
def forward(self, x):
cos_theta = F.normalize(x, dim=1).mm(F.normalize(self.weight, dim=0))
return cos_theta.clamp(-1, 1)
def get_inputs():
return [torch.rand([4, 4])]
def get_init_inputs():
return [[], {'in_features': 4, 'out_features': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
from torch.nn import Parameter
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_div_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = 1e-12
tmp14 = triton_helpers.maximum(tmp12, tmp13)
tmp15 = tmp0 / tmp14
tl.store(out_ptr0 + x2, tmp15, xmask)
@triton.jit
def triton_poi_fused_div_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (4 + x0), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (8 + x0), xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr0 + (12 + x0), xmask, eviction_policy='evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = 1e-12
tmp14 = triton_helpers.maximum(tmp12, tmp13)
tmp15 = tmp0 / tmp14
tl.store(out_ptr0 + x2, tmp15, xmask)
@triton.jit
def triton_poi_fused_clamp_ge_le_logical_and_2(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = -1.0
tmp2 = triton_helpers.maximum(tmp0, tmp1)
tmp3 = 1.0
tmp4 = triton_helpers.minimum(tmp2, tmp3)
tmp5 = tmp0 >= tmp1
tmp6 = tmp0 <= tmp3
tmp7 = tmp5 & tmp6
tl.store(out_ptr0 + x0, tmp4, xmask)
tl.store(out_ptr1 + x0, tmp7, xmask)
def call(args):
primals_1, primals_2 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_div_0[grid(16)](primals_1, buf0, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del primals_1
buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused_div_1[grid(16)](primals_2, buf1, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf0, buf1, out=buf2)
buf3 = buf1
del buf1
buf4 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
triton_poi_fused_clamp_ge_le_logical_and_2[grid(16)](buf2, buf3,
buf4, 16, XBLOCK=16, num_warps=1, num_stages=1)
del buf2
return buf3, primals_2, buf4, reinterpret_tensor(buf0, (4, 4), (1, 4), 0)
class AngleSimpleLinearNew(nn.Module):
"""Computes cos of angles between input vectors and weights vectors"""
def __init__(self, in_features, out_features):
super(AngleSimpleLinearNew, self).__init__()
self.in_features = in_features
self.out_features = out_features
self.weight = Parameter(torch.Tensor(in_features, out_features))
self.weight.data.uniform_(-1, 1).renorm_(2, 1, 1e-05).mul_(100000.0)
def forward(self, input_0):
primals_1 = self.weight
primals_2 = input_0
output = call([primals_1, primals_2])
return output[0]
|
grib0ed0v/face_recognition.pytorch
|
AngleSimpleLinear
| false
| 15,464
|
[
"Apache-2.0"
] | 158
|
05cb9b30e8220445fcb27988926d88f330091c12
|
https://github.com/grib0ed0v/face_recognition.pytorch/tree/05cb9b30e8220445fcb27988926d88f330091c12
|
ConvBlock
|
import torch
class ConvBlock(torch.nn.Module):
def __init__(self, input_size, output_size, kernel_size, stride,
padding, bias=True):
super(ConvBlock, self).__init__()
self.conv = torch.nn.Conv2d(input_size, output_size, kernel_size,
stride, padding, bias=bias)
self.act = torch.nn.PReLU()
def forward(self, x):
out = self.conv(x)
return self.act(out)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'input_size': 4, 'output_size': 4, 'kernel_size': 4,
'stride': 1, 'padding': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused__prelu_kernel_convolution_0(in_out_ptr0, in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 1296
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 81 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + 0)
tmp6 = tl.broadcast_to(tmp5, [XBLOCK])
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp7 = tmp6 * tmp2
tmp8 = tl.where(tmp4, tmp2, tmp7)
tl.store(in_out_ptr0 + x3, tmp2, xmask)
tl.store(out_ptr0 + x3, tmp8, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (1,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,
1), padding=(4, 4), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 4, 9, 9), (324, 81, 9, 1))
buf1 = buf0
del buf0
buf2 = empty_strided_cuda((4, 4, 9, 9), (324, 81, 9, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__prelu_kernel_convolution_0[grid(1296)](buf1,
primals_2, primals_4, buf2, 1296, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_2
return buf2, primals_1, primals_3, primals_4, buf1
class ConvBlockNew(torch.nn.Module):
def __init__(self, input_size, output_size, kernel_size, stride,
padding, bias=True):
super(ConvBlockNew, self).__init__()
self.conv = torch.nn.Conv2d(input_size, output_size, kernel_size,
stride, padding, bias=bias)
self.act = torch.nn.PReLU()
def forward(self, input_0):
primals_1 = self.conv.weight
primals_2 = self.conv.bias
primals_4 = self.act.weight
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
grofit/traiNNer
|
ConvBlock
| false
| 15,465
|
[
"Apache-2.0"
] | 78
|
12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
https://github.com/grofit/traiNNer/tree/12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
CenterLoss
|
import torch
import torch.nn.functional as F
import torch.nn as nn
class CenterLoss(nn.Module):
"""Implements the Center loss from https://ydwen.github.io/papers/WenECCV16.pdf"""
def __init__(self, num_classes, embed_size, cos_dist=True):
super().__init__()
self.cos_dist = cos_dist
self.num_classes = num_classes
self.centers = nn.Parameter(torch.randn(self.num_classes, embed_size))
self.embed_size = embed_size
self.mse = nn.MSELoss(reduction='elementwise_mean')
def get_centers(self):
"""Returns estimated centers"""
return self.centers
def forward(self, features, labels):
features = F.normalize(features)
batch_size = labels.size(0)
features_dim = features.size(1)
assert features_dim == self.embed_size
if self.cos_dist:
self.centers.data = F.normalize(self.centers.data, p=2, dim=1)
centers_batch = self.centers[labels, :]
if self.cos_dist:
cos_sim = nn.CosineSimilarity()
cos_diff = 1.0 - cos_sim(features, centers_batch)
center_loss = torch.sum(cos_diff) / batch_size
else:
center_loss = self.mse(centers_batch, features)
return center_loss
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.ones([4], dtype=torch.int64)]
def get_init_inputs():
return [[], {'num_classes': 4, 'embed_size': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_div_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = 1e-12
tmp14 = triton_helpers.maximum(tmp12, tmp13)
tmp15 = tmp0 / tmp14
tl.store(out_ptr0 + x2, tmp15, xmask)
@triton.jit
def triton_poi_fused_div_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 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 = 1e-12
tmp14 = triton_helpers.maximum(tmp12, tmp13)
tmp15 = tmp0 / tmp14
tl.store(out_ptr0 + x3, tmp15, xmask)
@triton.jit
def triton_per_fused_clamp_min_div_linalg_vector_norm_mul_rsub_sum_2(
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)
r2 = rindex // 16
r4 = rindex % 16
r1 = rindex // 4 % 4
r0 = rindex % 4
tmp0 = tl.load(in_ptr0 + (r4 + 64 * r2), None)
tmp2 = tl.load(in_ptr0 + (16 + r4 + 64 * r2), None)
tmp5 = tl.load(in_ptr0 + (32 + r4 + 64 * r2), None)
tmp8 = tl.load(in_ptr0 + (48 + r4 + 64 * r2), None)
tmp15 = tl.load(in_ptr1 + r1, None, 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)
tmp12 = 1e-08
tmp13 = triton_helpers.maximum(tmp11, tmp12)
tmp14 = tmp0 / tmp13
tmp16 = tl.full([XBLOCK, RBLOCK], 4, tl.int32)
tmp17 = tmp15 + tmp16
tmp18 = tmp15 < 0
tmp19 = tl.where(tmp18, tmp17, tmp15)
tl.device_assert((0 <= tmp19) & (tmp19 < 4),
'index out of bounds: 0 <= tmp19 < 4')
tmp21 = tl.load(in_ptr2 + (r0 + 4 * tmp19), None)
tmp22 = tmp21 * tmp21
tmp23 = tmp22 + tmp22
tmp24 = tmp23 + tmp22
tmp25 = tmp24 + tmp22
tmp26 = libdevice.sqrt(tmp25)
tmp27 = triton_helpers.maximum(tmp26, tmp12)
tmp28 = tmp21 / tmp27
tmp29 = tmp14 * tmp28
tmp30 = tmp2 / tmp13
tmp31 = tmp30 * tmp28
tmp32 = tmp29 + tmp31
tmp33 = tmp5 / tmp13
tmp34 = tmp33 * tmp28
tmp35 = tmp32 + tmp34
tmp36 = tmp8 / tmp13
tmp37 = tmp36 * tmp28
tmp38 = tmp35 + tmp37
tmp39 = 1.0
tmp40 = tmp39 - tmp38
tmp41 = tl.broadcast_to(tmp40, [XBLOCK, RBLOCK])
tmp43 = tl.sum(tmp41, 1)[:, None]
tmp44 = 0.25
tmp45 = tmp43 * tmp44
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp45, None)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_div_0[grid(16)](primals_3, buf0, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_div_1[grid(256)](primals_1, buf1, 256, XBLOCK=256,
num_warps=4, num_stages=1)
buf3 = empty_strided_cuda((), (), torch.float32)
buf18 = buf3
del buf3
triton_per_fused_clamp_min_div_linalg_vector_norm_mul_rsub_sum_2[grid
(1)](buf18, buf1, primals_2, buf0, 1, 64, XBLOCK=1, num_warps=2,
num_stages=1)
del buf1
buf4 = torch.ops.aten.set_.source_Tensor(primals_3, buf0)
assert_size_stride(buf4, (4, 4), (4, 1))
del primals_3
return buf18, primals_1, primals_2, buf0
class CenterLossNew(nn.Module):
"""Implements the Center loss from https://ydwen.github.io/papers/WenECCV16.pdf"""
def __init__(self, num_classes, embed_size, cos_dist=True):
super().__init__()
self.cos_dist = cos_dist
self.num_classes = num_classes
self.centers = nn.Parameter(torch.randn(self.num_classes, embed_size))
self.embed_size = embed_size
self.mse = nn.MSELoss(reduction='elementwise_mean')
def get_centers(self):
"""Returns estimated centers"""
return self.centers
def forward(self, input_0, input_1):
primals_3 = self.centers
primals_1 = input_0
primals_2 = input_1
output = call([primals_1, primals_2, primals_3])
return output[0]
|
grib0ed0v/face_recognition.pytorch
|
CenterLoss
| false
| 15,466
|
[
"Apache-2.0"
] | 158
|
05cb9b30e8220445fcb27988926d88f330091c12
|
https://github.com/grib0ed0v/face_recognition.pytorch/tree/05cb9b30e8220445fcb27988926d88f330091c12
|
L1CosineSim
|
import torch
import torch.nn as nn
class L1CosineSim(nn.Module):
""" L1 loss with Cosine similarity.
Can be used to replace L1 pixel loss, but includes a cosine similarity term
to ensure color correctness of the RGB vectors of each pixel.
lambda is a constant factor that adjusts the contribution of the cosine similarity term
It provides improved color stability, especially for low luminance values, which
are frequent in HDR images, since slight variations in any of the RGB components of these
low values do not contribute much totheL1loss, but they may however cause noticeable
color shifts.
Ref: https://arxiv.org/pdf/1803.02266.pdf
https://github.com/dmarnerides/hdr-expandnet/blob/master/train.py
"""
def __init__(self, loss_lambda=5, reduction='mean'):
super(L1CosineSim, self).__init__()
self.similarity = nn.CosineSimilarity(dim=1, eps=1e-20)
self.l1_loss = nn.L1Loss(reduction=reduction)
self.loss_lambda = loss_lambda
def forward(self, x: 'torch.Tensor', y: 'torch.Tensor') ->torch.Tensor:
cosine_term = (1 - self.similarity(x, y)).mean()
return self.l1_loss(x, y) + self.loss_lambda * cosine_term
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_abs_clamp_min_div_linalg_vector_norm_mean_mul_sub_0(
in_ptr0, in_ptr1, out_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
r1 = rindex % 16
r3 = rindex // 64
tmp0 = tl.load(in_ptr0 + r0, None)
tmp1 = tl.load(in_ptr1 + r0, None)
tmp7 = tl.load(in_ptr0 + (r1 + 64 * r3), None, eviction_policy='evict_last'
)
tmp9 = tl.load(in_ptr0 + (16 + r1 + 64 * r3), None, eviction_policy=
'evict_last')
tmp12 = tl.load(in_ptr0 + (32 + r1 + 64 * r3), None, eviction_policy=
'evict_last')
tmp15 = tl.load(in_ptr0 + (48 + r1 + 64 * r3), None, eviction_policy=
'evict_last')
tmp22 = tl.load(in_ptr1 + (r1 + 64 * r3), None, eviction_policy=
'evict_last')
tmp24 = tl.load(in_ptr1 + (16 + r1 + 64 * r3), None, eviction_policy=
'evict_last')
tmp27 = tl.load(in_ptr1 + (32 + r1 + 64 * r3), None, eviction_policy=
'evict_last')
tmp30 = tl.load(in_ptr1 + (48 + r1 + 64 * r3), None, eviction_policy=
'evict_last')
tmp2 = tmp0 - tmp1
tmp3 = tl_math.abs(tmp2)
tmp4 = tl.broadcast_to(tmp3, [RBLOCK])
tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0))
tmp8 = tmp7 * tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp13 = tmp12 * tmp12
tmp14 = tmp11 + tmp13
tmp16 = tmp15 * tmp15
tmp17 = tmp14 + tmp16
tmp18 = libdevice.sqrt(tmp17)
tmp19 = 1e-20
tmp20 = triton_helpers.maximum(tmp18, tmp19)
tmp21 = tmp0 / tmp20
tmp23 = tmp22 * tmp22
tmp25 = tmp24 * tmp24
tmp26 = tmp23 + tmp25
tmp28 = tmp27 * tmp27
tmp29 = tmp26 + tmp28
tmp31 = tmp30 * tmp30
tmp32 = tmp29 + tmp31
tmp33 = libdevice.sqrt(tmp32)
tmp34 = triton_helpers.maximum(tmp33, tmp19)
tmp35 = tmp1 / tmp34
tmp36 = tmp21 * tmp35
tl.store(out_ptr1 + tl.broadcast_to(r0, [RBLOCK]), tmp36, None)
tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp6, None)
@triton.jit
def triton_per_fused_abs_add_mean_mul_rsub_sub_sum_1(in_out_ptr0, in_ptr0,
xnumel, rnumel, XBLOCK: tl.constexpr):
RBLOCK: tl.constexpr = 64
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r0 = rindex % 16
r1 = rindex // 16
tmp0 = tl.load(in_ptr0 + (r0 + 64 * r1), None)
tmp1 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None)
tmp3 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None)
tmp5 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None)
tmp12 = tl.load(in_out_ptr0 + 0)
tmp13 = tl.broadcast_to(tmp12, [XBLOCK, 1])
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp7 = 1.0
tmp8 = tmp7 - tmp6
tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK])
tmp11 = tl.sum(tmp9, 1)[:, None]
tmp14 = 256.0
tmp15 = tmp13 / tmp14
tmp16 = 64.0
tmp17 = tmp11 / tmp16
tmp18 = 5.0
tmp19 = tmp17 * tmp18
tmp20 = tmp15 + tmp19
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp20, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((), (), torch.float32)
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_per_fused_abs_clamp_min_div_linalg_vector_norm_mean_mul_sub_0[
grid(1)](arg1_1, arg0_1, buf0, buf1, 1, 256, num_warps=2,
num_stages=1)
del arg0_1
del arg1_1
buf3 = buf0
del buf0
triton_per_fused_abs_add_mean_mul_rsub_sub_sum_1[grid(1)](buf3,
buf1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1)
del buf1
return buf3,
class L1CosineSimNew(nn.Module):
""" L1 loss with Cosine similarity.
Can be used to replace L1 pixel loss, but includes a cosine similarity term
to ensure color correctness of the RGB vectors of each pixel.
lambda is a constant factor that adjusts the contribution of the cosine similarity term
It provides improved color stability, especially for low luminance values, which
are frequent in HDR images, since slight variations in any of the RGB components of these
low values do not contribute much totheL1loss, but they may however cause noticeable
color shifts.
Ref: https://arxiv.org/pdf/1803.02266.pdf
https://github.com/dmarnerides/hdr-expandnet/blob/master/train.py
"""
def __init__(self, loss_lambda=5, reduction='mean'):
super(L1CosineSimNew, self).__init__()
self.similarity = nn.CosineSimilarity(dim=1, eps=1e-20)
self.l1_loss = nn.L1Loss(reduction=reduction)
self.loss_lambda = loss_lambda
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
grofit/traiNNer
|
L1CosineSim
| false
| 15,467
|
[
"Apache-2.0"
] | 78
|
12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
https://github.com/grofit/traiNNer/tree/12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
PA
|
import torch
import torch.nn as nn
class PA(nn.Module):
"""PA is pixel attention"""
def __init__(self, nf):
super(PA, self).__init__()
self.conv = nn.Conv2d(nf, nf, 1)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
y = self.conv(x)
y = self.sigmoid(y)
out = torch.mul(x, y)
return out
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'nf': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_convolution_mul_sigmoid_0(in_out_ptr0, in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x3, xmask)
tmp2 = tmp0 + tmp1
tmp4 = tl.sigmoid(tmp2)
tmp5 = tmp3 * tmp4
tl.store(in_out_ptr0 + x3, tmp2, xmask)
tl.store(out_ptr0 + x3, tmp5, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1))
buf1 = buf0
del buf0
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_convolution_mul_sigmoid_0[grid(256)](buf1,
primals_2, primals_3, buf2, 256, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_2
return buf2, primals_1, primals_3, buf1
class PANew(nn.Module):
"""PA is pixel attention"""
def __init__(self, nf):
super(PANew, self).__init__()
self.conv = nn.Conv2d(nf, nf, 1)
self.sigmoid = nn.Sigmoid()
def forward(self, input_0):
primals_1 = self.conv.weight
primals_2 = self.conv.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
grofit/traiNNer
|
PA
| false
| 15,468
|
[
"Apache-2.0"
] | 78
|
12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
https://github.com/grofit/traiNNer/tree/12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
PACnv
|
import torch
import torch.nn as nn
class PACnv(nn.Module):
def __init__(self, nf, k_size=3):
super(PACnv, self).__init__()
self.k2 = nn.Conv2d(nf, nf, 1)
self.sigmoid = nn.Sigmoid()
self.k3 = nn.Conv2d(nf, nf, kernel_size=k_size, padding=(k_size - 1
) // 2, bias=False)
self.k4 = nn.Conv2d(nf, nf, kernel_size=k_size, padding=(k_size - 1
) // 2, bias=False)
def forward(self, x):
y = self.k2(x)
y = self.sigmoid(y)
out = torch.mul(self.k3(x), y)
out = self.k4(out)
return out
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'nf': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_convolution_mul_sigmoid_0(in_out_ptr0, in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x3, xmask)
tmp2 = tmp0 + tmp1
tmp4 = tl.sigmoid(tmp2)
tmp5 = tmp3 * tmp4
tl.store(in_out_ptr0 + x3, tmp2, xmask)
tl.store(out_ptr0 + x3, tmp5, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_5, (4, 4, 3, 3), (36, 9, 3, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1))
buf2 = extern_kernels.convolution(primals_3, primals_4, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 4, 4, 4), (64, 16, 4, 1))
buf1 = buf0
del buf0
buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_convolution_mul_sigmoid_0[grid(256)](buf1,
primals_2, buf2, buf3, 256, XBLOCK=256, num_warps=4, num_stages=1)
del primals_2
buf4 = extern_kernels.convolution(buf3, primals_5, 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))
return buf4, primals_1, primals_3, primals_4, primals_5, buf1, buf2, buf3
class PACnvNew(nn.Module):
def __init__(self, nf, k_size=3):
super(PACnvNew, self).__init__()
self.k2 = nn.Conv2d(nf, nf, 1)
self.sigmoid = nn.Sigmoid()
self.k3 = nn.Conv2d(nf, nf, kernel_size=k_size, padding=(k_size - 1
) // 2, bias=False)
self.k4 = nn.Conv2d(nf, nf, kernel_size=k_size, padding=(k_size - 1
) // 2, bias=False)
def forward(self, input_0):
primals_1 = self.k2.weight
primals_2 = self.k2.bias
primals_4 = self.k3.weight
primals_5 = self.k4.weight
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
grofit/traiNNer
|
PACnv
| false
| 15,469
|
[
"Apache-2.0"
] | 78
|
12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
https://github.com/grofit/traiNNer/tree/12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
FrobeniusNormLoss
|
import torch
import torch.nn as nn
def get_outnorm(x: 'torch.Tensor', out_norm: 'str'='') ->torch.Tensor:
""" Common function to get a loss normalization value. Can
normalize by either the batch size ('b'), the number of
channels ('c'), the image size ('i') or combinations
('bi', 'bci', etc)
"""
img_shape = x.shape
if not out_norm:
return 1
norm = 1
if 'b' in out_norm:
norm /= img_shape[0]
if 'c' in out_norm:
norm /= img_shape[-3]
if 'i' in out_norm:
norm /= img_shape[-1] * img_shape[-2]
return norm
class FrobeniusNormLoss(nn.Module):
def __init__(self, order='fro', out_norm: 'str'='c', kind: 'str'='vec'):
super().__init__()
self.order = order
self.out_norm = out_norm
self.kind = kind
def forward(self, x: 'torch.Tensor', y: 'torch.Tensor') ->torch.Tensor:
norm = get_outnorm(x, self.out_norm)
if self.kind == 'mat':
loss = torch.linalg.matrix_norm(x - y, ord=self.order).mean()
else:
loss = torch.linalg.norm(x.view(-1, 1) - y.view(-1, 1), ord=
self.order)
return loss * norm
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
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_mul_sub_0(in_out_ptr0, in_ptr0,
in_ptr1, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp1 = tl.load(in_ptr1 + r0, None)
tmp2 = tmp0 - tmp1
tmp3 = tmp2 * tmp2
tmp4 = tl.broadcast_to(tmp3, [RBLOCK])
tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0))
tmp7 = libdevice.sqrt(tmp6)
tmp8 = 0.25
tmp9 = tmp7 * tmp8
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp9, None)
def call(args):
arg0_1, arg1_1 = 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_linalg_vector_norm_mul_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,
def get_outnorm(x: 'torch.Tensor', out_norm: 'str'='') ->torch.Tensor:
""" Common function to get a loss normalization value. Can
normalize by either the batch size ('b'), the number of
channels ('c'), the image size ('i') or combinations
('bi', 'bci', etc)
"""
img_shape = x.shape
if not out_norm:
return 1
norm = 1
if 'b' in out_norm:
norm /= img_shape[0]
if 'c' in out_norm:
norm /= img_shape[-3]
if 'i' in out_norm:
norm /= img_shape[-1] * img_shape[-2]
return norm
class FrobeniusNormLossNew(nn.Module):
def __init__(self, order='fro', out_norm: 'str'='c', kind: 'str'='vec'):
super().__init__()
self.order = order
self.out_norm = out_norm
self.kind = kind
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
grofit/traiNNer
|
FrobeniusNormLoss
| false
| 15,470
|
[
"Apache-2.0"
] | 78
|
12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
https://github.com/grofit/traiNNer/tree/12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
PAM_Module
|
from torch.nn import Module
import torch
from math import sqrt as sqrt
from itertools import product as product
from torch.nn import Conv2d
from torch.nn import Parameter
from torch.nn import Softmax
from torch.nn.modules.module import Module
class PAM_Module(Module):
""" Position attention module"""
def __init__(self, in_dim):
super(PAM_Module, self).__init__()
self.chanel_in = in_dim
self.query_conv = Conv2d(in_channels=in_dim, out_channels=in_dim //
4, kernel_size=1)
self.key_conv = Conv2d(in_channels=in_dim, out_channels=in_dim // 4,
kernel_size=1)
self.value_conv = Conv2d(in_channels=in_dim, out_channels=in_dim,
kernel_size=1)
self.gamma = Parameter(torch.zeros(1))
self.softmax = Softmax(dim=-1)
def forward(self, x):
"""
inputs :
x : input feature maps( B X C X H X W)
returns :
out : attention value + input feature
attention: B X (HxW) X (HxW)
"""
m_batchsize, C, height, width = x.size()
proj_query = self.query_conv(x).view(m_batchsize, -1, width * height
).permute(0, 2, 1)
proj_key = self.key_conv(x).view(m_batchsize, -1, width * height)
energy = torch.bmm(proj_query, proj_key)
attention = self.softmax(energy)
proj_value = self.value_conv(x).view(m_batchsize, -1, width * height)
out = torch.bmm(proj_value, attention.permute(0, 2, 1))
out = out.view(m_batchsize, C, height, width)
out = self.gamma * out + x
return out
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_dim': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
from torch.nn import Module
from math import sqrt as sqrt
from itertools import product as product
from torch.nn import Conv2d
from torch.nn import Parameter
from torch.nn import Softmax
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_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + 0)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
tmp3 = tmp0 + tmp2
tl.store(in_out_ptr0 + x0, tmp3, xmask)
@triton.jit
def triton_per_fused__softmax_1(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK:
tl.constexpr):
xnumel = 64
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
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, float('-inf'))
tmp4 = triton_helpers.max2(tmp3, 1)[:, None]
tmp5 = tmp0 - tmp4
tmp6 = tl_math.exp(tmp5)
tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
tmp9 = tl.where(xmask, tmp7, 0)
tmp10 = tl.sum(tmp9, 1)[:, None]
tmp11 = tmp6 / tmp10
tl.store(out_ptr2 + (r1 + 16 * x0), tmp11, xmask)
@triton.jit
def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, xmask)
@triton.jit
def triton_poi_fused_add_mul_3(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
tmp2 = tl.load(in_ptr1 + x0, xmask)
tmp4 = tl.load(in_ptr2 + x0, xmask)
tmp3 = tmp1 * tmp2
tmp5 = tmp3 + tmp4
tl.store(out_ptr0 + x0, tmp5, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (1, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_3, (1,), (1,))
assert_size_stride(primals_4, (1, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_5, (1,), (1,))
assert_size_stride(primals_6, (4, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_7, (4,), (1,))
assert_size_stride(primals_8, (1,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 1, 4, 4), (16, 16, 4, 1))
buf1 = extern_kernels.convolution(primals_1, primals_4, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf1, (4, 1, 4, 4), (16, 16, 4, 1))
buf2 = reinterpret_tensor(buf0, (4, 1, 4, 4), (16, 1, 4, 1), 0)
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(64)](buf2, primals_3, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del primals_3
buf3 = reinterpret_tensor(buf1, (4, 1, 4, 4), (16, 1, 4, 1), 0)
del buf1
triton_poi_fused_convolution_0[grid(64)](buf3, primals_5, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del primals_5
buf4 = empty_strided_cuda((4, 16, 16), (256, 16, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf2, (4, 16, 1), (16, 1, 0),
0), reinterpret_tensor(buf3, (4, 1, 16), (16, 0, 1), 0), out=buf4)
buf7 = empty_strided_cuda((4, 16, 16), (256, 16, 1), torch.float32)
triton_per_fused__softmax_1[grid(64)](buf4, buf7, 64, 16, XBLOCK=1,
num_warps=2, num_stages=1)
del buf4
buf8 = extern_kernels.convolution(primals_1, primals_6, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf8, (4, 4, 4, 4), (64, 16, 4, 1))
buf9 = buf8
del buf8
triton_poi_fused_convolution_2[grid(256)](buf9, primals_7, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_7
buf10 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf9, (4, 4, 16), (64, 16, 1),
0), reinterpret_tensor(buf7, (4, 16, 16), (256, 1, 16), 0), out
=buf10)
buf11 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_add_mul_3[grid(256)](primals_8, buf10, primals_1,
buf11, 256, XBLOCK=128, num_warps=4, num_stages=1)
return (buf11, primals_1, primals_2, primals_4, primals_6, primals_8,
buf7, buf10, reinterpret_tensor(buf9, (4, 16, 4), (64, 1, 16), 0),
reinterpret_tensor(buf2, (4, 1, 16), (16, 16, 1), 0),
reinterpret_tensor(buf3, (4, 16, 1), (16, 1, 16), 0))
class PAM_ModuleNew(Module):
""" Position attention module"""
def __init__(self, in_dim):
super(PAM_ModuleNew, self).__init__()
self.chanel_in = in_dim
self.query_conv = Conv2d(in_channels=in_dim, out_channels=in_dim //
4, kernel_size=1)
self.key_conv = Conv2d(in_channels=in_dim, out_channels=in_dim // 4,
kernel_size=1)
self.value_conv = Conv2d(in_channels=in_dim, out_channels=in_dim,
kernel_size=1)
self.gamma = Parameter(torch.zeros(1))
self.softmax = Softmax(dim=-1)
def forward(self, input_0):
primals_3 = self.gamma
primals_2 = self.query_conv.weight
primals_5 = self.query_conv.bias
primals_4 = self.key_conv.weight
primals_8 = self.key_conv.bias
primals_6 = self.value_conv.weight
primals_7 = self.value_conv.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8])
return output[0]
|
gpdsec/HSD
|
PAM_Module
| false
| 15,471
|
[
"MIT"
] | 58
|
8abcf78db5f313266a3bb3f85b9424927fe59a2d
|
https://github.com/gpdsec/HSD/tree/8abcf78db5f313266a3bb3f85b9424927fe59a2d
|
OFLoss
|
import torch
import torch.nn as nn
def get_outnorm(x: 'torch.Tensor', out_norm: 'str'='') ->torch.Tensor:
""" Common function to get a loss normalization value. Can
normalize by either the batch size ('b'), the number of
channels ('c'), the image size ('i') or combinations
('bi', 'bci', etc)
"""
img_shape = x.shape
if not out_norm:
return 1
norm = 1
if 'b' in out_norm:
norm /= img_shape[0]
if 'c' in out_norm:
norm /= img_shape[-3]
if 'i' in out_norm:
norm /= img_shape[-1] * img_shape[-2]
return norm
class OFLoss(nn.Module):
""" Overflow loss (similar to Range limiting loss, needs tests)
Penalizes for pixel values that exceed the valid range (default [0,1]).
Note: This solves part of the SPL brightness problem and can be useful
in other cases as well)
"""
def __init__(self, legit_range=None, out_norm: 'str'='bci'):
super(OFLoss, self).__init__()
if legit_range is None:
legit_range = [0, 1]
self.legit_range = legit_range
self.out_norm = out_norm
def forward(self, x):
norm = get_outnorm(x, self.out_norm)
img_clamp = x.clamp(self.legit_range[0], self.legit_range[1])
return torch.log((x - img_clamp).abs() + 1).sum() * norm
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_abs_add_clamp_log_mul_sub_sum_0(in_out_ptr0, in_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 = 0.0
tmp2 = triton_helpers.maximum(tmp0, tmp1)
tmp3 = 1.0
tmp4 = triton_helpers.minimum(tmp2, tmp3)
tmp5 = tmp0 - tmp4
tmp6 = tl_math.abs(tmp5)
tmp7 = tmp6 + tmp3
tmp8 = tl_math.log(tmp7)
tmp9 = tl.broadcast_to(tmp8, [RBLOCK])
tmp11 = triton_helpers.promote_to_tensor(tl.sum(tmp9, 0))
tmp12 = 0.00390625
tmp13 = tmp11 * tmp12
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp13, None)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((), (), torch.float32)
buf1 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_abs_add_clamp_log_mul_sub_sum_0[grid(1)](buf1,
arg0_1, 1, 256, num_warps=2, num_stages=1)
del arg0_1
return buf1,
def get_outnorm(x: 'torch.Tensor', out_norm: 'str'='') ->torch.Tensor:
""" Common function to get a loss normalization value. Can
normalize by either the batch size ('b'), the number of
channels ('c'), the image size ('i') or combinations
('bi', 'bci', etc)
"""
img_shape = x.shape
if not out_norm:
return 1
norm = 1
if 'b' in out_norm:
norm /= img_shape[0]
if 'c' in out_norm:
norm /= img_shape[-3]
if 'i' in out_norm:
norm /= img_shape[-1] * img_shape[-2]
return norm
class OFLossNew(nn.Module):
""" Overflow loss (similar to Range limiting loss, needs tests)
Penalizes for pixel values that exceed the valid range (default [0,1]).
Note: This solves part of the SPL brightness problem and can be useful
in other cases as well)
"""
def __init__(self, legit_range=None, out_norm: 'str'='bci'):
super(OFLossNew, self).__init__()
if legit_range is None:
legit_range = [0, 1]
self.legit_range = legit_range
self.out_norm = out_norm
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
grofit/traiNNer
|
OFLoss
| false
| 15,472
|
[
"Apache-2.0"
] | 78
|
12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
https://github.com/grofit/traiNNer/tree/12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
Deconvolution
|
import torch
import torch.nn as nn
import torch.utils.model_zoo
class Deconvolution(nn.Module):
def __init__(self, C, stride):
super(Deconvolution, self).__init__()
if stride == 2:
kernel_size = 3
output_padding = 1
elif stride == 4:
kernel_size = 5
output_padding = 1
else:
kernel_size = 3
output_padding = 0
self.deconv = nn.ConvTranspose2d(C, C, kernel_size=kernel_size,
stride=stride, padding=1, output_padding=output_padding)
def forward(self, x):
return self.deconv(x)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'C': 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
import torch.utils.model_zoo
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 = 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=True,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(256)](buf1, primals_2, 256,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_2
return buf1, primals_1, primals_3
class DeconvolutionNew(nn.Module):
def __init__(self, C, stride):
super(DeconvolutionNew, self).__init__()
if stride == 2:
kernel_size = 3
output_padding = 1
elif stride == 4:
kernel_size = 5
output_padding = 1
else:
kernel_size = 3
output_padding = 0
self.deconv = nn.ConvTranspose2d(C, C, kernel_size=kernel_size,
stride=stride, padding=1, output_padding=output_padding)
def forward(self, input_0):
primals_1 = self.deconv.weight
primals_2 = self.deconv.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
guoyongcs/HNAS
|
Deconvolution
| false
| 15,473
|
[
"MIT"
] | 60
|
2b34e1b637bb03d23ca6559c1b5d1245d9744348
|
https://github.com/guoyongcs/HNAS/tree/2b34e1b637bb03d23ca6559c1b5d1245d9744348
|
RelativeL1
|
import torch
import torch.nn as nn
class RelativeL1(nn.Module):
""" Relative L1 loss.
Comparing to the regular L1, introducing the division by |c|+epsilon
better models the human vision system’s sensitivity to variations
in the dark areas. (where epsilon = 0.01, to prevent values of 0 in the
denominator)
"""
def __init__(self, eps=0.01, reduction='mean'):
super().__init__()
self.criterion = nn.L1Loss(reduction=reduction)
self.eps = eps
def forward(self, x: 'torch.Tensor', y: 'torch.Tensor') ->torch.Tensor:
base = y + self.eps
return self.criterion(x / base, y / base)
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_abs_add_div_mean_sub_0(in_out_ptr0, in_ptr0, in_ptr1,
xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp1 = tl.load(in_ptr1 + r0, None)
tmp2 = 0.01
tmp3 = tmp1 + tmp2
tmp4 = tmp0 / tmp3
tmp5 = tmp1 / tmp3
tmp6 = tmp4 - tmp5
tmp7 = tl_math.abs(tmp6)
tmp8 = tl.broadcast_to(tmp7, [RBLOCK])
tmp10 = triton_helpers.promote_to_tensor(tl.sum(tmp8, 0))
tmp11 = 256.0
tmp12 = tmp10 / tmp11
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp12, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((), (), torch.float32)
buf1 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_abs_add_div_mean_sub_0[grid(1)](buf1, arg1_1,
arg0_1, 1, 256, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
return buf1,
class RelativeL1New(nn.Module):
""" Relative L1 loss.
Comparing to the regular L1, introducing the division by |c|+epsilon
better models the human vision system’s sensitivity to variations
in the dark areas. (where epsilon = 0.01, to prevent values of 0 in the
denominator)
"""
def __init__(self, eps=0.01, reduction='mean'):
super().__init__()
self.criterion = nn.L1Loss(reduction=reduction)
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]
|
grofit/traiNNer
|
RelativeL1
| false
| 15,474
|
[
"Apache-2.0"
] | 78
|
12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
https://github.com/grofit/traiNNer/tree/12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
ConvUpSample
|
import torch
import torch.nn as nn
class ConvUpSample(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size=1, stride=1,
padding=0, scale_factor=2, mode='nearest'):
super(ConvUpSample, self).__init__()
self.upsample = nn.Upsample(scale_factor=scale_factor, mode=mode)
self.conv = nn.Conv2d(in_channels, out_channels, kernel_size=
kernel_size, stride=stride, padding=padding)
def forward(self, x):
return self.conv(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 nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused__unsafe_index_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 8 % 8
x0 = xindex % 8
x2 = xindex // 64
x4 = xindex
tmp0 = x1
tmp1 = tmp0.to(tl.float32)
tmp2 = 0.5
tmp3 = tmp1 * tmp2
tmp4 = tmp3.to(tl.int32)
tmp5 = x0
tmp6 = tmp5.to(tl.float32)
tmp7 = tmp6 * tmp2
tmp8 = tmp7.to(tl.int32)
tmp9 = tl.load(in_ptr0 + (tmp8 + 4 * tmp4 + 16 * x2), xmask,
eviction_policy='evict_last')
tl.store(out_ptr0 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 64 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4, 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)
get_raw_stream(0)
triton_poi_fused__unsafe_index_0[grid(1024)](primals_1, buf0, 1024,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_1
buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf1, (4, 4, 8, 8), (256, 64, 8, 1))
buf2 = buf1
del buf1
triton_poi_fused_convolution_1[grid(1024)](buf2, primals_3, 1024,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_3
return buf2, primals_2, buf0
class ConvUpSampleNew(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size=1, stride=1,
padding=0, scale_factor=2, mode='nearest'):
super(ConvUpSampleNew, self).__init__()
self.upsample = nn.Upsample(scale_factor=scale_factor, mode=mode)
self.conv = nn.Conv2d(in_channels, out_channels, kernel_size=
kernel_size, stride=stride, padding=padding)
def forward(self, input_0):
primals_2 = self.conv.weight
primals_3 = self.conv.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
hadonga/PMF_MOD
|
ConvUpSample
| false
| 15,475
|
[
"MIT"
] | 65
|
1875be9bd019a7e8a121d92831fa3cbd557e2ca1
|
https://github.com/hadonga/PMF_MOD/tree/1875be9bd019a7e8a121d92831fa3cbd557e2ca1
|
TestUpsampleNearest2d
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class TestUpsampleNearest2d(nn.Module):
"""Module for UpsampleNearest2d conversion testing
"""
def __init__(self, inp=10, out=16, kernel_size=3, bias=True):
super(TestUpsampleNearest2d, self).__init__()
self.conv2d = nn.Conv2d(inp, out, kernel_size=kernel_size, bias=bias)
self.up = nn.UpsamplingNearest2d(scale_factor=2)
def forward(self, x):
x = self.conv2d(x)
x = F.upsample(x, scale_factor=2)
x = self.up(x)
return x
def get_inputs():
return [torch.rand([4, 10, 64, 64])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused__to_copy_add_arange_mul_0(out_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 124
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__to_copy_add_arange_mul_1(out_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 248
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_2(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x1 = xindex // 248 % 248
x0 = xindex % 248
x5 = xindex // 61504
x2 = xindex // 61504 % 16
x6 = xindex
tmp0 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
tmp19 = tl.load(in_ptr3 + x2, None, eviction_policy='evict_last')
tmp1 = tl.full([XBLOCK], 124, 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 + tmp4, None, eviction_policy='evict_last')
tmp10 = tl.full([XBLOCK], 62, tl.int32)
tmp11 = tmp9 + tmp10
tmp12 = tmp9 < 0
tmp13 = tl.where(tmp12, tmp11, tmp9)
tmp14 = tl.load(in_ptr1 + tmp8, None, eviction_policy='evict_last')
tmp15 = tmp14 + tmp10
tmp16 = tmp14 < 0
tmp17 = tl.where(tmp16, tmp15, tmp14)
tmp18 = tl.load(in_ptr2 + (tmp17 + 62 * tmp13 + 3844 * x5), None,
eviction_policy='evict_last')
tmp20 = tmp18 + tmp19
tl.store(out_ptr0 + x6, tmp20, None)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (16, 10, 3, 3), (90, 9, 3, 1))
assert_size_stride(primals_2, (16,), (1,))
assert_size_stride(primals_3, (4, 10, 64, 64), (40960, 4096, 64, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 16, 62, 62), (61504, 3844, 62, 1))
buf1 = empty_strided_cuda((124,), (1,), torch.int64)
get_raw_stream(0)
triton_poi_fused__to_copy_add_arange_mul_0[grid(124)](buf1, 124,
XBLOCK=128, num_warps=4, num_stages=1)
buf2 = empty_strided_cuda((248,), (1,), torch.int64)
triton_poi_fused__to_copy_add_arange_mul_1[grid(248)](buf2, 248,
XBLOCK=128, num_warps=4, num_stages=1)
buf3 = empty_strided_cuda((4, 16, 248, 248), (984064, 61504, 248, 1
), torch.float32)
triton_poi_fused__unsafe_index_convolution_2[grid(3936256)](buf2,
buf1, buf0, primals_2, buf3, 3936256, XBLOCK=1024, num_warps=4,
num_stages=1)
del buf0
del primals_2
return buf3, primals_1, primals_3, buf1, buf2
class TestUpsampleNearest2dNew(nn.Module):
"""Module for UpsampleNearest2d conversion testing
"""
def __init__(self, inp=10, out=16, kernel_size=3, bias=True):
super(TestUpsampleNearest2dNew, self).__init__()
self.conv2d = nn.Conv2d(inp, out, kernel_size=kernel_size, bias=bias)
self.up = nn.UpsamplingNearest2d(scale_factor=2)
def forward(self, input_0):
primals_1 = self.conv2d.weight
primals_2 = self.conv2d.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
gqgs/pytorch2keras
|
TestUpsampleNearest2d
| false
| 15,476
|
[
"MIT"
] | 733
|
9cd26e9e6698e1f07e455dbb94c15ecff53fb788
|
https://github.com/gqgs/pytorch2keras/tree/9cd26e9e6698e1f07e455dbb94c15ecff53fb788
|
Swish
|
import torch
import torch.nn as nn
def swish_func(x, beta=1.0, inplace=False):
"""
"Swish: a Self-Gated Activation Function"
Searching for Activation Functions (https://arxiv.org/abs/1710.05941)
If beta=1 applies the Sigmoid Linear Unit (SiLU) function element-wise
If beta=0, Swish becomes the scaled linear function (identity
activation) f(x) = x/2
As beta -> ∞, the sigmoid component converges to approach a 0-1 function
(unit step), and multiplying that by x gives us f(x)=2max(0,x), which
is the ReLU multiplied by a constant factor of 2, so Swish becomes like
the ReLU function.
Including beta, Swish can be loosely viewed as a smooth function that
nonlinearly interpolate between identity (linear) and ReLU function.
The degree of interpolation can be controlled by the model if beta is
set as a trainable parameter.
Alt: 1.78718727865 * (x * sigmoid(x) - 0.20662096414)
"""
if inplace:
result = x.clone()
torch.sigmoid_(beta * x)
x *= result
return x
return x * torch.sigmoid(beta * x)
class Swish(nn.Module):
__constants__ = ['beta', 'slope', 'inplace']
def __init__(self, beta=1.0, slope=1.67653251702, inplace=False):
"""
Shape:
- Input: (N, *) where * means, any number of additional
dimensions
- Output: (N, *), same shape as the input
"""
super(Swish, self).__init__()
self.inplace = inplace
self.beta = torch.nn.Parameter(torch.tensor(beta))
self.beta.requiresGrad = True
self.slope = slope / 2
def forward(self, x):
"""
# Disabled, using inplace causes:
# "RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation"
if self.inplace:
input.mul_(torch.sigmoid(self.beta*input))
return 2 * self.slope * input
else:
return 2 * self.slope * swish_func(input, self.beta)
"""
return 2 * self.slope * swish_func(x, self.beta, self.inplace)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_mul_sigmoid_0(in_ptr0, in_ptr1, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr1 + 0)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
tmp3 = tmp2 * tmp0
tmp4 = tl.sigmoid(tmp3)
tmp5 = tmp0 * tmp4
tmp6 = 1.67653251702
tmp7 = tmp5 * tmp6
tl.store(out_ptr0 + x0, tmp7, xmask)
def call(args):
primals_1, primals_2 = args
args.clear()
assert_size_stride(primals_1, (), ())
assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_mul_sigmoid_0[grid(256)](primals_2, primals_1,
buf0, 256, XBLOCK=128, num_warps=4, num_stages=1)
return buf0, primals_1, primals_2
def swish_func(x, beta=1.0, inplace=False):
"""
"Swish: a Self-Gated Activation Function"
Searching for Activation Functions (https://arxiv.org/abs/1710.05941)
If beta=1 applies the Sigmoid Linear Unit (SiLU) function element-wise
If beta=0, Swish becomes the scaled linear function (identity
activation) f(x) = x/2
As beta -> ∞, the sigmoid component converges to approach a 0-1 function
(unit step), and multiplying that by x gives us f(x)=2max(0,x), which
is the ReLU multiplied by a constant factor of 2, so Swish becomes like
the ReLU function.
Including beta, Swish can be loosely viewed as a smooth function that
nonlinearly interpolate between identity (linear) and ReLU function.
The degree of interpolation can be controlled by the model if beta is
set as a trainable parameter.
Alt: 1.78718727865 * (x * sigmoid(x) - 0.20662096414)
"""
if inplace:
result = x.clone()
torch.sigmoid_(beta * x)
x *= result
return x
return x * torch.sigmoid(beta * x)
class SwishNew(nn.Module):
__constants__ = ['beta', 'slope', 'inplace']
def __init__(self, beta=1.0, slope=1.67653251702, inplace=False):
"""
Shape:
- Input: (N, *) where * means, any number of additional
dimensions
- Output: (N, *), same shape as the input
"""
super(SwishNew, self).__init__()
self.inplace = inplace
self.beta = torch.nn.Parameter(torch.tensor(beta))
self.beta.requiresGrad = True
self.slope = slope / 2
def forward(self, input_0):
primals_1 = self.beta
primals_2 = input_0
output = call([primals_1, primals_2])
return output[0]
|
grofit/traiNNer
|
Swish
| false
| 15,477
|
[
"Apache-2.0"
] | 78
|
12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
https://github.com/grofit/traiNNer/tree/12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
Linear
|
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.model_zoo
class Linear(nn.Module):
def __init__(self, stride):
super(Linear, self).__init__()
self.scale = stride
def forward(self, x):
return F.interpolate(x, scale_factor=self.scale, mode='linear')
def get_inputs():
return [torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'stride': 1}]
|
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.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__to_copy__unsafe_index_add_arange_clamp_mul_sub_0(in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4
x2 = xindex
tmp0 = x0
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.load(in_ptr0 + (tmp9 + 4 * x1), xmask, eviction_policy=
'evict_last')
tmp11 = tl.full([1], 1, tl.int64)
tmp12 = tmp9 + tmp11
tmp13 = tl.full([1], 3, tl.int64)
tmp14 = triton_helpers.minimum(tmp12, tmp13)
tmp15 = tl.load(in_ptr0 + (tmp14 + 4 * x1), xmask, eviction_policy=
'evict_last')
tmp16 = tmp15 - tmp10
tmp17 = tmp9.to(tl.float32)
tmp18 = tmp8 - tmp17
tmp19 = triton_helpers.maximum(tmp18, tmp7)
tmp20 = triton_helpers.minimum(tmp19, tmp4)
tmp21 = tmp16 * tmp20
tmp22 = tmp10 + tmp21
tl.store(out_ptr0 + x2, tmp22, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0[grid
(64)](arg0_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1)
del arg0_1
return buf0,
class LinearNew(nn.Module):
def __init__(self, stride):
super(LinearNew, self).__init__()
self.scale = stride
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
guoyongcs/HNAS
|
Linear
| false
| 15,478
|
[
"MIT"
] | 60
|
2b34e1b637bb03d23ca6559c1b5d1245d9744348
|
https://github.com/guoyongcs/HNAS/tree/2b34e1b637bb03d23ca6559c1b5d1245d9744348
|
UpscaleBlock
|
import torch
import torch.nn as nn
class UpscaleBlock(nn.Module):
""" Upscaling Block using Pixel Shuffle to increase image dimensions. Used in Generator Network"""
"""
Pixel shuffle layer
(Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional
Neural Network, CVPR17)
However, while this approach helps, it is still easy for deconvolution to fall into creating artifacts.
https://distill.pub/2016/deconv-checkerboard/
"""
def __init__(self, in_channels, out_channels=None, kernel_size=3,
stride=1, upscale_factor=2):
super(UpscaleBlock, self).__init__()
if out_channels:
out_channels = out_channels
else:
out_channels = in_channels * upscale_factor ** 2
self.conv = nn.Conv2d(in_channels=in_channels, out_channels=
out_channels, kernel_size=kernel_size, stride=stride, padding=1)
self.pixel_shuffle = nn.PixelShuffle(upscale_factor=upscale_factor)
self.prelu = nn.PReLU()
def forward(self, x):
x = self.conv(x)
x = self.pixel_shuffle(x)
x = self.prelu(x)
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 16
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, xmask)
@triton.jit
def triton_poi_fused__prelu_kernel_1(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
x0 = xindex % 8
x1 = xindex // 8 % 8
x2 = xindex // 64
x3 = xindex
tmp0 = tl.load(in_ptr0 + (4 * (x1 // 2) + 16 * (x0 % 2) + 32 * (x1 % 2) +
64 * x2 + x0 // 2), xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + 0)
tmp4 = tl.broadcast_to(tmp3, [XBLOCK])
tmp1 = 0.0
tmp2 = tmp0 > tmp1
tmp5 = tmp4 * tmp0
tmp6 = tl.where(tmp2, tmp0, tmp5)
tl.store(out_ptr0 + x3, tmp6, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (16, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_2, (16,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (1,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 16, 4, 4), (256, 16, 4, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(1024)](buf1, primals_2, 1024,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_2
buf2 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.float32)
triton_poi_fused__prelu_kernel_1[grid(1024)](buf1, primals_4, buf2,
1024, XBLOCK=256, num_warps=4, num_stages=1)
return buf2, primals_1, primals_3, primals_4, buf1
class UpscaleBlockNew(nn.Module):
""" Upscaling Block using Pixel Shuffle to increase image dimensions. Used in Generator Network"""
"""
Pixel shuffle layer
(Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional
Neural Network, CVPR17)
However, while this approach helps, it is still easy for deconvolution to fall into creating artifacts.
https://distill.pub/2016/deconv-checkerboard/
"""
def __init__(self, in_channels, out_channels=None, kernel_size=3,
stride=1, upscale_factor=2):
super(UpscaleBlockNew, self).__init__()
if out_channels:
out_channels = out_channels
else:
out_channels = in_channels * upscale_factor ** 2
self.conv = nn.Conv2d(in_channels=in_channels, out_channels=
out_channels, kernel_size=kernel_size, stride=stride, padding=1)
self.pixel_shuffle = nn.PixelShuffle(upscale_factor=upscale_factor)
self.prelu = nn.PReLU()
def forward(self, input_0):
primals_1 = self.conv.weight
primals_2 = self.conv.bias
primals_4 = self.prelu.weight
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
grofit/traiNNer
|
UpscaleBlock
| false
| 15,479
|
[
"Apache-2.0"
] | 78
|
12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
https://github.com/grofit/traiNNer/tree/12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
soft_L1
|
import torch
import torch.utils.data
import torch.nn as nn
class soft_L1(nn.Module):
def __init__(self):
super(soft_L1, self).__init__()
def forward(self, input, target, eps=0.0):
ret = torch.abs(input - target) - eps
ret = torch.clamp(ret, min=0.0, max=100.0)
return ret
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.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_abs_clamp_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
tmp3 = tl_math.abs(tmp2)
tmp4 = 0.0
tmp5 = tmp3 - tmp4
tmp6 = triton_helpers.maximum(tmp5, tmp4)
tmp7 = 100.0
tmp8 = triton_helpers.minimum(tmp6, tmp7)
tl.store(out_ptr0 + x0, tmp8, xmask)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_abs_clamp_sub_0[grid(256)](arg0_1, arg1_1, buf0,
256, XBLOCK=128, num_warps=4, num_stages=1)
del arg0_1
del arg1_1
return buf0,
class soft_L1New(nn.Module):
def __init__(self):
super(soft_L1New, 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]
|
haidongz-usc/Curriculum-DeepSDF
|
soft_L1
| false
| 15,480
|
[
"MIT"
] | 65
|
ca216dda8edc6435139a6f657c45800791be94a7
|
https://github.com/haidongz-usc/Curriculum-DeepSDF/tree/ca216dda8edc6435139a6f657c45800791be94a7
|
TVLoss
|
import torch
from torch.nn import functional as F
import torch.nn as nn
def get_image_gradients(image: 'torch.Tensor', step: 'int'=1):
"""Returns image gradients (dy, dx) for each color channel, using
the finite-difference approximation.
Places the gradient [ie. I(x+1,y) - I(x,y)] on the base pixel (x, y).
Both output tensors have the same shape as the input: [b, c, h, w].
Arguments:
image: Tensor with shape [b, c, h, w].
step: the size of the step for the finite difference
Returns:
Pair of tensors (dy, dx) holding the vertical and horizontal
image gradients (ie. 1-step finite difference). To match the
original size image, for example with step=1, dy will always
have zeros in the last row, and dx will always have zeros in
the last column.
"""
right = F.pad(image, (0, step, 0, 0))[..., :, step:]
bottom = F.pad(image, (0, 0, 0, step))[..., step:, :]
dx, dy = right - image, bottom - image
dx[:, :, :, -step:] = 0
dy[:, :, -step:, :] = 0
return dx, dy
def get_outnorm(x: 'torch.Tensor', out_norm: 'str'='') ->torch.Tensor:
""" Common function to get a loss normalization value. Can
normalize by either the batch size ('b'), the number of
channels ('c'), the image size ('i') or combinations
('bi', 'bci', etc)
"""
img_shape = x.shape
if not out_norm:
return 1
norm = 1
if 'b' in out_norm:
norm /= img_shape[0]
if 'c' in out_norm:
norm /= img_shape[-3]
if 'i' in out_norm:
norm /= img_shape[-1] * img_shape[-2]
return norm
def get_4dim_image_gradients(image: 'torch.Tensor'):
"""Returns image gradients (dy, dx) for each color channel, using
the finite-difference approximation.
Similar to get_image_gradients(), but additionally calculates the
gradients in the two diagonal directions: 'dp' (the positive
diagonal: bottom left to top right) and 'dn' (the negative
diagonal: top left to bottom right).
Only 1-step finite difference has been tested and is available.
Arguments:
image: Tensor with shape [b, c, h, w].
Returns:
tensors (dy, dx, dp, dn) holding the vertical, horizontal and
diagonal image gradients (1-step finite difference). dx will
always have zeros in the last column, dy will always have zeros
in the last row, dp will always have zeros in the last row.
"""
right = F.pad(image, (0, 1, 0, 0))[..., :, 1:]
bottom = F.pad(image, (0, 0, 0, 1))[..., 1:, :]
botright = F.pad(image, (0, 1, 0, 1))[..., 1:, 1:]
dx, dy = right - image, bottom - image
dn, dp = botright - image, right - bottom
dx[:, :, :, -1] = 0
dy[:, :, -1, :] = 0
dp[:, :, -1, :] = 0
return dx, dy, dp, dn
class TVLoss(nn.Module):
"""Calculate the L1 or L2 total variation regularization.
Also can calculate experimental 4D directional total variation.
Args:
tv_type: regular 'tv' or 4D 'dtv'
p: use the absolute values '1' or Euclidean distance '2' to
calculate the tv. (alt names: 'l1' and 'l2')
reduction: aggregate results per image either by their 'mean' or
by the total 'sum'. Note: typically, 'sum' should be
normalized with out_norm: 'bci', while 'mean' needs only 'b'.
out_norm: normalizes the TV loss by either the batch size ('b'), the
number of channels ('c'), the image size ('i') or combinations
('bi', 'bci', etc).
beta: β factor to control the balance between sharp edges (1<β<2)
and washed out results (penalizing edges) with β >= 2.
Ref:
Mahendran et al. https://arxiv.org/pdf/1412.0035.pdf
"""
def __init__(self, tv_type: 'str'='tv', p=2, reduction: 'str'='mean',
out_norm: 'str'='b', beta: 'int'=2) ->None:
super(TVLoss, self).__init__()
if isinstance(p, str):
p = 1 if '1' in p else 2
if p not in [1, 2]:
raise ValueError(f'Expected p value to be 1 or 2, but got {p}')
self.p = p
self.tv_type = tv_type.lower()
self.reduction = torch.sum if reduction == 'sum' else torch.mean
self.out_norm = out_norm
self.beta = beta
def forward(self, x: 'torch.Tensor') ->torch.Tensor:
norm = get_outnorm(x, self.out_norm)
img_shape = x.shape
if len(img_shape) == 3:
reduce_axes = None
elif len(img_shape) == 4:
reduce_axes = -3, -2, -1
x.size()[0]
else:
raise ValueError(
f'Expected input tensor to be of ndim 3 or 4, but got {len(img_shape)}'
)
if self.tv_type in ('dtv', '4d'):
gradients = get_4dim_image_gradients(x)
else:
gradients = get_image_gradients(x)
loss = 0
for grad_dir in gradients:
if self.p == 1:
loss += self.reduction(grad_dir.abs(), dim=reduce_axes)
elif self.p == 2:
loss += self.reduction(torch.pow(grad_dir, 2), dim=reduce_axes)
loss = loss.sum() if 'b' in self.out_norm else loss.mean()
if self.beta != 2:
loss = torch.pow(loss, self.beta / 2)
return loss * norm
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.nn import functional as F
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_fill_lift_fresh_mean_pow_sub_0(in_ptr0, out_ptr0,
out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 4
RBLOCK: tl.constexpr = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex % 4
r5 = rindex
x0 = xindex
r3 = rindex // 4 % 4
tmp10 = tl.load(in_ptr0 + (r5 + 64 * x0), xmask, other=0.0)
tmp0 = r1
tmp1 = tl.full([1, 1], 3, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = 0.0
tmp4 = tl.full(tmp3.shape, 0.0, tmp3.dtype)
tmp5 = tl.where(tmp2, tmp3, tmp4)
tmp6 = 1 + r1
tmp7 = tl.full([1, 1], 4, tl.int64)
tmp8 = tmp6 < tmp7
tmp9 = tl.load(in_ptr0 + (1 + r5 + 64 * x0), tmp8 & xmask, other=0.0)
tmp11 = tmp9 - tmp10
tmp12 = tl.where(tmp2, tmp5, tmp11)
tmp13 = tmp12 * tmp12
tmp14 = tl.broadcast_to(tmp13, [XBLOCK, RBLOCK])
tmp16 = tl.where(xmask, tmp14, 0)
tmp17 = tl.sum(tmp16, 1)[:, None]
tmp18 = r3
tmp19 = tmp18 >= tmp1
tmp20 = tl.where(tmp19, tmp3, tmp4)
tmp21 = 1 + r3
tmp22 = tmp21 < tmp7
tmp23 = tl.load(in_ptr0 + (4 + r5 + 64 * x0), tmp22 & xmask, other=0.0)
tmp24 = tmp23 - tmp10
tmp25 = tl.where(tmp19, tmp20, tmp24)
tmp26 = tmp25 * tmp25
tmp27 = tl.broadcast_to(tmp26, [XBLOCK, RBLOCK])
tmp29 = tl.where(xmask, tmp27, 0)
tmp30 = tl.sum(tmp29, 1)[:, None]
tl.store(out_ptr0 + x0, tmp17, xmask)
tl.store(out_ptr1 + x0, tmp30, xmask)
@triton.jit
def triton_per_fused_add_fill_lift_fresh_mean_mul_pow_sub_sum_1(in_out_ptr0,
in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr):
RBLOCK: tl.constexpr = 4
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp5 = tl.load(in_ptr1 + r0, None)
tmp1 = 64.0
tmp2 = tmp0 / tmp1
tmp3 = 0.0
tmp4 = tmp2 + tmp3
tmp6 = tmp5 / tmp1
tmp7 = tmp4 + tmp6
tmp8 = tl.broadcast_to(tmp7, [XBLOCK, RBLOCK])
tmp10 = tl.sum(tmp8, 1)[:, None]
tmp11 = 0.25
tmp12 = tmp10 * tmp11
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp12, None)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4,), (1,), torch.float32)
buf1 = empty_strided_cuda((4,), (1,), torch.float32)
get_raw_stream(0)
triton_per_fused_fill_lift_fresh_mean_pow_sub_0[grid(4)](arg0_1,
buf0, buf1, 4, 64, XBLOCK=1, num_warps=2, num_stages=1)
del arg0_1
buf2 = empty_strided_cuda((), (), torch.float32)
buf3 = buf2
del buf2
triton_per_fused_add_fill_lift_fresh_mean_mul_pow_sub_sum_1[grid(1)](
buf3, buf0, buf1, 1, 4, XBLOCK=1, num_warps=2, num_stages=1)
del buf0
del buf1
return buf3,
def get_image_gradients(image: 'torch.Tensor', step: 'int'=1):
"""Returns image gradients (dy, dx) for each color channel, using
the finite-difference approximation.
Places the gradient [ie. I(x+1,y) - I(x,y)] on the base pixel (x, y).
Both output tensors have the same shape as the input: [b, c, h, w].
Arguments:
image: Tensor with shape [b, c, h, w].
step: the size of the step for the finite difference
Returns:
Pair of tensors (dy, dx) holding the vertical and horizontal
image gradients (ie. 1-step finite difference). To match the
original size image, for example with step=1, dy will always
have zeros in the last row, and dx will always have zeros in
the last column.
"""
right = F.pad(image, (0, step, 0, 0))[..., :, step:]
bottom = F.pad(image, (0, 0, 0, step))[..., step:, :]
dx, dy = right - image, bottom - image
dx[:, :, :, -step:] = 0
dy[:, :, -step:, :] = 0
return dx, dy
def get_outnorm(x: 'torch.Tensor', out_norm: 'str'='') ->torch.Tensor:
""" Common function to get a loss normalization value. Can
normalize by either the batch size ('b'), the number of
channels ('c'), the image size ('i') or combinations
('bi', 'bci', etc)
"""
img_shape = x.shape
if not out_norm:
return 1
norm = 1
if 'b' in out_norm:
norm /= img_shape[0]
if 'c' in out_norm:
norm /= img_shape[-3]
if 'i' in out_norm:
norm /= img_shape[-1] * img_shape[-2]
return norm
def get_4dim_image_gradients(image: 'torch.Tensor'):
"""Returns image gradients (dy, dx) for each color channel, using
the finite-difference approximation.
Similar to get_image_gradients(), but additionally calculates the
gradients in the two diagonal directions: 'dp' (the positive
diagonal: bottom left to top right) and 'dn' (the negative
diagonal: top left to bottom right).
Only 1-step finite difference has been tested and is available.
Arguments:
image: Tensor with shape [b, c, h, w].
Returns:
tensors (dy, dx, dp, dn) holding the vertical, horizontal and
diagonal image gradients (1-step finite difference). dx will
always have zeros in the last column, dy will always have zeros
in the last row, dp will always have zeros in the last row.
"""
right = F.pad(image, (0, 1, 0, 0))[..., :, 1:]
bottom = F.pad(image, (0, 0, 0, 1))[..., 1:, :]
botright = F.pad(image, (0, 1, 0, 1))[..., 1:, 1:]
dx, dy = right - image, bottom - image
dn, dp = botright - image, right - bottom
dx[:, :, :, -1] = 0
dy[:, :, -1, :] = 0
dp[:, :, -1, :] = 0
return dx, dy, dp, dn
class TVLossNew(nn.Module):
"""Calculate the L1 or L2 total variation regularization.
Also can calculate experimental 4D directional total variation.
Args:
tv_type: regular 'tv' or 4D 'dtv'
p: use the absolute values '1' or Euclidean distance '2' to
calculate the tv. (alt names: 'l1' and 'l2')
reduction: aggregate results per image either by their 'mean' or
by the total 'sum'. Note: typically, 'sum' should be
normalized with out_norm: 'bci', while 'mean' needs only 'b'.
out_norm: normalizes the TV loss by either the batch size ('b'), the
number of channels ('c'), the image size ('i') or combinations
('bi', 'bci', etc).
beta: β factor to control the balance between sharp edges (1<β<2)
and washed out results (penalizing edges) with β >= 2.
Ref:
Mahendran et al. https://arxiv.org/pdf/1412.0035.pdf
"""
def __init__(self, tv_type: 'str'='tv', p=2, reduction: 'str'='mean',
out_norm: 'str'='b', beta: 'int'=2) ->None:
super(TVLossNew, self).__init__()
if isinstance(p, str):
p = 1 if '1' in p else 2
if p not in [1, 2]:
raise ValueError(f'Expected p value to be 1 or 2, but got {p}')
self.p = p
self.tv_type = tv_type.lower()
self.reduction = torch.sum if reduction == 'sum' else torch.mean
self.out_norm = out_norm
self.beta = beta
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
grofit/traiNNer
|
TVLoss
| false
| 15,481
|
[
"Apache-2.0"
] | 78
|
12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
https://github.com/grofit/traiNNer/tree/12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
EnergyConservingLoss
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class EnergyConservingLoss(nn.L1Loss):
"""Energy conserving loss.
A two term loss that enforces energy conservation after
:cite:`Rethage2018`.
The loss can be described as:
.. math::
\\ell(x, y, m) = L = \\{l_1,\\dots,l_N\\}^\\top, \\quad
l_n = |x_n - y_n| + |b_n - \\hat{b_n}|,
where :math:`N` is the batch size. If reduction is not ``'none'``, then:
.. math::
\\ell(x, y, m) =
\\begin{cases}
\\operatorname{mean}(L), & \\text{if reduction} = \\text{'mean';}\\\\
\\operatorname{sum}(L), & \\text{if reduction} = \\text{'sum'.}
\\end{cases}
:math:`x` is the input signal (estimated target), :math:`y` the target
signal, :math:`m` the mixture signal, :math:`b` the background signal given
by :math:`b = m - y`, and :math:`\\hat{b}` the estimated background signal
given by :math:`\\hat{b} = m - x`.
Args:
reduction (string, optional): specifies the reduction to apply to the
output: 'none' | 'mean' | 'sum'.
'none': no reduction will be applied, 'mean': the sum of the output
will be divided by the number of elements in the output, 'sum': the
output will be summed.
Shape:
- Input: :math:`(N, *)` where `*` means, any number of additional
dimensions
- Target: :math:`(N, *)`, same shape as the input
- Mixture: :math:`(N, *)`, same shape as the input
- Output: scalar. If reduction is ``'none'``, then :math:`(N, *)`, same
shape as the input
Examples:
>>> import torch
>>> _ = torch.manual_seed(0)
>>> loss = EnergyConservingLoss()
>>> input = torch.randn(3, 5, requires_grad=True)
>>> target = torch.randn(3, 5)
>>> mixture = torch.randn(3, 5)
>>> loss(input, target, mixture)
tensor(2.1352, grad_fn=<AddBackward0>)
"""
def __init__(self, *, reduction='mean'):
super().__init__(None, None, reduction)
def forward(self, y_predicted, y, x):
noise = x - y
noise_predicted = x - y_predicted
return F.l1_loss(y_predicted, y, reduction=self.reduction) + F.l1_loss(
noise_predicted, noise, reduction=self.reduction)
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand(
[4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_abs_add_mean_sub_0(in_out_ptr0, in_ptr0, in_ptr1,
in_ptr2, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp1 = tl.load(in_ptr1 + r0, None)
tmp7 = tl.load(in_ptr2 + r0, None)
tmp2 = tmp0 - tmp1
tmp3 = tl_math.abs(tmp2)
tmp4 = tl.broadcast_to(tmp3, [RBLOCK])
tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0))
tmp8 = tmp7 - tmp0
tmp9 = tmp7 - tmp1
tmp10 = tmp8 - tmp9
tmp11 = tl_math.abs(tmp10)
tmp12 = tl.broadcast_to(tmp11, [RBLOCK])
tmp14 = triton_helpers.promote_to_tensor(tl.sum(tmp12, 0))
tmp15 = 256.0
tmp16 = tmp6 / tmp15
tmp17 = tmp14 / tmp15
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((), (), torch.float32)
buf2 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_abs_add_mean_sub_0[grid(1)](buf2, arg2_1, arg1_1,
arg0_1, 1, 256, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
del arg2_1
return buf2,
class EnergyConservingLossNew(nn.L1Loss):
"""Energy conserving loss.
A two term loss that enforces energy conservation after
:cite:`Rethage2018`.
The loss can be described as:
.. math::
\\ell(x, y, m) = L = \\{l_1,\\dots,l_N\\}^\\top, \\quad
l_n = |x_n - y_n| + |b_n - \\hat{b_n}|,
where :math:`N` is the batch size. If reduction is not ``'none'``, then:
.. math::
\\ell(x, y, m) =
\\begin{cases}
\\operatorname{mean}(L), & \\text{if reduction} = \\text{'mean';}\\\\
\\operatorname{sum}(L), & \\text{if reduction} = \\text{'sum'.}
\\end{cases}
:math:`x` is the input signal (estimated target), :math:`y` the target
signal, :math:`m` the mixture signal, :math:`b` the background signal given
by :math:`b = m - y`, and :math:`\\hat{b}` the estimated background signal
given by :math:`\\hat{b} = m - x`.
Args:
reduction (string, optional): specifies the reduction to apply to the
output: 'none' | 'mean' | 'sum'.
'none': no reduction will be applied, 'mean': the sum of the output
will be divided by the number of elements in the output, 'sum': the
output will be summed.
Shape:
- Input: :math:`(N, *)` where `*` means, any number of additional
dimensions
- Target: :math:`(N, *)`, same shape as the input
- Mixture: :math:`(N, *)`, same shape as the input
- Output: scalar. If reduction is ``'none'``, then :math:`(N, *)`, same
shape as the input
Examples:
>>> import torch
>>> _ = torch.manual_seed(0)
>>> loss = EnergyConservingLoss()
>>> input = torch.randn(3, 5, requires_grad=True)
>>> target = torch.randn(3, 5)
>>> mixture = torch.randn(3, 5)
>>> loss(input, target, mixture)
tensor(2.1352, grad_fn=<AddBackward0>)
"""
def __init__(self, *, reduction='mean'):
super().__init__(None, None, reduction)
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]
|
hagenw/audtorch
|
EnergyConservingLoss
| false
| 15,482
|
[
"MIT"
] | 81
|
d82ae7f7f8c7edb7b7180b83442224e9a68483bd
|
https://github.com/hagenw/audtorch/tree/d82ae7f7f8c7edb7b7180b83442224e9a68483bd
|
minibatch_std_concat_layer
|
import copy
import torch
import torch.nn as nn
def mean(tensor, dim=None, keepdim=False):
if dim is None:
return torch.mean(tensor)
else:
if isinstance(dim, int):
dim = [dim]
dim = sorted(dim)
for d in dim:
tensor = tensor.mean(dim=d, keepdim=True)
if not keepdim:
for i, d in enumerate(dim):
tensor.squeeze_(d - i)
return tensor
class minibatch_std_concat_layer(nn.Module):
def __init__(self, averaging='all'):
super(minibatch_std_concat_layer, self).__init__()
self.averaging = averaging.lower()
if 'group' in self.averaging:
self.n = int(self.averaging[5:])
else:
assert self.averaging in ['all', 'flat', 'spatial', 'none', 'gpool'
], 'Invalid averaging mode' % self.averaging
self.adjusted_std = lambda x, **kwargs: torch.sqrt(torch.mean((x -
torch.mean(x, **kwargs)) ** 2, **kwargs) + 1e-08)
def forward(self, x):
shape = list(x.size())
target_shape = copy.deepcopy(shape)
vals = self.adjusted_std(x, dim=0, keepdim=True)
if self.averaging == 'all':
target_shape[1] = 1
vals = torch.mean(vals, dim=1, keepdim=True)
elif self.averaging == 'spatial':
if len(shape) == 4:
vals = mean(vals, axis=[2, 3], keepdim=True)
elif self.averaging == 'none':
target_shape = [target_shape[0]] + [s for s in target_shape[1:]]
elif self.averaging == 'gpool':
if len(shape) == 4:
vals = mean(x, [0, 2, 3], keepdim=True)
elif self.averaging == 'flat':
target_shape[1] = 1
vals = torch.FloatTensor([self.adjusted_std(x)])
else:
target_shape[1] = self.n
vals = vals.view(self.n, self.shape[1] / self.n, self.shape[2],
self.shape[3])
vals = mean(vals, axis=0, keepdim=True).view(1, self.n, 1, 1)
vals = vals.expand(*target_shape)
return torch.cat([x, vals], 1)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_add_mean_pow_sqrt_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
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + (64 + x0), xmask)
tmp3 = tl.load(in_ptr0 + (128 + x0), xmask)
tmp5 = tl.load(in_ptr0 + (192 + x0), xmask)
tmp24 = tl.load(in_ptr0 + (16 + x0), xmask)
tmp25 = tl.load(in_ptr0 + (80 + x0), xmask)
tmp27 = tl.load(in_ptr0 + (144 + x0), xmask)
tmp29 = tl.load(in_ptr0 + (208 + x0), xmask)
tmp47 = tl.load(in_ptr0 + (32 + x0), xmask)
tmp48 = tl.load(in_ptr0 + (96 + x0), xmask)
tmp50 = tl.load(in_ptr0 + (160 + x0), xmask)
tmp52 = tl.load(in_ptr0 + (224 + x0), xmask)
tmp70 = tl.load(in_ptr0 + (48 + x0), xmask)
tmp71 = tl.load(in_ptr0 + (112 + x0), xmask)
tmp73 = tl.load(in_ptr0 + (176 + x0), xmask)
tmp75 = tl.load(in_ptr0 + (240 + x0), 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-08
tmp22 = tmp20 + tmp21
tmp23 = libdevice.sqrt(tmp22)
tmp26 = tmp24 + tmp25
tmp28 = tmp26 + tmp27
tmp30 = tmp28 + tmp29
tmp31 = tmp30 / tmp7
tmp32 = tmp24 - tmp31
tmp33 = tmp32 * tmp32
tmp34 = tmp25 - tmp31
tmp35 = tmp34 * tmp34
tmp36 = tmp33 + tmp35
tmp37 = tmp27 - tmp31
tmp38 = tmp37 * tmp37
tmp39 = tmp36 + tmp38
tmp40 = tmp29 - tmp31
tmp41 = tmp40 * tmp40
tmp42 = tmp39 + tmp41
tmp43 = tmp42 / tmp7
tmp44 = tmp43 + tmp21
tmp45 = libdevice.sqrt(tmp44)
tmp46 = tmp23 + tmp45
tmp49 = tmp47 + tmp48
tmp51 = tmp49 + tmp50
tmp53 = tmp51 + tmp52
tmp54 = tmp53 / tmp7
tmp55 = tmp47 - tmp54
tmp56 = tmp55 * tmp55
tmp57 = tmp48 - tmp54
tmp58 = tmp57 * tmp57
tmp59 = tmp56 + tmp58
tmp60 = tmp50 - tmp54
tmp61 = tmp60 * tmp60
tmp62 = tmp59 + tmp61
tmp63 = tmp52 - tmp54
tmp64 = tmp63 * tmp63
tmp65 = tmp62 + tmp64
tmp66 = tmp65 / tmp7
tmp67 = tmp66 + tmp21
tmp68 = libdevice.sqrt(tmp67)
tmp69 = tmp46 + tmp68
tmp72 = tmp70 + tmp71
tmp74 = tmp72 + tmp73
tmp76 = tmp74 + tmp75
tmp77 = tmp76 / tmp7
tmp78 = tmp70 - tmp77
tmp79 = tmp78 * tmp78
tmp80 = tmp71 - tmp77
tmp81 = tmp80 * tmp80
tmp82 = tmp79 + tmp81
tmp83 = tmp73 - tmp77
tmp84 = tmp83 * tmp83
tmp85 = tmp82 + tmp84
tmp86 = tmp75 - tmp77
tmp87 = tmp86 * tmp86
tmp88 = tmp85 + tmp87
tmp89 = tmp88 / tmp7
tmp90 = tmp89 + tmp21
tmp91 = libdevice.sqrt(tmp90)
tmp92 = tmp69 + tmp91
tmp93 = tmp92 / tmp7
tl.store(out_ptr0 + x0, tmp93, xmask)
@triton.jit
def triton_poi_fused_cat_1(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], 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], 5, tl.int64)
tmp9 = tl.load(in_ptr1 + x0, tmp6 & xmask, eviction_policy='evict_last',
other=0.0)
tmp10 = tl.where(tmp4, tmp5, tmp9)
tl.store(out_ptr0 + x3, tmp10, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((1, 1, 4, 4), (16, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_add_mean_pow_sqrt_sub_0[grid(16)](arg0_1, buf0, 16,
XBLOCK=16, num_warps=1, num_stages=1)
buf1 = empty_strided_cuda((4, 5, 4, 4), (80, 16, 4, 1), torch.float32)
triton_poi_fused_cat_1[grid(320)](arg0_1, buf0, buf1, 320, XBLOCK=
128, num_warps=4, num_stages=1)
del arg0_1
del buf0
return buf1,
def mean(tensor, dim=None, keepdim=False):
if dim is None:
return torch.mean(tensor)
else:
if isinstance(dim, int):
dim = [dim]
dim = sorted(dim)
for d in dim:
tensor = tensor.mean(dim=d, keepdim=True)
if not keepdim:
for i, d in enumerate(dim):
tensor.squeeze_(d - i)
return tensor
class minibatch_std_concat_layerNew(nn.Module):
def __init__(self, averaging='all'):
super(minibatch_std_concat_layerNew, self).__init__()
self.averaging = averaging.lower()
if 'group' in self.averaging:
self.n = int(self.averaging[5:])
else:
assert self.averaging in ['all', 'flat', 'spatial', 'none', 'gpool'
], 'Invalid averaging mode' % self.averaging
self.adjusted_std = lambda x, **kwargs: torch.sqrt(torch.mean((x -
torch.mean(x, **kwargs)) ** 2, **kwargs) + 1e-08)
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
grofit/traiNNer
|
minibatch_std_concat_layer
| false
| 15,483
|
[
"Apache-2.0"
] | 78
|
12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
https://github.com/grofit/traiNNer/tree/12d006fd44ed304e4178839c53b1f3d95ca25dcb
|
AdMSoftmaxLoss
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class AdMSoftmaxLoss(nn.Module):
def __init__(self, in_features, out_features, s=30.0, m=0.4):
"""
AM Softmax Loss
"""
super(AdMSoftmaxLoss, self).__init__()
self.s = s
self.m = m
self.in_features = in_features
self.out_features = out_features
self.fc = nn.Linear(in_features, out_features, bias=False)
def forward(self, x, labels):
"""
input shape (N, in_features)
"""
assert len(x) == len(labels)
assert torch.min(labels) >= 0
assert torch.max(labels) < self.out_features
for W in self.fc.parameters():
W = F.normalize(W, dim=1)
x = F.normalize(x, dim=1)
wf = self.fc(x)
numerator = self.s * (torch.diagonal(wf.transpose(0, 1)[labels]) -
self.m)
excl = torch.cat([torch.cat((wf[i, :y], wf[i, y + 1:])).unsqueeze(0
) for i, y in enumerate(labels)], dim=0)
denominator = torch.exp(numerator) + torch.sum(torch.exp(self.s *
excl), dim=1)
L = numerator - torch.log(denominator)
return -torch.mean(L)
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.ones([4], dtype=torch.int64)]
def get_init_inputs():
return [[], {'in_features': 4, 'out_features': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
import torch.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
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 = 1e-12
tmp14 = triton_helpers.maximum(tmp12, tmp13)
tmp15 = tmp0 / tmp14
tl.store(out_ptr0 + x3, tmp15, xmask)
@triton.jit
def triton_poi_fused_mul_sub_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16
x0 = xindex % 16
x2 = xindex
tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp1 = tl.full([XBLOCK], 4, tl.int32)
tmp2 = tmp0 + tmp1
tmp3 = tmp0 < 0
tmp4 = tl.where(tmp3, tmp2, tmp0)
tl.device_assert((0 <= tmp4) & (tmp4 < 4) | ~xmask,
'index out of bounds: 0 <= tmp4 < 4')
tmp6 = tl.load(in_ptr1 + (x0 + 16 * tmp4 + 64 * x1), xmask)
tmp7 = 0.4
tmp8 = tmp6 - tmp7
tmp9 = 30.0
tmp10 = tmp8 * tmp9
tl.store(out_ptr0 + x2, tmp10, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_div_0[grid(256)](primals_1, buf0, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del primals_1
buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf0, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_3, (4, 4), (1, 4), 0), out=buf1)
del primals_3
buf2 = empty_strided_cuda((4, 4, 4), (4, 1, 16), torch.float32)
triton_poi_fused_mul_sub_1[grid(64)](primals_2, buf1, buf2, 64,
XBLOCK=64, num_warps=1, num_stages=1)
return buf2, reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0
), primals_2, reinterpret_tensor(buf0, (64, 4), (4, 1), 0)
class AdMSoftmaxLossNew(nn.Module):
def __init__(self, in_features, out_features, s=30.0, m=0.4):
"""
AM Softmax Loss
"""
super(AdMSoftmaxLossNew, self).__init__()
self.s = s
self.m = m
self.in_features = in_features
self.out_features = out_features
self.fc = nn.Linear(in_features, out_features, bias=False)
def forward(self, input_0, input_1):
primals_3 = self.fc.weight
primals_1 = input_0
primals_2 = input_1
output = call([primals_1, primals_2, primals_3])
return output[0]
|
gcambara/s3prl
|
AdMSoftmaxLoss
| false
| 15,484
|
[
"MIT"
] | 856
|
33284ebde3a903ed8604d6dae85669d0174ae1d3
|
https://github.com/gcambara/s3prl/tree/33284ebde3a903ed8604d6dae85669d0174ae1d3
|
Nullifier
|
import torch
import torch.nn as nn
class Nullifier(nn.Container):
def __init__(self):
super(Nullifier, self).__init__()
def forward(self, inTensor):
outTensor = inTensor.clone()
outTensor.fill_(0.0)
return outTensor
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_fill_0(out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = 0.0
tl.store(out_ptr0 + x0, tmp0, xmask)
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_fill_0[grid(256)](buf0, 256, XBLOCK=128, num_warps
=4, num_stages=1)
return buf0,
class NullifierNew(nn.Container):
def __init__(self):
super(NullifierNew, self).__init__()
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
haoruilee/DeepSets
|
Nullifier
| false
| 15,485
|
[
"Apache-2.0"
] | 213
|
b405dd6b51a34fb1ef622e25e6685b417b7b7cbb
|
https://github.com/haoruilee/DeepSets/tree/b405dd6b51a34fb1ef622e25e6685b417b7b7cbb
|
MMTM
|
import torch
import torch.nn as nn
def init_weights(m):
None
if type(m) == nn.Linear:
None
else:
None
class MMTM(nn.Module):
def __init__(self, dim_visual, dim_skeleton, ratio):
super(MMTM, self).__init__()
dim = dim_visual + dim_skeleton
dim_out = int(2 * dim / ratio)
self.fc_squeeze = nn.Linear(dim, dim_out)
self.fc_visual = nn.Linear(dim_out, dim_visual)
self.fc_skeleton = nn.Linear(dim_out, dim_skeleton)
self.relu = nn.ReLU()
self.sigmoid = nn.Sigmoid()
with torch.no_grad():
self.fc_squeeze.apply(init_weights)
self.fc_visual.apply(init_weights)
self.fc_skeleton.apply(init_weights)
def forward(self, visual, skeleton):
squeeze_array = []
for tensor in [visual, skeleton]:
tview = tensor.view(tensor.shape[:2] + (-1,))
squeeze_array.append(torch.mean(tview, dim=-1))
squeeze = torch.cat(squeeze_array, 1)
excitation = self.fc_squeeze(squeeze)
excitation = self.relu(excitation)
vis_out = self.fc_visual(excitation)
sk_out = self.fc_skeleton(excitation)
vis_out = self.sigmoid(vis_out)
sk_out = self.sigmoid(sk_out)
dim_diff = len(visual.shape) - len(vis_out.shape)
vis_out = vis_out.view(vis_out.shape + (1,) * dim_diff)
dim_diff = len(skeleton.shape) - len(sk_out.shape)
sk_out = sk_out.view(sk_out.shape + (1,) * dim_diff)
return visual * vis_out, skeleton * sk_out
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'dim_visual': 4, 'dim_skeleton': 4, '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 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_per_fused_mean_0(in_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.
constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
x2 = xindex % 4
x3 = xindex // 4
tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(xmask, tmp1, 0)
tmp4 = tl.sum(tmp3, 1)[:, None]
tmp5 = 16.0
tmp6 = tmp4 / tmp5
tl.store(out_ptr1 + (x2 + 8 * x3), tmp6, xmask)
@triton.jit
def triton_per_fused_mean_1(in_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.
constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
x2 = xindex % 4
x3 = xindex // 4
tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(xmask, tmp1, 0)
tmp4 = tl.sum(tmp3, 1)[:, None]
tmp5 = 16.0
tmp6 = tmp4 / tmp5
tl.store(out_ptr1 + (x2 + 8 * x3), tmp6, xmask)
@triton.jit
def triton_poi_fused_relu_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.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_mul_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 16
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tl.sigmoid(tmp1)
tmp3 = tmp0 * tmp2
tl.store(out_ptr0 + x2, tmp3, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_3, (4, 8), (8, 1))
assert_size_stride(primals_4, (4,), (1,))
assert_size_stride(primals_5, (4, 4), (4, 1))
assert_size_stride(primals_6, (4,), (1,))
assert_size_stride(primals_7, (4, 4), (4, 1))
assert_size_stride(primals_8, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf4 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
buf2 = reinterpret_tensor(buf4, (4, 4), (8, 1), 0)
get_raw_stream(0)
triton_per_fused_mean_0[grid(16)](primals_1, buf2, 16, 16, XBLOCK=8,
num_warps=2, num_stages=1)
buf3 = reinterpret_tensor(buf4, (4, 4), (8, 1), 4)
triton_per_fused_mean_1[grid(16)](primals_2, buf3, 16, 16, XBLOCK=1,
num_warps=2, num_stages=1)
buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf4, reinterpret_tensor(primals_3, (8, 4), (1, 8
), 0), out=buf5)
del primals_3
buf6 = buf5
del buf5
triton_poi_fused_relu_2[grid(16)](buf6, primals_4, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del primals_4
buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_6, buf6, reinterpret_tensor(primals_5,
(4, 4), (1, 4), 0), alpha=1, beta=1, out=buf7)
del primals_6
buf8 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_8, buf6, reinterpret_tensor(primals_7,
(4, 4), (1, 4), 0), alpha=1, beta=1, out=buf8)
del primals_8
buf9 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_mul_3[grid(256)](primals_1, buf7, buf9, 256,
XBLOCK=256, num_warps=4, num_stages=1)
buf10 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_mul_3[grid(256)](primals_2, buf8, buf10, 256,
XBLOCK=256, num_warps=4, num_stages=1)
return (buf9, buf10, primals_1, primals_2, buf4, buf6, buf7, buf8,
primals_7, primals_5)
def init_weights(m):
None
if type(m) == nn.Linear:
None
else:
None
class MMTMNew(nn.Module):
def __init__(self, dim_visual, dim_skeleton, ratio):
super(MMTMNew, self).__init__()
dim = dim_visual + dim_skeleton
dim_out = int(2 * dim / ratio)
self.fc_squeeze = nn.Linear(dim, dim_out)
self.fc_visual = nn.Linear(dim_out, dim_visual)
self.fc_skeleton = nn.Linear(dim_out, dim_skeleton)
self.relu = nn.ReLU()
self.sigmoid = nn.Sigmoid()
with torch.no_grad():
self.fc_squeeze.apply(init_weights)
self.fc_visual.apply(init_weights)
self.fc_skeleton.apply(init_weights)
def forward(self, input_0, input_1):
primals_3 = self.fc_squeeze.weight
primals_4 = self.fc_squeeze.bias
primals_5 = self.fc_visual.weight
primals_6 = self.fc_visual.bias
primals_7 = self.fc_skeleton.weight
primals_8 = self.fc_skeleton.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])
return output[0], output[1]
|
haamoon/mmtm
|
MMTM
| false
| 15,486
|
[
"MIT"
] | 70
|
1c81cfefad5532cfb39193b8af3840ac3346e897
|
https://github.com/haamoon/mmtm/tree/1c81cfefad5532cfb39193b8af3840ac3346e897
|
MaskedInstanceNorm1d
|
import torch
import torch.cuda
from torch import nn
import torch.distributed
import torch.utils.data
import torch.optim
class MaskedInstanceNorm1d(nn.Module):
"""Instance norm + masking."""
MAX_CNT = 100000.0
def __init__(self, d_channel: 'int', unbiased: 'bool'=True, affine:
'bool'=False):
super().__init__()
self.d_channel = d_channel
self.unbiased = unbiased
self.affine = affine
if self.affine:
gamma = torch.ones(d_channel, dtype=torch.float)
beta = torch.zeros_like(gamma)
self.register_parameter('gamma', nn.Parameter(gamma))
self.register_parameter('beta', nn.Parameter(beta))
def forward(self, x: 'torch.Tensor', x_mask: 'torch.Tensor'
) ->torch.Tensor:
"""`x`: [B,C,T], `x_mask`: [B,T] => [B,C,T]."""
x_mask = x_mask.unsqueeze(1).type_as(x)
cnt = x_mask.sum(dim=-1, keepdim=True)
cnt_for_mu = cnt.clamp(1.0, self.MAX_CNT)
mu = (x * x_mask).sum(dim=-1, keepdim=True) / cnt_for_mu
sigma = (x - mu) ** 2
cnt_fot_sigma = (cnt - int(self.unbiased)).clamp(1.0, self.MAX_CNT)
sigma = (sigma * x_mask).sum(dim=-1, keepdim=True) / cnt_fot_sigma
sigma = (sigma + 1e-08).sqrt()
y = (x - mu) / sigma
if self.affine:
gamma = self.gamma.unsqueeze(0).unsqueeze(-1)
beta = self.beta.unsqueeze(0).unsqueeze(-1)
y = y * gamma + beta
return y
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'d_channel': 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.cuda
from torch import nn
import torch.distributed
import torch.utils.data
import torch.optim
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_add_clamp_div_mul_pow_sqrt_sub_sum_0(in_out_ptr0,
in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex % 64
x0 = xindex % 16
x2 = xindex // 64
x4 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x3, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + (4 * 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 * 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 * 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 * 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 = tmp1 + tmp4
tmp16 = tmp15 + tmp8
tmp17 = tmp16 + tmp12
tmp18 = 1.0
tmp19 = triton_helpers.maximum(tmp17, tmp18)
tmp20 = 100000.0
tmp21 = triton_helpers.minimum(tmp19, tmp20)
tmp22 = tmp14 / tmp21
tmp23 = tmp0 - tmp22
tmp24 = tmp23 * tmp23
tmp25 = tmp24 * tmp1
tmp26 = tmp3 - tmp22
tmp27 = tmp26 * tmp26
tmp28 = tmp27 * tmp4
tmp29 = tmp25 + tmp28
tmp30 = tmp7 - tmp22
tmp31 = tmp30 * tmp30
tmp32 = tmp31 * tmp8
tmp33 = tmp29 + tmp32
tmp34 = tmp11 - tmp22
tmp35 = tmp34 * tmp34
tmp36 = tmp35 * tmp12
tmp37 = tmp33 + tmp36
tmp38 = tmp17 - tmp18
tmp39 = triton_helpers.maximum(tmp38, tmp18)
tmp40 = triton_helpers.minimum(tmp39, tmp20)
tmp41 = tmp37 / tmp40
tmp42 = 1e-08
tmp43 = tmp41 + tmp42
tmp44 = libdevice.sqrt(tmp43)
tl.store(out_ptr0 + x4, tmp22, xmask)
tl.store(in_out_ptr0 + x4, tmp44, xmask)
@triton.jit
def triton_poi_fused_add_clamp_div_sqrt_sub_sum_1(in_ptr0, in_ptr1, in_ptr2,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex % 256
x4 = xindex // 4
x5 = xindex
tmp0 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + x4, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + x4, xmask, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = tmp2 / tmp3
tl.store(out_ptr0 + x5, tmp4, xmask)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4, 1), (64, 16, 4, 1, 256),
torch.float32)
buf1 = empty_strided_cuda((4, 4, 4, 4, 1), (64, 16, 4, 1, 256),
torch.float32)
buf2 = buf1
del buf1
get_raw_stream(0)
triton_poi_fused_add_clamp_div_mul_pow_sqrt_sub_sum_0[grid(256)](buf2,
arg1_1, arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1)
del arg0_1
buf3 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1),
torch.float32)
triton_poi_fused_add_clamp_div_sqrt_sub_sum_1[grid(1024)](arg1_1,
buf0, buf2, buf3, 1024, XBLOCK=256, num_warps=4, num_stages=1)
del arg1_1
del buf0
del buf2
return buf3,
class MaskedInstanceNorm1dNew(nn.Module):
"""Instance norm + masking."""
MAX_CNT = 100000.0
def __init__(self, d_channel: 'int', unbiased: 'bool'=True, affine:
'bool'=False):
super().__init__()
self.d_channel = d_channel
self.unbiased = unbiased
self.affine = affine
if self.affine:
gamma = torch.ones(d_channel, dtype=torch.float)
beta = torch.zeros_like(gamma)
self.register_parameter('gamma', nn.Parameter(gamma))
self.register_parameter('beta', nn.Parameter(beta))
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
hamjam/NeMo
|
MaskedInstanceNorm1d
| false
| 15,487
|
[
"Apache-2.0"
] | 4,145
|
b3484d32e1317666151f931bfa39867d88ed8658
|
https://github.com/hamjam/NeMo/tree/b3484d32e1317666151f931bfa39867d88ed8658
|
ConvGLU
|
import torch
import torch.cuda
from torch import nn
import torch.distributed
import torch.utils.data
import torch.optim
def str2act(txt):
"""Translates text to neural network activation"""
return {'sigmoid': nn.Sigmoid(), 'relu': nn.ReLU(), 'none': nn.
Sequential(), 'lrelu': nn.LeakyReLU(0.2), 'selu': nn.SELU()}[txt.
lower()]
class ConvGLU(nn.Module):
"""
A convGlu operation, used by the Degli paper's model.
"""
def __init__(self, in_ch, out_ch, kernel_size=(7, 7), padding=None,
batchnorm=False, act='sigmoid', stride=None):
super().__init__()
if not padding:
padding = kernel_size[0] // 2, kernel_size[1] // 2
if stride is None:
self.conv = nn.Conv2d(in_ch, out_ch * 2, kernel_size, padding=
padding)
else:
self.conv = nn.Conv2d(in_ch, out_ch * 2, kernel_size, padding=
padding, stride=stride)
self.weight = self.conv.weight
self.bias = self.conv.bias
if batchnorm:
self.conv = nn.Sequential(self.conv, nn.BatchNorm2d(out_ch * 2))
self.sigmoid = str2act(act)
def forward(self, x):
x = self.conv(x)
ch = x.shape[1]
x = x[:, :ch // 2, ...] * self.sigmoid(x[:, ch // 2:, ...])
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_ch': 4, 'out_ch': 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.cuda
from torch import nn
import torch.distributed
import torch.utils.data
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_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 512
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 8
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, xmask)
@triton.jit
def triton_poi_fused_mul_sigmoid_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 % 64
x1 = xindex // 64
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 128 * x1), xmask)
tmp1 = tl.load(in_ptr0 + (64 + x0 + 128 * x1), xmask)
tmp2 = tl.sigmoid(tmp1)
tmp3 = tmp0 * tmp2
tl.store(out_ptr0 + x2, tmp3, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (8, 4, 7, 7), (196, 49, 7, 1))
assert_size_stride(primals_2, (8,), (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=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 8, 4, 4), (128, 16, 4, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(512)](buf1, primals_2, 512,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_2
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_mul_sigmoid_1[grid(256)](buf1, buf2, 256, XBLOCK=
256, num_warps=4, num_stages=1)
return buf2, primals_1, primals_3, buf1
def str2act(txt):
"""Translates text to neural network activation"""
return {'sigmoid': nn.Sigmoid(), 'relu': nn.ReLU(), 'none': nn.
Sequential(), 'lrelu': nn.LeakyReLU(0.2), 'selu': nn.SELU()}[txt.
lower()]
class ConvGLUNew(nn.Module):
"""
A convGlu operation, used by the Degli paper's model.
"""
def __init__(self, in_ch, out_ch, kernel_size=(7, 7), padding=None,
batchnorm=False, act='sigmoid', stride=None):
super().__init__()
if not padding:
padding = kernel_size[0] // 2, kernel_size[1] // 2
if stride is None:
self.conv = nn.Conv2d(in_ch, out_ch * 2, kernel_size, padding=
padding)
else:
self.conv = nn.Conv2d(in_ch, out_ch * 2, kernel_size, padding=
padding, stride=stride)
self.weight = self.conv.weight
self.bias = self.conv.bias
if batchnorm:
self.conv = nn.Sequential(self.conv, nn.BatchNorm2d(out_ch * 2))
self.sigmoid = str2act(act)
def forward(self, input_0):
primals_1 = self.weight
primals_2 = self.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
hamjam/NeMo
|
ConvGLU
| false
| 15,488
|
[
"Apache-2.0"
] | 4,145
|
b3484d32e1317666151f931bfa39867d88ed8658
|
https://github.com/hamjam/NeMo/tree/b3484d32e1317666151f931bfa39867d88ed8658
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.