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.nn as nn
import torch.nn.parallel
import torch.utils.data
import torch.distributions
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_cat_0(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 4 % 4
    x0 = xindex % 4
    x2 = xindex // 16
    x3 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 1, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x0 + 4 * x2), tmp4 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp6 = tmp0 >= tmp3
    tmp7 = tl.full([1], 2, tl.int64)
    tmp8 = tmp0 < tmp7
    tmp9 = tmp6 & tmp8
    tmp10 = tl.load(in_ptr1 + (x0 + 4 * x2), tmp9 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp11 = tmp0 >= tmp7
    tmp12 = tl.full([1], 3, tl.int64)
    tmp13 = tmp0 < tmp12
    tmp14 = tmp11 & tmp13
    tmp15 = tl.load(in_ptr2 + (x0 + 4 * x2), tmp14 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp16 = tmp0 >= tmp12
    tl.full([1], 4, tl.int64)
    tmp19 = tl.load(in_ptr3 + (x0 + 4 * x2), tmp16 & xmask, eviction_policy
        ='evict_last', other=0.0)
    tmp20 = tl.where(tmp14, tmp15, tmp19)
    tmp21 = tl.where(tmp9, tmp10, tmp20)
    tmp22 = tl.where(tmp4, tmp5, tmp21)
    tl.store(out_ptr0 + x3, tmp22, xmask)


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


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


@triton.jit
def triton_per_fused__log_softmax_3(in_ptr0, out_ptr2, xnumel, rnumel,
    XBLOCK: tl.constexpr):
    xnumel = 4
    rnumel = 100
    RBLOCK: tl.constexpr = 128
    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 + 100 * x0), rmask & xmask, other=0.0)
    tmp1 = 1.0
    tmp2 = tmp0 * tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.where(rmask & xmask, tmp3, float('-inf'))
    tmp6 = triton_helpers.max2(tmp5, 1)[:, None]
    tmp7 = tmp2 - tmp6
    tmp8 = tmp7 * tmp1
    tmp9 = tl_math.exp(tmp8)
    tmp10 = tl.broadcast_to(tmp9, [XBLOCK, RBLOCK])
    tmp12 = tl.where(rmask & xmask, tmp10, 0)
    tmp13 = tl.sum(tmp12, 1)[:, None]
    tmp14 = tl_math.log(tmp13)
    tmp15 = tmp8 - tmp14
    tl.store(out_ptr2 + (r1 + 100 * x0), tmp15, rmask & xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    assert_size_stride(primals_3, (4, 1, 4, 1), (4, 4, 1, 1))
    assert_size_stride(primals_4, (1, 1, 4, 1), (4, 4, 1, 1))
    assert_size_stride(primals_5, (100, 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(reinterpret_tensor(primals_1, (4, 4), (4, 1), 0),
            reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0)
        buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(primals_1, (4, 4), (4, 1), 16),
            reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf1)
        buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(primals_1, (4, 4), (4, 1), 32),
            reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf2)
        buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(primals_1, (4, 4), (4, 1), 48),
            reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf3)
        del primals_2
        buf4 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_cat_0[grid(64)](buf0, buf1, buf2, buf3, buf4, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        del buf0
        del buf1
        del buf2
        del buf3
        buf5 = extern_kernels.convolution(buf4, primals_3, stride=(4, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf5, (4, 4, 1, 4), (16, 4, 4, 1))
        buf6 = buf5
        del buf5
        triton_poi_fused_sigmoid_1[grid(64)](buf6, 64, XBLOCK=64, num_warps
            =1, num_stages=1)
        buf7 = extern_kernels.convolution(reinterpret_tensor(buf6, (4, 1, 4,
            4), (16, 4, 4, 1), 0), primals_4, stride=(4, 1), padding=(0, 0),
            dilation=(1, 1), transposed=False, output_padding=(0, 0),
            groups=1, bias=None)
        assert_size_stride(buf7, (4, 1, 1, 4), (4, 4, 4, 1))
        buf8 = buf7
        del buf7
        triton_poi_fused_sigmoid_2[grid(16)](buf8, 16, XBLOCK=16, num_warps
            =1, num_stages=1)
        buf9 = empty_strided_cuda((4, 100), (100, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf8, (4, 4), (4, 1), 0),
            reinterpret_tensor(primals_5, (4, 100), (1, 4), 0), out=buf9)
        buf12 = empty_strided_cuda((4, 100), (100, 1), torch.float32)
        triton_per_fused__log_softmax_3[grid(4)](buf9, buf12, 4, 100,
            XBLOCK=1, num_warps=2, num_stages=1)
        del buf9
    return buf12, primals_3, primals_4, reinterpret_tensor(primals_1, (4, 4
        ), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (4, 1), 16
        ), reinterpret_tensor(primals_1, (4, 4), (4, 1), 32
        ), reinterpret_tensor(primals_1, (4, 4), (4, 1), 48
        ), buf4, buf6, buf8, buf12, primals_5


class InformedSenderNew(nn.Module):

    def __init__(self, game_size, feat_size, embedding_size, hidden_size,
        vocab_size=100, temp=1.0):
        super(InformedSenderNew, self).__init__()
        self.game_size = game_size
        self.embedding_size = embedding_size
        self.hidden_size = hidden_size
        self.vocab_size = vocab_size
        self.temp = temp
        self.lin1 = nn.Linear(feat_size, embedding_size, bias=False)
        self.conv2 = nn.Conv2d(1, hidden_size, kernel_size=(game_size, 1),
            stride=(game_size, 1), bias=False)
        self.conv3 = nn.Conv2d(1, 1, kernel_size=(hidden_size, 1), stride=(
            hidden_size, 1), bias=False)
        self.lin4 = nn.Linear(embedding_size, vocab_size, bias=False)

    def return_embeddings(self, x):
        embs = []
        for i in range(self.game_size):
            h = x[i]
            if len(h.size()) == 3:
                h = h.squeeze(dim=-1)
            h_i = self.lin1(h)
            h_i = h_i.unsqueeze(dim=1)
            h_i = h_i.unsqueeze(dim=1)
            embs.append(h_i)
        h = torch.cat(embs, dim=2)
        return h

    def forward(self, input_0):
        primals_2 = self.lin1.weight
        primals_3 = self.conv2.weight
        primals_4 = self.conv3.weight
        primals_5 = self.lin4.weight
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
        return output[0]


Measured latency_ms: 0.115027