import torch
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
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__softmax_add_log_max_neg_0(in_ptr0, in_ptr1, out_ptr0,
    out_ptr1, out_ptr2, out_ptr3, 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')
    tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp13 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp23 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp24 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp34 = 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'
        )
    tmp2 = 1e-20
    tmp3 = tmp1 + tmp2
    tmp4 = tl_math.log(tmp3)
    tmp5 = -tmp4
    tmp6 = tmp5 + tmp2
    tmp7 = tl_math.log(tmp6)
    tmp8 = -tmp7
    tmp9 = tmp0 + tmp8
    tmp10 = 1.0
    tmp11 = tmp9 * tmp10
    tmp14 = tmp13 + tmp2
    tmp15 = tl_math.log(tmp14)
    tmp16 = -tmp15
    tmp17 = tmp16 + tmp2
    tmp18 = tl_math.log(tmp17)
    tmp19 = -tmp18
    tmp20 = tmp12 + tmp19
    tmp21 = tmp20 * tmp10
    tmp22 = triton_helpers.maximum(tmp11, tmp21)
    tmp25 = tmp24 + tmp2
    tmp26 = tl_math.log(tmp25)
    tmp27 = -tmp26
    tmp28 = tmp27 + tmp2
    tmp29 = tl_math.log(tmp28)
    tmp30 = -tmp29
    tmp31 = tmp23 + tmp30
    tmp32 = tmp31 * tmp10
    tmp33 = triton_helpers.maximum(tmp22, tmp32)
    tmp36 = tmp35 + tmp2
    tmp37 = tl_math.log(tmp36)
    tmp38 = -tmp37
    tmp39 = tmp38 + tmp2
    tmp40 = tl_math.log(tmp39)
    tmp41 = -tmp40
    tmp42 = tmp34 + tmp41
    tmp43 = tmp42 * tmp10
    tmp44 = triton_helpers.maximum(tmp33, tmp43)
    tmp45 = tmp11 - tmp44
    tmp46 = 2.0
    tmp47 = tmp45 * tmp46
    tmp48 = tl_math.exp(tmp47)
    tmp49 = tmp21 - tmp44
    tmp50 = tmp49 * tmp46
    tmp51 = tl_math.exp(tmp50)
    tmp52 = tmp48 + tmp51
    tmp53 = tmp32 - tmp44
    tmp54 = tmp53 * tmp46
    tmp55 = tl_math.exp(tmp54)
    tmp56 = tmp52 + tmp55
    tmp57 = tmp43 - tmp44
    tmp58 = tmp57 * tmp46
    tmp59 = tl_math.exp(tmp58)
    tmp60 = tmp56 + tmp59
    tmp61 = tmp48 / tmp60
    tmp62 = tmp51 / tmp60
    tmp63 = triton_helpers.maximum(tmp61, tmp62)
    tmp64 = tmp55 / tmp60
    tmp65 = triton_helpers.maximum(tmp63, tmp64)
    tmp66 = tmp59 / tmp60
    tmp67 = triton_helpers.maximum(tmp65, tmp66)
    tmp68 = tmp61 > tmp62
    tmp69 = tmp61 == tmp62
    tmp70 = tmp61 != tmp61
    tmp71 = tmp62 != tmp62
    tmp72 = tmp70 > tmp71
    tmp73 = tmp68 | tmp72
    tmp74 = tmp70 & tmp71
    tmp75 = tmp69 | tmp74
    tmp76 = tl.full([1], 0, tl.int64)
    tmp77 = tl.full([1], 1, tl.int64)
    tmp78 = tmp76 < tmp77
    tmp79 = tmp75 & tmp78
    tmp80 = tmp73 | tmp79
    tmp81 = tl.where(tmp80, tmp61, tmp62)
    tmp82 = tl.where(tmp80, tmp76, tmp77)
    tmp83 = tmp81 > tmp64
    tmp84 = tmp81 == tmp64
    tmp85 = tmp81 != tmp81
    tmp86 = tmp64 != tmp64
    tmp87 = tmp85 > tmp86
    tmp88 = tmp83 | tmp87
    tmp89 = tmp85 & tmp86
    tmp90 = tmp84 | tmp89
    tmp91 = tl.full([1], 2, tl.int64)
    tmp92 = tmp82 < tmp91
    tmp93 = tmp90 & tmp92
    tmp94 = tmp88 | tmp93
    tmp95 = tl.where(tmp94, tmp81, tmp64)
    tmp96 = tl.where(tmp94, tmp82, tmp91)
    tmp97 = tmp95 > tmp66
    tmp98 = tmp95 == tmp66
    tmp99 = tmp95 != tmp95
    tmp100 = tmp66 != tmp66
    tmp101 = tmp99 > tmp100
    tmp102 = tmp97 | tmp101
    tmp103 = tmp99 & tmp100
    tmp104 = tmp98 | tmp103
    tmp105 = tl.full([1], 3, tl.int64)
    tmp106 = tmp96 < tmp105
    tmp107 = tmp104 & tmp106
    tmp108 = tmp102 | tmp107
    tl.where(tmp108, tmp95, tmp66)
    tmp110 = tl.where(tmp108, tmp96, tmp105)
    tl.store(out_ptr0 + x0, tmp44, xmask)
    tl.store(out_ptr1 + x0, tmp60, xmask)
    tl.store(out_ptr2 + x0, tmp67, xmask)
    tl.store(out_ptr3 + x0, tmp110, xmask)


