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 libdevice, math as tl_math
import torch.nn as nn
from torch.nn.parameter import Parameter
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_add_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 4
    x0 = xindex % 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = tmp2 > tmp3
    tl.store(out_ptr0 + x2, tmp4, xmask)


@triton.jit
def triton_poi_fused__softmax_add_gt_leaky_relu_mul_where_1(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 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last').to(tl
        .int1)
    tmp4 = tl.load(in_ptr2 + x0, xmask)
    tmp5 = tl.load(in_ptr3 + 0)
    tmp6 = tl.broadcast_to(tmp5, [XBLOCK])
    tmp13 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp15 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        ).to(tl.int1)
    tmp16 = tl.load(in_ptr3 + 1)
    tmp17 = tl.broadcast_to(tmp16, [XBLOCK])
    tmp23 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp25 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        ).to(tl.int1)
    tmp26 = tl.load(in_ptr3 + 2)
    tmp27 = tl.broadcast_to(tmp26, [XBLOCK])
    tmp33 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp35 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        ).to(tl.int1)
    tmp36 = tl.load(in_ptr3 + 3)
    tmp37 = tl.broadcast_to(tmp36, [XBLOCK])
    tmp1 = 0.0
    tmp2 = tmp0 > tmp1
    tmp7 = tmp4 + tmp6
    tmp8 = 4.0
    tmp9 = tmp7 * tmp8
    tmp10 = tl.where(tmp3, tmp7, tmp9)
    tmp11 = -8999999815811072.0
    tmp12 = tl.where(tmp2, tmp10, tmp11)
    tmp14 = tmp13 > tmp1
    tmp18 = tmp4 + tmp17
    tmp19 = tmp18 * tmp8
    tmp20 = tl.where(tmp15, tmp18, tmp19)
    tmp21 = tl.where(tmp14, tmp20, tmp11)
    tmp22 = triton_helpers.maximum(tmp12, tmp21)
    tmp24 = tmp23 > tmp1
    tmp28 = tmp4 + tmp27
    tmp29 = tmp28 * tmp8
    tmp30 = tl.where(tmp25, tmp28, tmp29)
    tmp31 = tl.where(tmp24, tmp30, tmp11)
    tmp32 = triton_helpers.maximum(tmp22, tmp31)
    tmp34 = tmp33 > tmp1
    tmp38 = tmp4 + tmp37
    tmp39 = tmp38 * tmp8
    tmp40 = tl.where(tmp35, tmp38, tmp39)
    tmp41 = tl.where(tmp34, tmp40, tmp11)
    tmp42 = triton_helpers.maximum(tmp32, tmp41)
    tl.store(out_ptr0 + x0, tmp42, xmask)


@triton.jit
def triton_poi_fused__softmax_add_gt_leaky_relu_mul_where_2(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)
    tmp3 = tl.load(in_ptr1 + x2, xmask).to(tl.int1)
    tmp4 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last')
    tmp1 = 0.0
    tmp2 = tmp0 > tmp1
    tmp6 = tmp4 + tmp5
    tmp7 = 4.0
    tmp8 = tmp6 * tmp7
    tmp9 = tl.where(tmp3, tmp6, tmp8)
    tmp10 = -8999999815811072.0
    tmp11 = tl.where(tmp2, tmp9, tmp10)
    tmp13 = tmp11 - tmp12
    tmp14 = tl_math.exp(tmp13)
    tl.store(out_ptr0 + x2, tmp14, xmask)


@triton.jit
def triton_poi_fused__softmax_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    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_elu_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask)
    tmp1 = 0.0
    tmp2 = tmp0 > tmp1
    tmp3 = 1.0
    tmp4 = tmp0 * tmp3
    tmp5 = libdevice.expm1(tmp4)
    tmp6 = tmp5 * tmp3
    tmp7 = tl.where(tmp2, tmp4, tmp6)
    tmp8 = tmp7 > tmp1
    tmp9 = tmp7 * tmp3
    tmp10 = libdevice.expm1(tmp9)
    tmp11 = tmp10 * tmp3
    tmp12 = tl.where(tmp8, tmp9, tmp11)
    tl.store(out_ptr0 + x0, tmp12, xmask)


