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
from torch import nn
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_abs_clamp_min_div_linalg_vector_norm_mean_mul_sub_0(
    in_ptr0, in_ptr1, out_ptr0, out_ptr1, 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
    r1 = rindex % 16
    r3 = rindex // 64
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp1 = tl.load(in_ptr1 + r0, None)
    tmp7 = tl.load(in_ptr0 + (r1 + 64 * r3), None, eviction_policy='evict_last'
        )
    tmp9 = tl.load(in_ptr0 + (16 + r1 + 64 * r3), None, eviction_policy=
        'evict_last')
    tmp12 = tl.load(in_ptr0 + (32 + r1 + 64 * r3), None, eviction_policy=
        'evict_last')
    tmp15 = tl.load(in_ptr0 + (48 + r1 + 64 * r3), None, eviction_policy=
        'evict_last')
    tmp22 = tl.load(in_ptr1 + (r1 + 64 * r3), None, eviction_policy=
        'evict_last')
    tmp24 = tl.load(in_ptr1 + (16 + r1 + 64 * r3), None, eviction_policy=
        'evict_last')
    tmp27 = tl.load(in_ptr1 + (32 + r1 + 64 * r3), None, eviction_policy=
        'evict_last')
    tmp30 = tl.load(in_ptr1 + (48 + r1 + 64 * r3), None, eviction_policy=
        'evict_last')
    tmp2 = tmp0 - tmp1
    tmp3 = tl_math.abs(tmp2)
    tmp4 = tl.broadcast_to(tmp3, [RBLOCK])
    tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0))
    tmp8 = tmp7 * tmp7
    tmp10 = tmp9 * tmp9
    tmp11 = tmp8 + tmp10
    tmp13 = tmp12 * tmp12
    tmp14 = tmp11 + tmp13
    tmp16 = tmp15 * tmp15
    tmp17 = tmp14 + tmp16
    tmp18 = libdevice.sqrt(tmp17)
    tmp19 = 1e-20
    tmp20 = triton_helpers.maximum(tmp18, tmp19)
    tmp21 = tmp0 / tmp20
    tmp23 = tmp22 * tmp22
    tmp25 = tmp24 * tmp24
    tmp26 = tmp23 + tmp25
    tmp28 = tmp27 * tmp27
    tmp29 = tmp26 + tmp28
    tmp31 = tmp30 * tmp30
    tmp32 = tmp29 + tmp31
    tmp33 = libdevice.sqrt(tmp32)
    tmp34 = triton_helpers.maximum(tmp33, tmp19)
    tmp35 = tmp1 / tmp34
    tmp36 = tmp21 * tmp35
    tl.store(out_ptr1 + tl.broadcast_to(r0, [RBLOCK]), tmp36, None)
    tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp6, None)


@triton.jit
def triton_per_fused_abs_add_mean_mul_rsub_sub_sum_1(in_out_ptr0, in_ptr0,
    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 % 16
    r1 = rindex // 16
    tmp0 = tl.load(in_ptr0 + (r0 + 64 * r1), None)
    tmp1 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None)
    tmp3 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None)
    tmp5 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None)
    tmp12 = tl.load(in_out_ptr0 + 0)
    tmp13 = tl.broadcast_to(tmp12, [XBLOCK, 1])
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp6 = tmp4 + tmp5
    tmp7 = 1.0
    tmp8 = tmp7 - tmp6
    tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK])
    tmp11 = tl.sum(tmp9, 1)[:, None]
    tmp14 = 256.0
    tmp15 = tmp13 / tmp14
    tmp16 = 64.0
    tmp17 = tmp11 / tmp16
    tmp18 = 5.0
    tmp19 = tmp17 * tmp18
    tmp20 = tmp15 + tmp19
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp20, 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((), (), torch.float32)
        buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_per_fused_abs_clamp_min_div_linalg_vector_norm_mean_mul_sub_0[
            grid(1)](arg1_1, arg0_1, buf0, buf1, 1, 256, num_warps=2,
            num_stages=1)
        del arg0_1
        del arg1_1
        buf3 = buf0
        del buf0
        triton_per_fused_abs_add_mean_mul_rsub_sub_sum_1[grid(1)](buf3,
            buf1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1)
        del buf1
    return buf3,


class ExpandNetLossNew(nn.Module):

    def __init__(self, loss_lambda=5):
        super(ExpandNetLossNew, self).__init__()
        self.similarity = torch.nn.CosineSimilarity(dim=1, eps=1e-20)
        self.l1_loss = nn.L1Loss()
        self.loss_lambda = loss_lambda

    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.028059