import torch
from torch import device
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_poi_fused_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 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)
    tl.store(in_out_ptr0 + x2, tmp4, xmask)


@triton.jit
def triton_poi_fused_add_exp_mul_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask)
    tmp6 = tl.load(in_ptr2 + x0, xmask)
    tmp2 = 0.5
    tmp3 = tmp1 * tmp2
    tmp4 = tl_math.exp(tmp3)
    tmp5 = tmp0 * tmp4
    tmp7 = tmp5 + tmp6
    tl.store(out_ptr0 + x0, tmp7, xmask)


@triton.jit
def triton_poi_fused_leaky_relu_2(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = tmp2 > tmp3
    tmp5 = 0.2
    tmp6 = tmp2 * tmp5
    tmp7 = tl.where(tmp4, tmp2, tmp6)
    tl.store(out_ptr0 + x2, tmp4, xmask)
    tl.store(out_ptr1 + x2, tmp7, xmask)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
        primals_13, primals_14, primals_15, primals_16, primals_17,
        primals_18, primals_19) = args
    args.clear()
    assert_size_stride(primals_1, (4, 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, 1))
    assert_size_stride(primals_7, (4,), (1,))
    assert_size_stride(primals_8, (4, 4), (4, 1))
    assert_size_stride(primals_9, (4,), (1,))
    assert_size_stride(primals_10, (4, 4), (4, 1))
    assert_size_stride(primals_11, (4,), (1,))
    assert_size_stride(primals_12, (4, 4), (4, 1))
    assert_size_stride(primals_13, (4,), (1,))
    assert_size_stride(primals_14, (4, 4), (4, 1))
    assert_size_stride(primals_15, (4,), (1,))
    assert_size_stride(primals_16, (4, 4), (4, 1))
    assert_size_stride(primals_17, (4,), (1,))
    assert_size_stride(primals_18, (4, 4), (4, 1))
    assert_size_stride(primals_19, (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 = buf0
        del buf0
        get_raw_stream(0)
        triton_poi_fused_relu_0[grid(256)](buf1, primals_3, 256, XBLOCK=256,
            num_warps=4, num_stages=1)
        del primals_3
        buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.mm(buf1, reinterpret_tensor(primals_4, (4, 4), (1, 4
            ), 0), out=buf2)
        buf3 = buf2
        del buf2
        triton_poi_fused_relu_0[grid(256)](buf3, primals_5, 256, XBLOCK=256,
            num_warps=4, num_stages=1)
        del primals_5
        buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.mm(buf3, reinterpret_tensor(primals_6, (4, 4), (1, 4
            ), 0), out=buf4)
        buf5 = buf4
        del buf4
        triton_poi_fused_relu_0[grid(256)](buf5, primals_7, 256, XBLOCK=256,
            num_warps=4, num_stages=1)
        del primals_7
        buf6 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_9, buf5, reinterpret_tensor(primals_8,
            (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf6)
        del primals_9
        buf7 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_11, buf5, reinterpret_tensor(
            primals_10, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf7)
        del primals_11
        buf8 = torch.ops.aten.randn.default([64, 4], dtype=torch.float32,
            device=device(type='cuda', index=0), pin_memory=False)
        buf9 = buf8
        del buf8
        buf10 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        triton_poi_fused_add_exp_mul_1[grid(256)](buf9, buf7, buf6, buf10, 
            256, XBLOCK=256, num_warps=4, num_stages=1)
        buf11 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        extern_kernels.mm(buf10, reinterpret_tensor(primals_12, (4, 4), (1,
            4), 0), out=buf11)
        buf12 = empty_strided_cuda((64, 4), (4, 1), torch.bool)
        buf13 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        triton_poi_fused_leaky_relu_2[grid(256)](buf11, primals_13, buf12,
            buf13, 256, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_13
        buf14 = buf11
        del buf11
        extern_kernels.mm(buf13, reinterpret_tensor(primals_14, (4, 4), (1,
            4), 0), out=buf14)
        buf15 = empty_strided_cuda((64, 4), (4, 1), torch.bool)
        buf16 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        triton_poi_fused_leaky_relu_2[grid(256)](buf14, primals_15, buf15,
            buf16, 256, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_15
        buf17 = buf14
        del buf14
        extern_kernels.mm(buf16, reinterpret_tensor(primals_16, (4, 4), (1,
            4), 0), out=buf17)
        buf18 = empty_strided_cuda((64, 4), (4, 1), torch.bool)
        buf19 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        triton_poi_fused_leaky_relu_2[grid(256)](buf17, primals_17, buf18,
            buf19, 256, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_17
        buf20 = buf17
        del buf17
        extern_kernels.mm(buf19, reinterpret_tensor(primals_18, (4, 4), (1,
            4), 0), out=buf20)
        buf21 = empty_strided_cuda((64, 4), (4, 1), torch.bool)
        buf22 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
        triton_poi_fused_leaky_relu_2[grid(256)](buf20, primals_19, buf21,
            buf22, 256, XBLOCK=256, num_warps=4, num_stages=1)
        del buf20
        del primals_19
    return (buf22, buf6, buf7, reinterpret_tensor(primals_1, (64, 4), (4, 1
        ), 0), buf1, buf3, buf5, buf7, buf9, buf10, buf12, buf13, buf15,
        buf16, buf18, buf19, buf21, primals_18, primals_16, primals_14,
        primals_12, primals_10, primals_8, primals_6, primals_4)


class VAENew(nn.Module):

    def __init__(self, x_dim, h_dim1, h_dim2, h_dim3, z_dim):
        super(VAENew, self).__init__()
        self.x_dim = x_dim
        self.fc1 = nn.Linear(x_dim, h_dim1)
        self.fc2 = nn.Linear(h_dim1, h_dim2)
        self.fc3 = nn.Linear(h_dim2, h_dim3)
        self.fc31 = nn.Linear(h_dim3, z_dim)
        self.fc32 = nn.Linear(h_dim3, z_dim)
        self.dropout = nn.Dropout(0.5)
        self.Encoder = nn.Sequential(self.fc1, nn.Dropout(0.2), nn.ReLU(),
            self.fc2, nn.Dropout(0.2), nn.ReLU(), self.fc3, nn.Dropout(0.2),
            nn.ReLU())
        self.fc4 = nn.Linear(z_dim, h_dim3)
        self.fc5 = nn.Linear(h_dim3, h_dim2)
        self.fc6 = nn.Linear(h_dim2, h_dim1)
        self.fc7 = nn.Linear(h_dim1, x_dim)
        self.Decoder = nn.Sequential(self.fc4, nn.Dropout(0.2), nn.
            LeakyReLU(negative_slope=0.2), self.fc5, nn.Dropout(0.2), nn.
            LeakyReLU(negative_slope=0.2), self.fc6, nn.Dropout(0.2), nn.
            LeakyReLU(negative_slope=0.2), self.fc7, nn.Dropout(0.2), nn.
            LeakyReLU(negative_slope=0.2))

    def encode(self, x):
        h = self.Encoder(x)
        return self.fc31(h), self.fc32(h)

    def sampling(self, mu, log_var):
        std = torch.exp(0.5 * log_var)
        eps = torch.randn_like(std)
        return eps.mul(std).add_(mu)

    def decode(self, z):
        output = self.Decoder(z)
        return output

    def forward(self, input_0):
        primals_2 = self.fc1.weight
        primals_3 = self.fc1.bias
        primals_4 = self.fc2.weight
        primals_5 = self.fc2.bias
        primals_6 = self.fc3.weight
        primals_7 = self.fc3.bias
        primals_8 = self.fc31.weight
        primals_9 = self.fc31.bias
        primals_10 = self.fc32.weight
        primals_11 = self.fc32.bias
        primals_12 = self.fc4.weight
        primals_13 = self.fc4.bias
        primals_14 = self.fc5.weight
        primals_15 = self.fc5.bias
        primals_16 = self.fc6.weight
        primals_17 = self.fc6.bias
        primals_18 = self.fc7.weight
        primals_19 = self.fc7.bias
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9,
            primals_10, primals_11, primals_12, primals_13, primals_14,
            primals_15, primals_16, primals_17, primals_18, primals_19])
        return output[0], output[1], output[2]


Measured latency_ms: 0.196857