import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language 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.utils import weight_norm
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_per_fused__weight_norm_interface_0(in_out_ptr0, in_ptr0, in_ptr1,
    out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 4
    rnumel = 12
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    rmask = rindex < rnumel
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + 12 * x0), rmask & 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(rmask & 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 + 12 * x0), tmp9, rmask & xmask)


@triton.jit
def triton_poi_fused_copy_1(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 = x0
    tmp1 = tl.full([1], 5, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = -4 + x0
    tmp4 = tl.full([1], 1, tl.int64)
    tmp5 = tmp3 < tmp4
    tmp6 = tmp5 & tmp2
    tmp7 = tmp0 >= tmp4
    tmp8 = tmp0 < tmp1
    tmp9 = tmp7 & tmp8
    tmp10 = tmp9 & tmp6
    tmp11 = tl.load(in_ptr0 + (-1 + x0 + 4 * x1), tmp10 & xmask, other=0.0)
    tmp12 = float('nan')
    tmp13 = tl.where(tmp9, tmp11, tmp12)
    tmp14 = tl.full(tmp13.shape, 0.0, tmp13.dtype)
    tmp15 = tl.where(tmp6, tmp13, tmp14)
    tmp16 = tmp3 >= tmp4
    tmp17 = tmp3 < tmp1
    tmp18 = tmp16 & tmp17
    tmp19 = tmp18 & tmp2
    tmp20 = tl.load(in_ptr0 + (-5 + x0 + 4 * x1), tmp19 & xmask, other=0.0)
    tmp21 = tl.where(tmp18, tmp20, tmp12)
    tmp22 = tl.where(tmp5, tmp15, tmp21)
    tmp23 = tl.full(tmp22.shape, 0.0, tmp22.dtype)
    tmp24 = tl.where(tmp2, tmp22, tmp23)
    tmp25 = tmp0 < tmp4
    tmp26 = 4 + x0
    tmp27 = tmp26 >= tmp4
    tmp28 = tmp26 < tmp1
    tmp29 = tmp27 & tmp28
    tmp30 = tmp29 & tmp25
    tmp31 = tl.load(in_ptr0 + (3 + x0 + 4 * x1), tmp30 & xmask, other=0.0)
    tmp32 = tl.where(tmp29, tmp31, tmp12)
    tmp33 = tl.full(tmp32.shape, 0.0, tmp32.dtype)
    tmp34 = tl.where(tmp25, tmp32, tmp33)
    tmp35 = tl.load(in_ptr0 + (-1 + x0 + 4 * x1), tmp9 & xmask, other=0.0)
    tmp36 = tl.where(tmp9, tmp35, tmp12)
    tmp37 = tl.where(tmp25, tmp34, tmp36)
    tmp38 = tl.where(tmp2, tmp24, tmp37)
    tl.store(out_ptr0 + x2, tmp38, xmask)


@triton.jit
def triton_poi_fused_copy_2(in_ptr0, in_ptr1, 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 = x0
    tmp1 = tl.full([1], 5, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = -4 + x0
    tmp4 = tl.full([1], 1, tl.int64)
    tmp5 = tmp3 < tmp4
    tmp6 = tmp5 & tmp2
    tmp7 = tmp0 >= tmp4
    tmp8 = tmp0 < tmp1
    tmp9 = tmp7 & tmp8
    tmp10 = tmp9 & tmp6
    tmp11 = tl.load(in_ptr0 + (-1 + x0 + 4 * x1), tmp10 & xmask, other=0.0)
    tmp12 = tl.load(in_ptr1 + x1, tmp10 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp13 = tmp11 + tmp12
    tmp14 = tl.full([1], 0, tl.int32)
    tmp15 = triton_helpers.maximum(tmp14, tmp13)
    tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype)
    tmp17 = tl.where(tmp10, tmp15, tmp16)
    tmp18 = float('nan')
    tmp19 = tl.where(tmp9, tmp17, tmp18)
    tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype)
    tmp21 = tl.where(tmp6, tmp19, tmp20)
    tmp22 = tmp3 >= tmp4
    tmp23 = tmp3 < tmp1
    tmp24 = tmp22 & tmp23
    tmp25 = tmp24 & tmp2
    tmp26 = tl.load(in_ptr0 + (-5 + x0 + 4 * x1), tmp25 & xmask, other=0.0)
    tmp27 = tl.load(in_ptr1 + x1, tmp25 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp28 = tmp26 + tmp27
    tmp29 = triton_helpers.maximum(tmp14, tmp28)
    tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype)
    tmp31 = tl.where(tmp25, tmp29, tmp30)
    tmp32 = tl.where(tmp24, tmp31, tmp18)
    tmp33 = tl.where(tmp5, tmp21, tmp32)
    tmp34 = tl.full(tmp33.shape, 0.0, tmp33.dtype)
    tmp35 = tl.where(tmp2, tmp33, tmp34)
    tmp36 = tmp0 < tmp4
    tmp37 = 4 + x0
    tmp38 = tmp37 >= tmp4
    tmp39 = tmp37 < tmp1
    tmp40 = tmp38 & tmp39
    tmp41 = tmp40 & tmp36
    tmp42 = tl.load(in_ptr0 + (3 + x0 + 4 * x1), tmp41 & xmask, other=0.0)
    tmp43 = tl.load(in_ptr1 + x1, tmp41 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp44 = tmp42 + tmp43
    tmp45 = triton_helpers.maximum(tmp14, tmp44)
    tmp46 = tl.full(tmp45.shape, 0.0, tmp45.dtype)
    tmp47 = tl.where(tmp41, tmp45, tmp46)
    tmp48 = tl.where(tmp40, tmp47, tmp18)
    tmp49 = tl.full(tmp48.shape, 0.0, tmp48.dtype)
    tmp50 = tl.where(tmp36, tmp48, tmp49)
    tmp51 = tl.load(in_ptr0 + (-1 + x0 + 4 * x1), tmp9 & xmask, other=0.0)
    tmp52 = tl.load(in_ptr1 + x1, tmp9 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp53 = tmp51 + tmp52
    tmp54 = triton_helpers.maximum(tmp14, tmp53)
    tmp55 = tl.full(tmp54.shape, 0.0, tmp54.dtype)
    tmp56 = tl.where(tmp9, tmp54, tmp55)
    tmp57 = tl.where(tmp9, tmp56, tmp18)
    tmp58 = tl.where(tmp36, tmp50, tmp57)
    tmp59 = tl.where(tmp2, tmp35, tmp58)
    tl.store(out_ptr0 + x2, tmp59, xmask)


@triton.jit
def triton_poi_fused_add_relu_threshold_backward_3(in_ptr0, in_ptr1,
    in_ptr2, out_ptr0, out_ptr1, out_ptr2, xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr2 + x2, xmask)
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp6 = tmp4 + tmp5
    tmp7 = triton_helpers.maximum(tmp3, tmp6)
    tmp8 = 0.0
    tmp9 = tmp4 <= tmp8
    tmp10 = tmp7 <= tmp8
    tl.store(out_ptr0 + x2, tmp7, xmask)
    tl.store(out_ptr1 + x2, tmp9, xmask)
    tl.store(out_ptr2 + x2, tmp10, xmask)


@triton.jit
def triton_poi_fused_relu_threshold_backward_4(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 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp5 = 0.0
    tmp6 = tmp4 <= tmp5
    tl.store(out_ptr0 + x2, tmp6, xmask)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7) = args
    args.clear()
    assert_size_stride(primals_1, (4, 1, 1), (1, 1, 1))
    assert_size_stride(primals_2, (4, 4, 3), (12, 3, 1))
    assert_size_stride(primals_3, (4,), (1,))
    assert_size_stride(primals_4, (4, 4), (4, 1))
    assert_size_stride(primals_5, (4, 1, 1), (1, 1, 1))
    assert_size_stride(primals_6, (4, 4, 3), (12, 3, 1))
    assert_size_stride(primals_7, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 1, 1), (1, 4, 4), torch.float32)
        buf1 = reinterpret_tensor(buf0, (4, 1, 1), (1, 1, 1), 0)
        del buf0
        buf2 = empty_strided_cuda((4, 4, 3), (12, 3, 1), torch.float32)
        get_raw_stream(0)
        triton_per_fused__weight_norm_interface_0[grid(4)](buf1, primals_2,
            primals_1, buf2, 4, 12, XBLOCK=1, num_warps=2, num_stages=1)
        buf4 = empty_strided_cuda((4, 6), (6, 1), torch.float32)
        triton_poi_fused_copy_1[grid(24)](primals_4, buf4, 24, XBLOCK=32,
            num_warps=1, num_stages=1)
        buf5 = extern_kernels.convolution(reinterpret_tensor(buf4, (1, 4, 6
            ), (24, 6, 1), 0), buf2, stride=(1,), padding=(0,), dilation=(1
            ,), transposed=False, output_padding=(0,), groups=1, bias=None)
        assert_size_stride(buf5, (1, 4, 4), (16, 4, 1))
        buf6 = empty_strided_cuda((4, 1, 1), (1, 4, 4), torch.float32)
        buf7 = reinterpret_tensor(buf6, (4, 1, 1), (1, 1, 1), 0)
        del buf6
        buf8 = empty_strided_cuda((4, 4, 3), (12, 3, 1), torch.float32)
        triton_per_fused__weight_norm_interface_0[grid(4)](buf7, primals_6,
            primals_5, buf8, 4, 12, XBLOCK=1, num_warps=2, num_stages=1)
        buf10 = empty_strided_cuda((4, 6), (6, 1), torch.float32)
        triton_poi_fused_copy_2[grid(24)](buf5, primals_3, buf10, 24,
            XBLOCK=32, num_warps=1, num_stages=1)
        buf11 = extern_kernels.convolution(reinterpret_tensor(buf10, (1, 4,
            6), (24, 6, 1), 0), buf8, stride=(1,), padding=(0,), dilation=(
            1,), transposed=False, output_padding=(0,), groups=1, bias=None)
        assert_size_stride(buf11, (1, 4, 4), (16, 4, 1))
        buf12 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf14 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        buf13 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        triton_poi_fused_add_relu_threshold_backward_3[grid(16)](buf11,
            primals_7, primals_4, buf12, buf14, buf13, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        del buf11
        del primals_4
        del primals_7
        buf15 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        triton_poi_fused_relu_threshold_backward_4[grid(16)](buf5,
            primals_3, buf15, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del buf5
        del primals_3
    return (buf12, buf2, buf8, primals_1, primals_2, primals_5, primals_6,
        buf1, buf2, reinterpret_tensor(buf4, (1, 4, 6), (24, 6, 1), 0),
        buf7, buf8, reinterpret_tensor(buf10, (1, 4, 6), (24, 6, 1), 0),
        buf13, buf14, buf15)


class TemporalBlockNew(nn.Module):

    def __init__(self, n_inputs, n_outputs, kernel_size=3, stride=1,
        dilation=1, padding=1, dropout=0.2):
        super(TemporalBlockNew, self).__init__()
        self.conv1 = weight_norm(nn.Conv1d(n_inputs, n_outputs, kernel_size,
            stride=stride, padding=padding, dilation=dilation, padding_mode
            ='circular'))
        self.relu1 = nn.ReLU()
        self.dropout1 = nn.Dropout(dropout)
        self.conv2 = weight_norm(nn.Conv1d(n_outputs, n_outputs,
            kernel_size, stride=stride, padding=padding, dilation=dilation,
            padding_mode='circular'))
        self.relu2 = nn.ReLU()
        self.dropout2 = nn.Dropout(dropout)
        self.net = nn.Sequential(self.conv1, self.relu1, self.dropout1,
            self.conv2, self.relu2, self.dropout2)
        self.downsample = nn.Conv1d(n_inputs, n_outputs, 1
            ) if n_inputs != n_outputs else None
        self.relu = nn.ReLU()
        self.init_weights()

    def init_weights(self):
        for m in self.modules():
            if isinstance(m, nn.Conv1d):
                nn.init.kaiming_normal_(m.weight, mode='fan_in',
                    nonlinearity='leaky_relu')

    def forward(self, input_0):
        primals_3 = self.conv1.bias
        primals_1 = self.conv1.weight_g
        primals_2 = self.conv1.weight_v
        primals_7 = self.conv2.bias
        primals_5 = self.conv2.weight_g
        primals_6 = self.conv2.weight_v
        primals_4 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7])
        return output[0]


Measured latency_ms: 0.036395