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.utils.data
import torch
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 % 16
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tl.store(out_ptr0 + x2, tmp0, xmask)


@triton.jit
def triton_poi_fused_cat_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 512
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 8
    x1 = xindex // 8 % 16
    x2 = xindex // 128
    x3 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (4 * (x1 // 4) + 16 * x2 + x0), tmp4 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp6 = tmp0 >= tmp3
    tl.full([1], 8, tl.int64)
    tmp9 = tl.load(in_ptr1 + (4 * (x1 % 4) + 16 * x2 + (-4 + x0)), tmp6 &
        xmask, eviction_policy='evict_last', other=0.0)
    tmp10 = tl.where(tmp4, tmp5, tmp9)
    tl.store(out_ptr0 + x3, tmp10, xmask)


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


@triton.jit
def triton_poi_fused__softmax_leaky_relu_mul_where_4(in_out_ptr0, in_ptr0,
    in_ptr1, in_ptr2, in_ptr3, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask).to(tl.int1)
    tmp1 = tl.load(in_ptr1 + x2, xmask).to(tl.int1)
    tmp2 = tl.load(in_out_ptr0 + x2, xmask)
    tmp8 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
    tmp3 = 4.0
    tmp4 = tmp2 * tmp3
    tmp5 = tl.where(tmp1, tmp2, tmp4)
    tmp6 = -8999999815811072.0
    tmp7 = tl.where(tmp0, tmp5, tmp6)
    tmp9 = tmp7 - tmp8
    tmp10 = tl_math.exp(tmp9)
    tmp12 = tmp10 / tmp11
    tl.store(in_out_ptr0 + x2, tmp12, xmask)


@triton.jit
def triton_poi_fused_leaky_relu_5(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 = 0.0
    tmp2 = tmp0 > tmp1
    tmp3 = 0.01
    tmp4 = tmp0 * tmp3
    tmp5 = tl.where(tmp2, tmp0, tmp4)
    tl.store(out_ptr0 + x0, tmp2, xmask)
    tl.store(out_ptr1 + x0, 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), (4, 1))
    assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_3, (4, 4), (4, 1))
    assert_size_stride(primals_4, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_5, (8, 1), (1, 1))
    assert_size_stride(primals_6, (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_repeat_0[grid(64)](primals_1, buf0, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        del primals_1
        buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(primals_2, buf0, out=buf1)
        buf2 = buf0
        del buf0
        triton_poi_fused_repeat_0[grid(64)](primals_3, buf2, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        del primals_3
        buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(primals_4, buf2, out=buf3)
        buf4 = empty_strided_cuda((4, 16, 8), (128, 8, 1), torch.float32)
        triton_poi_fused_cat_1[grid(512)](buf1, buf3, buf4, 512, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf5 = reinterpret_tensor(buf3, (64, 1), (1, 1), 0)
        del buf3
        extern_kernels.mm(reinterpret_tensor(buf4, (64, 8), (8, 1), 0),
            primals_5, out=buf5)
        buf6 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
        triton_poi_fused_leaky_relu_2[grid(64)](buf5, buf6, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf7 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
        triton_poi_fused_leaky_relu_2[grid(64)](primals_6, buf7, 64, XBLOCK
            =64, num_warps=1, num_stages=1)
        del primals_6
        buf8 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
        buf9 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
        triton_poi_fused__softmax_leaky_relu_mul_where_3[grid(16)](buf7,
            buf6, buf5, buf8, buf9, 16, XBLOCK=16, num_warps=1, num_stages=1)
        buf10 = reinterpret_tensor(buf5, (4, 4, 4), (16, 4, 1), 0)
        del buf5
        triton_poi_fused__softmax_leaky_relu_mul_where_4[grid(64)](buf10,
            buf7, buf6, buf8, buf9, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del buf8
        del buf9
        buf11 = buf2
        del buf2
        extern_kernels.bmm(buf10, buf1, out=buf11)
        buf12 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool)
        buf13 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_leaky_relu_5[grid(64)](buf11, buf12, buf13, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        del buf11
    return buf13, buf6, buf7, buf10, buf12, reinterpret_tensor(buf1, (4, 4,
        4), (16, 1, 4), 0), reinterpret_tensor(buf4, (8, 64), (1, 8), 0
        ), reinterpret_tensor(primals_5, (1, 8), (1, 1), 0
        ), reinterpret_tensor(primals_4, (4, 4, 4), (16, 1, 4), 0
        ), reinterpret_tensor(primals_2, (4, 4, 4), (16, 1, 4), 0)


class GraphEncoderDecoderAttentionLayerNew(nn.Module):
    """
    Graph-to-Graph message passing, adapted from https://arxiv.org/abs/1710.10903
    """

    def __init__(self, in_src_features, in_tgt_features, out_features,
        dropout, alpha, concat=True):
        super(GraphEncoderDecoderAttentionLayerNew, self).__init__()
        self.dropout = dropout
        self.in_src_features = in_src_features
        self.in_tgt_features = in_tgt_features
        self.out_features = out_features
        self.alpha = alpha
        self.concat = concat
        self.Ws = nn.Parameter(torch.empty(size=(in_src_features,
            out_features)))
        self.Wt = nn.Parameter(torch.empty(size=(in_tgt_features,
            out_features)))
        nn.init.xavier_uniform_(self.Ws.data, gain=1.414)
        nn.init.xavier_uniform_(self.Wt.data, gain=1.414)
        self.a = nn.Parameter(torch.empty(size=(2 * out_features, 1)))
        nn.init.xavier_uniform_(self.a.data, gain=1.414)
        self.leakyrelu = nn.LeakyReLU(self.alpha)

    def _prepare_attentional_mechanism_input(self, Ws_ctx, Wt_h):
        Ns = Ws_ctx.size()[1]
        Nt = Wt_h.size()[1]
        Ws_ctx_repeated_in_chunks = Ws_ctx.repeat_interleave(Nt, dim=1)
        Wt_h_repeated_alternating = Wt_h.repeat([1, Ns, 1])
        all_combinations_matrix = torch.cat([Ws_ctx_repeated_in_chunks,
            Wt_h_repeated_alternating], dim=2)
        return all_combinations_matrix.view(Ws_ctx.size(0), Nt, Ns, 2 *
            self.out_features)

    def forward(self, input_0, input_1, input_2):
        primals_1 = self.Ws
        primals_3 = self.Wt
        primals_5 = self.a
        primals_2 = input_0
        primals_4 = input_1
        primals_6 = input_2
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6])
        return output[0]


Measured latency_ms: 0.122473