@triton.jit
def triton_poi_fused__softmax__to_copy_add_eq_log_neg_sub_1(in_ptr0,
    in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, out_ptr2, 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_ptr1 + x2, xmask)
    tmp12 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp17 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
    tmp19 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last')
    tmp2 = 1e-20
    tmp3 = tmp1 + tmp2
    tmp4 = tl_math.log(tmp3)
    tmp5 = -tmp4
    tmp6 = tmp5 + tmp2
    tmp7 = tl_math.log(tmp6)
    tmp8 = -tmp7
    tmp9 = tmp0 + tmp8
    tmp10 = 1.0
    tmp11 = tmp9 * tmp10
    tmp13 = tmp11 - tmp12
    tmp14 = 2.0
    tmp15 = tmp13 * tmp14
    tmp16 = tl_math.exp(tmp15)
    tmp18 = tmp16 / tmp17
    tmp20 = tmp18 == tmp19
    tmp21 = tmp20.to(tl.float32)
    tmp22 = tmp21 - tmp18
    tmp23 = tmp22 + tmp18
    tl.store(out_ptr0 + x2, tmp23, xmask)
    tl.store(out_ptr2 + x2, tmp8, xmask)


def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4), (4, 1))
    assert_size_stride(arg1_1, (4, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        buf1 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        buf2 = empty_strided_cuda((4,), (1,), torch.float32)
        buf3 = empty_strided_cuda((4,), (1,), torch.int64)
        get_raw_stream(0)
        triton_poi_fused__softmax_add_log_max_neg_0[grid(4)](arg1_1, arg0_1,
            buf0, buf1, buf2, buf3, 4, XBLOCK=4, num_warps=1, num_stages=1)
        buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused__softmax__to_copy_add_eq_log_neg_sub_1[grid(16)](
            arg1_1, arg0_1, buf0, buf1, buf2, buf4, arg0_1, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        del arg0_1
        del arg1_1
        del buf0
        del buf1
        del buf2
    return buf4, reinterpret_tensor(buf3, (1, 4), (4, 1), 0)


class gumbel_samplerNew(nn.Module):

    def __init__(self):
        super(gumbel_samplerNew, self).__init__()

    def forward(self, input_0, input_1):
        arg0_1 = input_0
        arg1_1 = input_1
        output = call([arg0_1, arg1_1])
        return output[0], output[1]


Measured latency_ms: 0.016445