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 libdevice, math as tl_math
import torch.nn as nn
import torch.nn.parallel
import torch.optim
import torch.utils.data
import torch.utils.data.distributed
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda


@triton.jit
def triton_per_fused_add_clamp_div_log_mul_neg_pow_rsub_sigmoid_sub_sum_0(
    in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, out_ptr3,
    out_ptr4, xnumel, rnumel):
    XBLOCK: tl.constexpr = 1
    RBLOCK: tl.constexpr = 256
    xoffset = tl.program_id(0) * XBLOCK
    tl.full([1], xoffset, tl.int32)
    tl.full([RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[:]
    tl.full([RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp3 = tl.load(in_ptr1 + r0, None)
    tmp1 = 1.0
    tmp2 = tmp1 - tmp0
    tmp4 = tl.sigmoid(tmp3)
    tmp5 = tmp4 * tmp0
    tmp6 = tmp1 - tmp4
    tmp7 = 0.05
    tmp8 = tmp6 + tmp7
    tmp9 = triton_helpers.minimum(tmp8, tmp1)
    tmp10 = tmp9 * tmp2
    tmp11 = tmp1 - tmp5
    tmp12 = tmp11 - tmp10
    tmp13 = tmp0 * tmp1
    tmp14 = 4.0
    tmp15 = tmp2 * tmp14
    tmp16 = tmp13 + tmp15
    tmp17 = libdevice.pow(tmp12, tmp16)
    tmp18 = 1e-05
    tmp19 = triton_helpers.maximum(tmp4, tmp18)
    tmp20 = tl_math.log(tmp19)
    tmp21 = tmp0 * tmp20
    tmp22 = triton_helpers.maximum(tmp9, tmp18)
    tmp23 = tl_math.log(tmp22)
    tmp24 = tmp2 * tmp23
    tmp25 = tmp21 + tmp24
    tmp26 = tmp25 * tmp17
    tmp27 = tl.broadcast_to(tmp26, [RBLOCK])
    tmp29 = triton_helpers.promote_to_tensor(tl.sum(tmp27, 0))
    tmp30 = -tmp29
    tmp31 = 0.25
    tmp32 = tmp30 * tmp31
    tmp33 = tmp32 * tmp31
    tmp34 = 1000.0
    tmp35 = tmp33 * tmp34
    tl.store(out_ptr0 + tl.broadcast_to(r0, [RBLOCK]), tmp2, None)
    tl.store(out_ptr1 + tl.broadcast_to(r0, [RBLOCK]), tmp5, None)
    tl.store(out_ptr2 + tl.broadcast_to(r0, [RBLOCK]), tmp10, None)
    tl.store(out_ptr3 + tl.broadcast_to(r0, [RBLOCK]), tmp17, None)
    tl.store(out_ptr4 + tl.broadcast_to(r0, [RBLOCK]), tmp26, None)
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp35, None)


def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg1_1, (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, 4), (64, 16, 4, 1), torch.float32)
        buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf5 = empty_strided_cuda((), (), torch.float32)
        buf6 = buf5
        del buf5
        get_raw_stream(0)
        triton_per_fused_add_clamp_div_log_mul_neg_pow_rsub_sigmoid_sub_sum_0[
            grid(1)](buf6, arg0_1, arg1_1, buf0, buf1, buf2, buf3, buf4, 1,
            256, num_warps=2, num_stages=1)
        del arg0_1
        del arg1_1
    return buf6, buf3, buf4, buf2, buf1, buf0


class AsymmetricLossOptimizedNew(nn.Module):
    """ Notice - optimized version, minimizes memory allocation and gpu uploading,
    favors inplace operations"""

    def __init__(self, gamma_neg=4, gamma_pos=1, clip=0.05, eps=1e-05,
        disable_torch_grad_focal_loss=False):
        super(AsymmetricLossOptimizedNew, self).__init__()
        self.gamma_neg = gamma_neg
        self.gamma_pos = gamma_pos
        self.clip = clip
        self.disable_torch_grad_focal_loss = disable_torch_grad_focal_loss
        self.eps = eps
        (self.targets) = (self.anti_targets) = (self.xs_pos) = (self.xs_neg
            ) = (self.asymmetric_w) = (self.loss) = None

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


Measured latency_ms: 0.022473