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_mean_0(in_ptr0, out_ptr0, out_ptr1, 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
    y3 = yindex
    y0 = yindex % 4
    y1 = yindex // 4
    tmp0 = tl.load(in_ptr0 + (x2 + 4 * y3), xmask & ymask, eviction_policy=
        'evict_last')
    tmp1 = tl.load(in_ptr0 + (64 + x2 + 4 * y3), xmask & ymask,
        eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (128 + x2 + 4 * y3), xmask & ymask,
        eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (192 + x2 + 4 * y3), xmask & ymask,
        eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp6 = tmp4 + tmp5
    tmp7 = 4.0
    tmp8 = tmp6 / tmp7
    tmp9 = tl.sigmoid(tmp8)
    tl.store(out_ptr0 + (y0 + 4 * x2 + 16 * y1), tmp9, xmask & ymask)
    tl.store(out_ptr1 + (x2 + 4 * y3), tmp8, xmask & ymask)


@triton.jit
def triton_poi_fused_clone_1(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)
    tl.store(in_out_ptr0 + x0, tmp0, xmask)


@triton.jit
def triton_poi_fused_mean_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 = 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
    tl.store(out_ptr0 + x0, tmp8, xmask)


@triton.jit
def triton_per_fused_add_binary_cross_entropy_with_logits_3(in_out_ptr0,
    in_ptr0, in_ptr1, 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)
    tmp13 = tl.load(in_ptr1 + r0, None)
    tmp1 = 0.0
    tmp2 = tmp1 * tmp0
    tmp3 = triton_helpers.minimum(tmp1, tmp0)
    tmp4 = tl_math.abs(tmp0)
    tmp5 = -tmp4
    tmp6 = tl_math.exp(tmp5)
    tmp7 = libdevice.log1p(tmp6)
    tmp8 = tmp3 - tmp7
    tmp9 = tmp2 - tmp8
    tmp10 = tl.broadcast_to(tmp9, [XBLOCK, RBLOCK])
    tmp12 = tl.sum(tmp10, 1)[:, None]
    tmp14 = triton_helpers.minimum(tmp1, tmp13)
    tmp15 = tl_math.abs(tmp13)
    tmp16 = -tmp15
    tmp17 = tl_math.exp(tmp16)
    tmp18 = libdevice.log1p(tmp17)
    tmp19 = tmp14 - tmp18
    tmp20 = tmp13 - tmp19
    tmp21 = tl.broadcast_to(tmp20, [XBLOCK, RBLOCK])
    tmp23 = tl.sum(tmp21, 1)[:, None]
    tmp24 = 64.0
    tmp25 = tmp12 / tmp24
    tmp26 = tmp25 + tmp1
    tmp27 = tmp23 / tmp24
    tmp28 = tmp27 + tmp1
    tmp29 = tmp26 + tmp28
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp29, 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, 4), (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, 4), (16, 4, 1), torch.float32)
        buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_clone_mean_0[grid(16, 4)](primals_1, buf0, buf2, 
            16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1)
        del primals_1
        buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf0, (16, 4), (4, 1), 0),
            reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf1)
        del primals_2
        buf3 = reinterpret_tensor(buf1, (4, 4, 4), (16, 1, 4), 0)
        del buf1
        triton_poi_fused_clone_1[grid(64)](buf3, 64, XBLOCK=64, num_warps=1,
            num_stages=1)
        buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(buf2, buf3, out=buf4)
        buf5 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_mean_2[grid(64)](primals_3, buf5, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        del primals_3
        buf6 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(buf5, buf3, out=buf6)
        del buf3
        buf7 = empty_strided_cuda((), (), torch.float32)
        buf9 = buf7
        del buf7
        triton_per_fused_add_binary_cross_entropy_with_logits_3[grid(1)](buf9,
            buf4, buf6, 1, 64, XBLOCK=1, num_warps=2, num_stages=1)
    return buf9, reinterpret_tensor(buf0, (16, 4), (4, 1), 0
        ), buf4, buf6, reinterpret_tensor(buf5, (4, 4, 4), (16, 1, 4), 0
        ), reinterpret_tensor(buf2, (4, 4, 4), (16, 1, 4), 0)


class Discriminator(nn.Module):

    def __init__(self, n_hidden):
        super(Discriminator, self).__init__()
        self.weight = nn.Parameter(torch.Tensor(n_hidden, n_hidden))
        self.reset_parameters()

    def uniform(self, size, tensor):
        bound = 1.0 / math.sqrt(size)
        if tensor is not None:
            tensor.data.uniform_(-bound, bound)

    def reset_parameters(self):
        size = self.weight.size(0)
        self.uniform(size, self.weight)

    def forward(self, features, summary):
        features = torch.matmul(features, torch.matmul(self.weight, summary))
        return features


class MutualInformationDiscriminatorHomoNew(nn.Module):

    def __init__(self, n_hidden, average_across_node_types=True,
        convex_combination_weight=None):
        super(MutualInformationDiscriminatorHomoNew, self).__init__()
        self.discriminator = Discriminator(n_hidden)
        self.loss = nn.BCEWithLogitsLoss()
        self.average_across_node_types = average_across_node_types
        self.convex_combination_weight = convex_combination_weight
        self.global_summary = None

    def forward(self, input_0, input_1):
        primals_2 = self.discriminator.weight
        primals_1 = input_0
        primals_3 = input_1
        output = call([primals_1, primals_2, primals_3])
        return output[0]


Measured latency_ms: 0.078369