@triton.jit
def triton_poi_fused_relu_5(in_out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_out_ptr0 + x0, xmask)
    tmp1 = tl.full([1], 0, tl.int32)
    tmp2 = triton_helpers.maximum(tmp1, tmp0)
    tl.store(in_out_ptr0 + x0, tmp2, xmask)


@triton.jit
def triton_poi_fused_add_exp_mul_6(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask)
    tmp4 = tl.load(in_ptr2 + x0, xmask)
    tmp2 = tl_math.exp(tmp1)
    tmp3 = tmp0 * 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) = 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, (8, 1), (1, 1))
    assert_size_stride(primals_5, (4, 4), (4, 1))
    assert_size_stride(primals_6, (4, 4), (4, 1))
    assert_size_stride(primals_7, (4, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_3, primals_2, out=buf0)
        del primals_2
        buf1 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        extern_kernels.mm(buf0, reinterpret_tensor(primals_4, (4, 1), (1, 1
            ), 0), out=buf1)
        buf2 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        extern_kernels.mm(buf0, reinterpret_tensor(primals_4, (4, 1), (1, 1
            ), 4), out=buf2)
        buf3 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
        get_raw_stream(0)
        triton_poi_fused_add_leaky_relu_0[grid(16)](buf1, buf2, buf3, 16,
            XBLOCK=16, num_warps=1, num_stages=1)
        buf4 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        triton_poi_fused__softmax_add_gt_leaky_relu_mul_where_1[grid(4)](
            primals_1, buf3, buf1, buf2, buf4, 4, XBLOCK=4, num_warps=1,
            num_stages=1)
        buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused__softmax_add_gt_leaky_relu_mul_where_2[grid(16)](
            primals_1, buf3, buf1, buf2, buf4, buf5, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        del buf1
        del buf2
        del buf4
        buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused__softmax_3[grid(16)](buf5, buf6, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        buf7 = buf5
        del buf5
        extern_kernels.mm(buf6, buf0, out=buf7)
        buf8 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused_elu_4[grid(16)](buf7, buf8, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        buf9 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(buf8, primals_5, out=buf9)
        buf10 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_1, buf9, out=buf10)
        buf11 = buf10
        del buf10
        triton_poi_fused_relu_5[grid(16)](buf11, 16, XBLOCK=16, num_warps=1,
            num_stages=1)
        buf12 = buf9
        del buf9
        extern_kernels.mm(buf11, primals_6, out=buf12)
        buf13 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_1, buf12, out=buf13)
        buf14 = buf12
        del buf12
        extern_kernels.mm(buf11, primals_7, out=buf14)
        buf15 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(primals_1, buf14, out=buf15)
        buf16 = torch.ops.aten.randn.default([4, 4], dtype=torch.float32,
            device=device(type='cuda', index=0), pin_memory=False)
        buf17 = buf16
        del buf16
        buf18 = buf14
        del buf14
        triton_poi_fused_add_exp_mul_6[grid(16)](buf17, buf15, buf13, buf18,
            16, XBLOCK=16, num_warps=1, num_stages=1)
        buf19 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(buf18, reinterpret_tensor(buf18, (4, 4), (1, 4), 
            0), out=buf19)
    return (buf19, buf13, buf15, primals_1, buf3, buf6, buf7, buf11, buf15,
        buf17, buf18, reinterpret_tensor(primals_7, (4, 4), (1, 4), 0),
        reinterpret_tensor(primals_6, (4, 4), (1, 4), 0),
        reinterpret_tensor(buf8, (4, 4), (1, 4), 0), reinterpret_tensor(
        primals_5, (4, 4), (1, 4), 0), reinterpret_tensor(buf0, (4, 4), (1,
        4), 0), reinterpret_tensor(primals_4, (1, 4), (1, 1), 4),
        reinterpret_tensor(primals_4, (1, 4), (1, 1), 0),
        reinterpret_tensor(primals_3, (4, 4), (1, 4), 0))


class GraphConvolution(nn.Module):

    def __init__(self, input_dim, output_dim, dropout, bias=False):
        super(GraphConvolution, self).__init__()
        self.input_dim = input_dim
        self.output_dim = output_dim
        self.weight = Parameter(torch.FloatTensor(input_dim, output_dim))
        self.reset_parameters()
        if bias:
            self.bias = Parameter(torch.FloatTensor(output_dim))
            nn.init.zeros_(self.bias)
        else:
            self.register_parameter('bias', None)
        self.dropout = nn.Dropout(dropout)

    def reset_parameters(self):
        nn.init.xavier_uniform_(self.weight)

    def forward(self, input, adj):
        input = self.dropout(input)
        support = torch.mm(input, self.weight)
        output = torch.spmm(adj, support)
        if self.bias is not None:
            output = output + self.bias
        return output


class InnerProductDecoder(nn.Module):
    """
    内积用来做decoder，用来生成邻接矩阵
    """

    def __init__(self, dropout):
        super(InnerProductDecoder, self).__init__()
        self.dropout = nn.Dropout(dropout)

    def forward(self, z):
        z = self.dropout(z)
        adj = torch.mm(z, z.t())
        return adj


class GraphAttentionLayer(nn.Module):

    def __init__(self, input_dim, output_dim, dropout, alpha):
        super(GraphAttentionLayer, self).__init__()
        self.input_dim = input_dim
        self.output_dim = output_dim
        self.weight = Parameter(torch.FloatTensor(input_dim, output_dim))
        self.a = Parameter(torch.FloatTensor(2 * output_dim, 1))
        self.reset_parameters()
        self.dropout = nn.Dropout(dropout)
        self.leakyrelu = nn.LeakyReLU(alpha)
        self.elu = nn.ELU()

    def reset_parameters(self):
        nn.init.xavier_uniform_(self.weight)
        nn.init.xavier_normal_(self.a)

    def forward(self, input, adj):
        Wh = torch.mm(input, self.weight)
        Wh1 = torch.matmul(Wh, self.a[:self.output_dim, :])
        Wh2 = torch.matmul(Wh, self.a[self.output_dim:, :])
        e = Wh1 + Wh2.T
        e = self.leakyrelu(e)
        zero_vec = -9000000000000000.0 * torch.ones_like(e)
        attention = torch.where(adj > 0, e, zero_vec)
        attention = F.softmax(attention, dim=-1)
        attention = self.dropout(attention)
        attention_wh = torch.matmul(attention, Wh)
        return self.elu(attention_wh)


class GATModelVAENew(nn.Module):

    def __init__(self, input_feat_dim, hidden_dim1, hidden_dim2,
        hidden_dim3, dropout, alpha, vae_bool=True):
        super(GATModelVAENew, self).__init__()
        self.vae_bool = vae_bool
        self.gc_att = GraphAttentionLayer(input_feat_dim, hidden_dim1,
            dropout, alpha)
        self.gc1 = GraphConvolution(hidden_dim1, hidden_dim2, dropout)
        self.gc2 = GraphConvolution(hidden_dim2, hidden_dim3, dropout)
        self.gc3 = GraphConvolution(hidden_dim2, hidden_dim3, dropout)
        self.ip = InnerProductDecoder(dropout)
        self.elu = nn.ELU()
        self.relu = nn.ReLU()

    def encode(self, input, adj):
        gc_att = self.elu(self.gc_att(input, adj.to_dense()))
        hidden1 = self.relu(self.gc1(gc_att, adj))
        return self.gc2(hidden1, adj), self.gc3(hidden1, adj)

    def reparameterize(self, mu, logvar):
        if self.vae_bool:
            std = torch.exp(logvar)
            eps = torch.randn_like(std)
            return eps.mul(std).add_(mu)
        else:
            return mu

    def forward(self, input_0, input_1):
        primals_1 = self.gc_att.weight
        primals_4 = self.gc_att.a
        primals_2 = self.gc1.weight
        primals_3 = self.gc2.weight
        primals_5 = self.gc3.weight
        primals_6 = input_0
        primals_7 = input_1
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7])
        return output[0], output[1], output[2]


Measured latency_ms: 0.114471