# AOT ID: ['0_inference']
from ctypes import c_void_p, c_long, c_int
import torch
import math
import random
import os
import tempfile
from math import inf, nan
from torch._inductor.hooks import run_intermediate_hooks
from torch._inductor.utils import maybe_profile
from torch._inductor.codegen.memory_planning import _align as align
from torch import device, empty_strided
from torch._inductor.async_compile import AsyncCompile
from torch._inductor.select_algorithm import extern_kernels
from torch._inductor.codegen.multi_kernel import MultiKernelCall
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid, split_scan_grid, grid_combo_kernels, start_graph, end_graph
from torch._C import _cuda_getCurrentRawStream as get_raw_stream

aten = torch.ops.aten
inductor_ops = torch.ops.inductor
_quantized = torch.ops._quantized
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cpu = torch._C._dynamo.guards._empty_strided_cpu
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
empty_strided_xpu = torch._C._dynamo.guards._empty_strided_xpu
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
alloc_from_pool = torch.ops.inductor._alloc_from_pool
async_compile = AsyncCompile()


# kernel path: runs/run_shard_7/inductor_cache/cg/ccgeik5lg55dafw2bimkoqczeqgbcybsxris5v5litllvo7d4564.py
# Topologically Sorted Source Nodes: [add, mul, sub, res, res_1], Original ATen: [aten.add, aten.mul, aten.sub, aten.clamp, aten.sqrt]
# Source node to ATen node mapping:
#   add => add
#   mul => mul
#   res => clamp_min
#   res_1 => sqrt
#   sub => sub
# Graph fragment:
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%unsqueeze, %unsqueeze_1), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mm, 2), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add, %mul), kwargs = {})
#   %clamp_min : [num_users=1] = call_function[target=torch.ops.aten.clamp_min.default](args = (%sub, 1e-12), kwargs = {})
#   %sqrt : [num_users=1] = call_function[target=torch.ops.aten.sqrt.default](args = (%clamp_min,), kwargs = {})
triton_poi_fused_add_clamp_mul_sqrt_sub_0 = async_compile.triton('triton_poi_fused_add_clamp_mul_sqrt_sub_0', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[16], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_clamp_mul_sqrt_sub_0', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 9, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_add_clamp_mul_sqrt_sub_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = (xindex // 4)
    x0 = xindex % 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (4*x1), xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (2 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr0 + (3 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr0 + (4*x0), xmask, eviction_policy='evict_last')
    tmp13 = tl.load(in_ptr0 + (1 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp16 = tl.load(in_ptr0 + (2 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp19 = tl.load(in_ptr0 + (3 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp23 = tl.load(in_out_ptr0 + (x2), xmask)
    tmp1 = tmp0 * tmp0
    tmp3 = tmp2 * tmp2
    tmp4 = tmp1 + tmp3
    tmp6 = tmp5 * tmp5
    tmp7 = tmp4 + tmp6
    tmp9 = tmp8 * tmp8
    tmp10 = tmp7 + tmp9
    tmp12 = tmp11 * tmp11
    tmp14 = tmp13 * tmp13
    tmp15 = tmp12 + tmp14
    tmp17 = tmp16 * tmp16
    tmp18 = tmp15 + tmp17
    tmp20 = tmp19 * tmp19
    tmp21 = tmp18 + tmp20
    tmp22 = tmp10 + tmp21
    tmp24 = 2.0
    tmp25 = tmp23 * tmp24
    tmp26 = tmp22 - tmp25
    tmp27 = 1e-12
    tmp28 = triton_helpers.maximum(tmp26, tmp27)
    tmp29 = libdevice.sqrt(tmp28)
    tl.store(in_out_ptr0 + (x2), tmp29, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/p3/cp3o24hg2b6ufn2jb57bo43mpub6ukgixynbrienm5d6lmj6ry7z.py
# Topologically Sorted Source Nodes: [res, res_1, setitem], Original ATen: [aten.clamp, aten.sqrt, aten.lift_fresh, aten.index_put]
# Source node to ATen node mapping:
#   res => clamp_min
#   res_1 => sqrt
#   setitem => full_default, index_put
# Graph fragment:
#   %clamp_min : [num_users=1] = call_function[target=torch.ops.aten.clamp_min.default](args = (%sub, 1e-12), kwargs = {})
#   %sqrt : [num_users=1] = call_function[target=torch.ops.aten.sqrt.default](args = (%clamp_min,), kwargs = {})
#   %full_default : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([], 0.0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %index_put : [num_users=1] = call_function[target=torch.ops.aten.index_put_.default](args = (%sqrt, [%lift_fresh_copy_1, %lift_fresh_copy_2], %full_default), kwargs = {})
triton_poi_fused_clamp_index_put_lift_fresh_sqrt_1 = async_compile.triton('triton_poi_fused_clamp_index_put_lift_fresh_sqrt_1', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[4], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0,), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_clamp_index_put_lift_fresh_sqrt_1', 'mutated_arg_names': ['out_ptr0'], 'no_x_dim': False, 'num_load': 0, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_clamp_index_put_lift_fresh_sqrt_1(out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = x0
    tmp1 = tl.full([1], 2, tl.int64)
    tmp2 = tmp0 < tmp1
    tmp3 = tl.full([1], 1, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.full([1], 0, tl.int64)
    tmp6 = tl.where(tmp4, tmp5, tmp3)
    tmp7 = tl.full([1], 3, tl.int64)
    tmp8 = tmp0 < tmp7
    tmp9 = tl.where(tmp8, tmp1, tmp7)
    tmp10 = tl.where(tmp2, tmp6, tmp9)
    tmp11 = 0.0
    tl.store(out_ptr0 + (tl.broadcast_to(5*tmp10, [XBLOCK])), tmp11, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/pv/cpv4qpjkkjnm64osykztotp63kwayeyw77adir2adz3offniwul5.py
# Topologically Sorted Source Nodes: [pow_2, score_teacher, sort], Original ATen: [aten.pow, aten.mul, aten.sort]
# Source node to ATen node mapping:
#   pow_2 => pow_2
#   score_teacher => mul_1
#   sort => sort
# Graph fragment:
#   %pow_2 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%index_put, 3), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%pow_2, -3), kwargs = {})
#   %sort : [num_users=1] = call_function[target=torch.ops.aten.sort.default](args = (%mul_1, 1, True), kwargs = {})
triton_per_fused_mul_pow_sort_2 = async_compile.triton('triton_per_fused_mul_pow_sort_2', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.persistent_reduction(
    size_hints=[4, 4],
    reduction_hint=ReductionHint.INNER,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*i16', 2: 'i32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_mul_pow_sort_2', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False}
)
@triton.jit
def triton_per_fused_mul_pow_sort_2(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 4
    rnumel = 4
    RBLOCK: tl.constexpr = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + (4*x0)), xmask, other=0.0)
    tmp1 = tmp0 * tmp0
    tmp2 = tmp1 * tmp0
    tmp3 = -3.0
    tmp4 = tmp2 * tmp3
    tmp5 = r1
    tmp6 = tmp5.to(tl.int16)
    tmp7 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK])
    tmp8 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
    tmp9, tmp10, = triton_helpers.sort_with_index(tmp7, tmp8, None, 1, stable=False, descending=True)
    tl.store(out_ptr0 + (r1 + (4*x0)), tmp10, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/52/c52mir27ozx2cplfhvyjwkfxszj7w3iaikplsnnxn2n6hibidbjz.py
# Topologically Sorted Source Nodes: [pow_4, score_student, ordered_student, logsumexp], Original ATen: [aten.pow, aten.mul, aten.gather, aten.logsumexp]
# Source node to ATen node mapping:
#   logsumexp => abs_1, amax, eq, exp, full_default_2, sub_2, sum_3, where
#   ordered_student => gather
#   pow_4 => pow_4
#   score_student => mul_3
# Graph fragment:
#   %pow_4 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%index_put_1, 3), kwargs = {})
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%pow_4, -3), kwargs = {})
#   %gather : [num_users=5] = call_function[target=torch.ops.aten.gather.default](args = (%mul_3, 1, %slice_2), kwargs = {})
#   %amax : [num_users=2] = call_function[target=torch.ops.aten.amax.default](args = (%gather, [1], True), kwargs = {})
#   %abs_1 : [num_users=1] = call_function[target=torch.ops.aten.abs.default](args = (%amax,), kwargs = {})
#   %eq : [num_users=1] = call_function[target=torch.ops.aten.eq.Scalar](args = (%abs_1, inf), kwargs = {})
#   %full_default_2 : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([], 0.0), kwargs = {dtype: torch.float32, layout: torch.strided, device: cuda:0, pin_memory: False})
#   %where : [num_users=2] = call_function[target=torch.ops.aten.where.self](args = (%eq, %full_default_2, %amax), kwargs = {})
#   %sub_2 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%gather, %where), kwargs = {})
#   %exp : [num_users=1] = call_function[target=torch.ops.aten.exp.default](args = (%sub_2,), kwargs = {})
#   %sum_3 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp, [1]), kwargs = {})
triton_poi_fused_gather_logsumexp_mul_pow_3 = async_compile.triton('triton_poi_fused_gather_logsumexp_mul_pow_3', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[4], 
    filename=__file__,
    triton_meta={'signature': {0: '*i16', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_gather_logsumexp_mul_pow_3', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 3, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_gather_logsumexp_mul_pow_3(in_ptr0, in_ptr1, out_ptr0, out_ptr1, 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 + (1 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr0 + (2 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp23 = tl.load(in_ptr0 + (3 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp1 = tmp0.to(tl.int64)
    tmp2 = tl.full([XBLOCK], 4, tl.int32)
    tmp3 = tmp1 + tmp2
    tmp4 = tmp1 < 0
    tmp5 = tl.where(tmp4, tmp3, tmp1)
    tl.device_assert(((0 <= tmp5) & (tmp5 < 4)) | ~(xmask), "index out of bounds: 0 <= tmp5 < 4")
    tmp7 = tl.load(in_ptr1 + (tmp5 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp8 = tmp7 * tmp7
    tmp9 = tmp8 * tmp7
    tmp10 = -3.0
    tmp11 = tmp9 * tmp10
    tmp13 = tmp12.to(tl.int64)
    tmp14 = tmp13 + tmp2
    tmp15 = tmp13 < 0
    tmp16 = tl.where(tmp15, tmp14, tmp13)
    tl.device_assert(((0 <= tmp16) & (tmp16 < 4)) | ~(xmask), "index out of bounds: 0 <= tmp16 < 4")
    tmp18 = tl.load(in_ptr1 + (tmp16 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp19 = tmp18 * tmp18
    tmp20 = tmp19 * tmp18
    tmp21 = tmp20 * tmp10
    tmp22 = triton_helpers.maximum(tmp11, tmp21)
    tmp24 = tmp23.to(tl.int64)
    tmp25 = tmp24 + tmp2
    tmp26 = tmp24 < 0
    tmp27 = tl.where(tmp26, tmp25, tmp24)
    tl.device_assert(((0 <= tmp27) & (tmp27 < 4)) | ~(xmask), "index out of bounds: 0 <= tmp27 < 4")
    tmp29 = tl.load(in_ptr1 + (tmp27 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp30 = tmp29 * tmp29
    tmp31 = tmp30 * tmp29
    tmp32 = tmp31 * tmp10
    tmp33 = triton_helpers.maximum(tmp22, tmp32)
    tmp34 = tl_math.abs(tmp33)
    tmp35 = float("inf")
    tmp36 = tmp34 == tmp35
    tmp37 = 0.0
    tmp38 = tl.where(tmp36, tmp37, tmp33)
    tmp39 = tmp11 - tmp38
    tmp40 = tl_math.exp(tmp39)
    tmp41 = tmp21 - tmp38
    tmp42 = tl_math.exp(tmp41)
    tmp43 = tmp40 + tmp42
    tmp44 = tmp32 - tmp38
    tmp45 = tl_math.exp(tmp44)
    tmp46 = tmp43 + tmp45
    tl.store(out_ptr0 + (x0), tmp33, xmask)
    tl.store(out_ptr1 + (x0), tmp46, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/vs/cvsaweidwnsbxk5lizky3axmdtnikqzfh7myhvsev343f4fja5ez.py
# Topologically Sorted Source Nodes: [stack], Original ATen: [aten.stack]
# Source node to ATen node mapping:
#   stack => cat
# Graph fragment:
#   %cat : [num_users=1] = call_function[target=torch.ops.aten.cat.default](args = ([%unsqueeze_4, %unsqueeze_5, %unsqueeze_6], 1), kwargs = {})
triton_poi_fused_stack_4 = async_compile.triton('triton_poi_fused_stack_4', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[16], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*i16', 3: '*fp32', 4: '*fp32', 5: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_stack_4', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 5, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_stack_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 12
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 3
    x1 = (xindex // 3)
    x2 = xindex
    tmp0 = x0
    tmp1 = tl.full([1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = tl.full([1], 1, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x1), tmp4 & xmask, eviction_policy='evict_last', other=0.0)
    tmp6 = tl_math.log(tmp5)
    tmp7 = tl.load(in_ptr1 + (x1), tmp4 & xmask, eviction_policy='evict_last', other=0.0)
    tmp8 = tl_math.abs(tmp7)
    tmp9 = float("inf")
    tmp10 = tmp8 == tmp9
    tmp11 = 0.0
    tmp12 = tl.where(tmp10, tmp11, tmp7)
    tmp13 = tmp6 + tmp12
    tmp14 = tl.full(tmp13.shape, 0.0, tmp13.dtype)
    tmp15 = tl.where(tmp4, tmp13, tmp14)
    tmp16 = tmp0 >= tmp3
    tmp17 = tl.full([1], 2, tl.int64)
    tmp18 = tmp0 < tmp17
    tmp19 = tmp16 & tmp18
    tmp20 = tl.load(in_ptr2 + (2 + (4*x1)), tmp19 & xmask, eviction_policy='evict_last', other=0.0)
    tmp21 = tmp20.to(tl.int64)
    tmp22 = tl.full([XBLOCK], 4, tl.int32)
    tmp23 = tmp21 + tmp22
    tmp24 = tmp21 < 0
    tmp25 = tl.where(tmp24, tmp23, tmp21)
    tl.device_assert(((0 <= tl.broadcast_to(tmp25, [XBLOCK])) & (tl.broadcast_to(tmp25, [XBLOCK]) < 4)) | ~(tmp19 & xmask), "index out of bounds: 0 <= tl.broadcast_to(tmp25, [XBLOCK]) < 4")
    tmp27 = tl.load(in_ptr3 + (tmp25 + (4*x1)), tmp19 & xmask, eviction_policy='evict_last', other=0.0)
    tmp28 = tmp27 * tmp27
    tmp29 = tmp28 * tmp27
    tmp30 = -3.0
    tmp31 = tmp29 * tmp30
    tmp32 = tl.load(in_ptr2 + (3 + (4*x1)), tmp19 & xmask, eviction_policy='evict_last', other=0.0)
    tmp33 = tmp32.to(tl.int64)
    tmp34 = tmp33 + tmp22
    tmp35 = tmp33 < 0
    tmp36 = tl.where(tmp35, tmp34, tmp33)
    tl.device_assert(((0 <= tl.broadcast_to(tmp36, [XBLOCK])) & (tl.broadcast_to(tmp36, [XBLOCK]) < 4)) | ~(tmp19 & xmask), "index out of bounds: 0 <= tl.broadcast_to(tmp36, [XBLOCK]) < 4")
    tmp38 = tl.load(in_ptr3 + (tmp36 + (4*x1)), tmp19 & xmask, eviction_policy='evict_last', other=0.0)
    tmp39 = tmp38 * tmp38
    tmp40 = tmp39 * tmp38
    tmp41 = tmp40 * tmp30
    tmp42 = triton_helpers.maximum(tmp31, tmp41)
    tmp43 = tl_math.abs(tmp42)
    tmp44 = tmp43 == tmp9
    tmp45 = tl.where(tmp44, tmp11, tmp42)
    tmp46 = tmp31 - tmp45
    tmp47 = tl_math.exp(tmp46)
    tmp48 = tmp41 - tmp45
    tmp49 = tl_math.exp(tmp48)
    tmp50 = tmp47 + tmp49
    tmp51 = tl_math.log(tmp50)
    tmp52 = tmp51 + tmp45
    tmp53 = tl.full(tmp52.shape, 0.0, tmp52.dtype)
    tmp54 = tl.where(tmp19, tmp52, tmp53)
    tmp55 = tmp0 >= tmp17
    tmp56 = tl.full([1], 3, tl.int64)
    tmp57 = tmp0 < tmp56
    tmp58 = tl.load(in_ptr2 + (3 + (4*x1)), tmp55 & xmask, eviction_policy='evict_last', other=0.0)
    tmp59 = tmp58.to(tl.int64)
    tmp60 = tmp59 + tmp22
    tmp61 = tmp59 < 0
    tmp62 = tl.where(tmp61, tmp60, tmp59)
    tl.device_assert(((0 <= tl.broadcast_to(tmp62, [XBLOCK])) & (tl.broadcast_to(tmp62, [XBLOCK]) < 4)) | ~(tmp55 & xmask), "index out of bounds: 0 <= tl.broadcast_to(tmp62, [XBLOCK]) < 4")
    tmp64 = tl.load(in_ptr3 + (tmp62 + (4*x1)), tmp55 & xmask, eviction_policy='evict_last', other=0.0)
    tmp65 = tmp64 * tmp64
    tmp66 = tmp65 * tmp64
    tmp67 = tmp66 * tmp30
    tmp68 = tl_math.abs(tmp67)
    tmp69 = tmp68 == tmp9
    tmp70 = tl.where(tmp69, tmp11, tmp67)
    tmp71 = tmp67 - tmp70
    tmp72 = tl_math.exp(tmp71)
    tmp73 = tl_math.log(tmp72)
    tmp74 = tmp73 + tmp70
    tmp75 = tl.full(tmp74.shape, 0.0, tmp74.dtype)
    tmp76 = tl.where(tmp55, tmp74, tmp75)
    tmp77 = tl.where(tmp19, tmp54, tmp76)
    tmp78 = tl.where(tmp4, tmp15, tmp77)
    tl.store(out_ptr0 + (x2), tmp78, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/6t/c6t7rj6cxxah2fyezy6pp2aw5nxel7tmlcmfeuw34oas4264vybr.py
# Topologically Sorted Source Nodes: [pow_4, score_student, ordered_student, sub_2, log_prob, mul_4, loss], Original ATen: [aten.pow, aten.mul, aten.gather, aten.sub, aten.sum, aten.mean]
# Source node to ATen node mapping:
#   log_prob => sum_6
#   loss => mean
#   mul_4 => mul_4
#   ordered_student => gather
#   pow_4 => pow_4
#   score_student => mul_3
#   sub_2 => sub_5
# Graph fragment:
#   %pow_4 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%index_put_1, 3), kwargs = {})
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%pow_4, -3), kwargs = {})
#   %gather : [num_users=5] = call_function[target=torch.ops.aten.gather.default](args = (%mul_3, 1, %slice_2), kwargs = {})
#   %sub_5 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%gather, %cat), kwargs = {})
#   %sum_6 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%sub_5, [1]), kwargs = {})
#   %mul_4 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_6, -1), kwargs = {})
#   %mean : [num_users=1] = call_function[target=torch.ops.aten.mean.default](args = (%mul_4,), kwargs = {})
triton_per_fused_gather_mean_mul_pow_sub_sum_5 = async_compile.triton('triton_per_fused_gather_mean_mul_pow_sub_sum_5', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.persistent_reduction(
    size_hints=[1, 4],
    reduction_hint=ReductionHint.DEFAULT,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*i16', 2: '*fp32', 3: '*fp32', 4: 'i32', 5: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {4: 1}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=(4,))]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_gather_mean_mul_pow_sub_sum_5', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 6, 'num_reduction': 1, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False}
)
@triton.jit
def triton_per_fused_gather_mean_mul_pow_sub_sum_5(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 1
    rnumel = 4
    RBLOCK: tl.constexpr = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + (1 + (4*r0)), None, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr2 + (3*r0), None, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr0 + (2 + (4*r0)), None, eviction_policy='evict_last')
    tmp24 = tl.load(in_ptr2 + (1 + (3*r0)), None, eviction_policy='evict_last')
    tmp27 = tl.load(in_ptr0 + (3 + (4*r0)), None, eviction_policy='evict_last')
    tmp37 = tl.load(in_ptr2 + (2 + (3*r0)), None, eviction_policy='evict_last')
    tmp1 = tmp0.to(tl.int64)
    tmp2 = tl.full([XBLOCK, RBLOCK], 4, tl.int32)
    tmp3 = tmp1 + tmp2
    tmp4 = tmp1 < 0
    tmp5 = tl.where(tmp4, tmp3, tmp1)
    tl.device_assert((0 <= tmp5) & (tmp5 < 4), "index out of bounds: 0 <= tmp5 < 4")
    tmp7 = tl.load(in_ptr1 + (tmp5 + (4*r0)), None, eviction_policy='evict_last')
    tmp8 = tmp7 * tmp7
    tmp9 = tmp8 * tmp7
    tmp10 = -3.0
    tmp11 = tmp9 * tmp10
    tmp13 = tmp11 - tmp12
    tmp15 = tmp14.to(tl.int64)
    tmp16 = tmp15 + tmp2
    tmp17 = tmp15 < 0
    tmp18 = tl.where(tmp17, tmp16, tmp15)
    tl.device_assert((0 <= tmp18) & (tmp18 < 4), "index out of bounds: 0 <= tmp18 < 4")
    tmp20 = tl.load(in_ptr1 + (tmp18 + (4*r0)), None, eviction_policy='evict_last')
    tmp21 = tmp20 * tmp20
    tmp22 = tmp21 * tmp20
    tmp23 = tmp22 * tmp10
    tmp25 = tmp23 - tmp24
    tmp26 = tmp13 + tmp25
    tmp28 = tmp27.to(tl.int64)
    tmp29 = tmp28 + tmp2
    tmp30 = tmp28 < 0
    tmp31 = tl.where(tmp30, tmp29, tmp28)
    tl.device_assert((0 <= tmp31) & (tmp31 < 4), "index out of bounds: 0 <= tmp31 < 4")
    tmp33 = tl.load(in_ptr1 + (tmp31 + (4*r0)), None, eviction_policy='evict_last')
    tmp34 = tmp33 * tmp33
    tmp35 = tmp34 * tmp33
    tmp36 = tmp35 * tmp10
    tmp38 = tmp36 - tmp37
    tmp39 = tmp26 + tmp38
    tmp40 = -1.0
    tmp41 = tmp39 * tmp40
    tmp42 = tl.broadcast_to(tmp41, [XBLOCK, RBLOCK])
    tmp44 = tl.sum(tmp42, 1)[:, None]
    tmp45 = 4.0
    tmp46 = tmp44 / tmp45
    tl.debug_barrier()
    tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp46, None)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

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, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [prod], Original ATen: [aten.mm]
        extern_kernels.mm(arg0_1, reinterpret_tensor(arg0_1, (4, 4), (1, 4), 0), out=buf0)
        buf1 = buf0; del buf0  # reuse
        buf2 = buf1; del buf1  # reuse
        # Topologically Sorted Source Nodes: [add, mul, sub, res, res_1], Original ATen: [aten.add, aten.mul, aten.sub, aten.clamp, aten.sqrt]
        stream0 = get_raw_stream(0)
        triton_poi_fused_add_clamp_mul_sqrt_sub_0.run(buf2, arg0_1, 16, grid=grid(16), stream=stream0)
        del arg0_1
        # Topologically Sorted Source Nodes: [res, res_1, setitem], Original ATen: [aten.clamp, aten.sqrt, aten.lift_fresh, aten.index_put]
        triton_poi_fused_clamp_index_put_lift_fresh_sqrt_1.run(buf2, 4, grid=grid(4), stream=stream0)
        buf5 = empty_strided_cuda((4, 4), (4, 1), torch.int16)
        # Topologically Sorted Source Nodes: [pow_2, score_teacher, sort], Original ATen: [aten.pow, aten.mul, aten.sort]
        triton_per_fused_mul_pow_sort_2.run(buf2, buf5, 4, 4, grid=grid(4), stream=stream0)
        buf6 = buf2; del buf2  # reuse
        # Topologically Sorted Source Nodes: [prod_1], Original ATen: [aten.mm]
        extern_kernels.mm(arg1_1, reinterpret_tensor(arg1_1, (4, 4), (1, 4), 0), out=buf6)
        buf7 = buf6; del buf6  # reuse
        buf8 = buf7; del buf7  # reuse
        # Topologically Sorted Source Nodes: [add_1, mul_2, sub_1, res_3, res_4], Original ATen: [aten.add, aten.mul, aten.sub, aten.clamp, aten.sqrt]
        triton_poi_fused_add_clamp_mul_sqrt_sub_0.run(buf8, arg1_1, 16, grid=grid(16), stream=stream0)
        del arg1_1
        # Topologically Sorted Source Nodes: [res_3, res_4, setitem_1], Original ATen: [aten.clamp, aten.sqrt, aten.lift_fresh, aten.index_put]
        triton_poi_fused_clamp_index_put_lift_fresh_sqrt_1.run(buf8, 4, grid=grid(4), stream=stream0)
        buf10 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        buf11 = empty_strided_cuda((4, ), (1, ), torch.float32)
        # Topologically Sorted Source Nodes: [pow_4, score_student, ordered_student, logsumexp], Original ATen: [aten.pow, aten.mul, aten.gather, aten.logsumexp]
        triton_poi_fused_gather_logsumexp_mul_pow_3.run(buf5, buf8, buf10, buf11, 4, grid=grid(4), stream=stream0)
        buf12 = empty_strided_cuda((4, 3), (3, 1), torch.float32)
        # Topologically Sorted Source Nodes: [stack], Original ATen: [aten.stack]
        triton_poi_fused_stack_4.run(buf11, buf10, buf5, buf8, buf12, 12, grid=grid(12), stream=stream0)
        del buf10
        del buf11
        buf14 = empty_strided_cuda((), (), torch.float32)
        buf15 = buf14; del buf14  # reuse
        # Topologically Sorted Source Nodes: [pow_4, score_student, ordered_student, sub_2, log_prob, mul_4, loss], Original ATen: [aten.pow, aten.mul, aten.gather, aten.sub, aten.sum, aten.mean]
        triton_per_fused_gather_mean_mul_pow_sub_sum_5.run(buf15, buf5, buf8, buf12, 1, 4, grid=grid(1), stream=stream0)
        del buf12
        del buf5
        del buf8
    return (buf15, )


def benchmark_compiled_module(times=10, repeat=10):
    from torch._dynamo.testing import rand_strided
    from torch._inductor.utils import print_performance
    arg0_1 = rand_strided((4, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    arg1_1 = rand_strided((4, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([arg0_1, arg1_1])
    return print_performance(fn, times=times, repeat=repeat)


if __name__ == "__main__":
    from torch._inductor.wrapper_benchmark import compiled_module_main
    compiled_module_main('None', benchmark_compiled_module)

import torch
import torch.nn as nn


def pdist(e, squared=False, eps=1e-12):
    e_square = e.pow(2).sum(dim=1)
    prod = e @ e.t()
    res = (e_square.unsqueeze(1) + e_square.unsqueeze(0) - 2 * prod).clamp(min
        =eps)
    if not squared:
        res = res.sqrt()
    res = res.clone()
    res[range(len(e)), range(len(e))] = 0
    return res


class HardDarkRank(nn.Module):

    def __init__(self, alpha=3, beta=3, permute_len=4):
        super().__init__()
        self.alpha = alpha
        self.beta = beta
        self.permute_len = permute_len

    def forward(self, student, teacher):
        score_teacher = -1 * self.alpha * pdist(teacher, squared=False).pow(
            self.beta)
        score_student = -1 * self.alpha * pdist(student, squared=False).pow(
            self.beta)
        permute_idx = score_teacher.sort(dim=1, descending=True)[1][:, 1:
            self.permute_len + 1]
        ordered_student = torch.gather(score_student, 1, permute_idx)
        log_prob = (ordered_student - torch.stack([torch.logsumexp(
            ordered_student[:, i:], dim=1) for i in range(permute_idx.size(
            1))], dim=1)).sum(dim=1)
        loss = (-1 * log_prob).mean()
        return loss


def get_inputs():
    return [torch.rand([4, 4]), torch.rand([4, 4])]


def get_init_inputs():
    return [[], {}]

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 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_add_clamp_mul_sqrt_sub_0(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 4
    x0 = xindex % 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp13 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp16 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp19 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp23 = tl.load(in_out_ptr0 + x2, xmask)
    tmp1 = tmp0 * tmp0
    tmp3 = tmp2 * tmp2
    tmp4 = tmp1 + tmp3
    tmp6 = tmp5 * tmp5
    tmp7 = tmp4 + tmp6
    tmp9 = tmp8 * tmp8
    tmp10 = tmp7 + tmp9
    tmp12 = tmp11 * tmp11
    tmp14 = tmp13 * tmp13
    tmp15 = tmp12 + tmp14
    tmp17 = tmp16 * tmp16
    tmp18 = tmp15 + tmp17
    tmp20 = tmp19 * tmp19
    tmp21 = tmp18 + tmp20
    tmp22 = tmp10 + tmp21
    tmp24 = 2.0
    tmp25 = tmp23 * tmp24
    tmp26 = tmp22 - tmp25
    tmp27 = 1e-12
    tmp28 = triton_helpers.maximum(tmp26, tmp27)
    tmp29 = libdevice.sqrt(tmp28)
    tl.store(in_out_ptr0 + x2, tmp29, xmask)


@triton.jit
def triton_poi_fused_clamp_index_put_lift_fresh_sqrt_1(out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = x0
    tmp1 = tl.full([1], 2, tl.int64)
    tmp2 = tmp0 < tmp1
    tmp3 = tl.full([1], 1, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.full([1], 0, tl.int64)
    tmp6 = tl.where(tmp4, tmp5, tmp3)
    tmp7 = tl.full([1], 3, tl.int64)
    tmp8 = tmp0 < tmp7
    tmp9 = tl.where(tmp8, tmp1, tmp7)
    tmp10 = tl.where(tmp2, tmp6, tmp9)
    tmp11 = 0.0
    tl.store(out_ptr0 + tl.broadcast_to(5 * tmp10, [XBLOCK]), tmp11, xmask)


@triton.jit
def triton_per_fused_mul_pow_sort_2(in_ptr0, out_ptr0, xnumel, rnumel,
    XBLOCK: tl.constexpr):
    xnumel = 4
    RBLOCK: tl.constexpr = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + 4 * x0), xmask, other=0.0)
    tmp1 = tmp0 * tmp0
    tmp2 = tmp1 * tmp0
    tmp3 = -3.0
    tmp4 = tmp2 * tmp3
    tmp5 = r1
    tmp6 = tmp5.to(tl.int16)
    tmp7 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK])
    tmp8 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
    _tmp9, tmp10 = triton_helpers.sort_with_index(tmp7, tmp8, None, 1,
        stable=False, descending=True)
    tl.store(out_ptr0 + (r1 + 4 * x0), tmp10, xmask)


@triton.jit
def triton_poi_fused_gather_logsumexp_mul_pow_3(in_ptr0, in_ptr1, out_ptr0,
    out_ptr1, 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 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp23 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp1 = tmp0.to(tl.int64)
    tmp2 = tl.full([XBLOCK], 4, tl.int32)
    tmp3 = tmp1 + tmp2
    tmp4 = tmp1 < 0
    tmp5 = tl.where(tmp4, tmp3, tmp1)
    tl.device_assert((0 <= tmp5) & (tmp5 < 4) | ~xmask,
        'index out of bounds: 0 <= tmp5 < 4')
    tmp7 = tl.load(in_ptr1 + (tmp5 + 4 * x0), xmask, eviction_policy=
        'evict_last')
    tmp8 = tmp7 * tmp7
    tmp9 = tmp8 * tmp7
    tmp10 = -3.0
    tmp11 = tmp9 * tmp10
    tmp13 = tmp12.to(tl.int64)
    tmp14 = tmp13 + tmp2
    tmp15 = tmp13 < 0
    tmp16 = tl.where(tmp15, tmp14, tmp13)
    tl.device_assert((0 <= tmp16) & (tmp16 < 4) | ~xmask,
        'index out of bounds: 0 <= tmp16 < 4')
    tmp18 = tl.load(in_ptr1 + (tmp16 + 4 * x0), xmask, eviction_policy=
        'evict_last')
    tmp19 = tmp18 * tmp18
    tmp20 = tmp19 * tmp18
    tmp21 = tmp20 * tmp10
    tmp22 = triton_helpers.maximum(tmp11, tmp21)
    tmp24 = tmp23.to(tl.int64)
    tmp25 = tmp24 + tmp2
    tmp26 = tmp24 < 0
    tmp27 = tl.where(tmp26, tmp25, tmp24)
    tl.device_assert((0 <= tmp27) & (tmp27 < 4) | ~xmask,
        'index out of bounds: 0 <= tmp27 < 4')
    tmp29 = tl.load(in_ptr1 + (tmp27 + 4 * x0), xmask, eviction_policy=
        'evict_last')
    tmp30 = tmp29 * tmp29
    tmp31 = tmp30 * tmp29
    tmp32 = tmp31 * tmp10
    tmp33 = triton_helpers.maximum(tmp22, tmp32)
    tmp34 = tl_math.abs(tmp33)
    tmp35 = float('inf')
    tmp36 = tmp34 == tmp35
    tmp37 = 0.0
    tmp38 = tl.where(tmp36, tmp37, tmp33)
    tmp39 = tmp11 - tmp38
    tmp40 = tl_math.exp(tmp39)
    tmp41 = tmp21 - tmp38
    tmp42 = tl_math.exp(tmp41)
    tmp43 = tmp40 + tmp42
    tmp44 = tmp32 - tmp38
    tmp45 = tl_math.exp(tmp44)
    tmp46 = tmp43 + tmp45
    tl.store(out_ptr0 + x0, tmp33, xmask)
    tl.store(out_ptr1 + x0, tmp46, xmask)


@triton.jit
def triton_poi_fused_stack_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 12
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 3
    x1 = xindex // 3
    x2 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 1, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + x1, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp6 = tl_math.log(tmp5)
    tmp7 = tl.load(in_ptr1 + x1, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp8 = tl_math.abs(tmp7)
    tmp9 = float('inf')
    tmp10 = tmp8 == tmp9
    tmp11 = 0.0
    tmp12 = tl.where(tmp10, tmp11, tmp7)
    tmp13 = tmp6 + tmp12
    tmp14 = tl.full(tmp13.shape, 0.0, tmp13.dtype)
    tmp15 = tl.where(tmp4, tmp13, tmp14)
    tmp16 = tmp0 >= tmp3
    tmp17 = tl.full([1], 2, tl.int64)
    tmp18 = tmp0 < tmp17
    tmp19 = tmp16 & tmp18
    tmp20 = tl.load(in_ptr2 + (2 + 4 * x1), tmp19 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp21 = tmp20.to(tl.int64)
    tmp22 = tl.full([XBLOCK], 4, tl.int32)
    tmp23 = tmp21 + tmp22
    tmp24 = tmp21 < 0
    tmp25 = tl.where(tmp24, tmp23, tmp21)
    tl.device_assert((0 <= tl.broadcast_to(tmp25, [XBLOCK])) & (tl.
        broadcast_to(tmp25, [XBLOCK]) < 4) | ~(tmp19 & xmask),
        'index out of bounds: 0 <= tl.broadcast_to(tmp25, [XBLOCK]) < 4')
    tmp27 = tl.load(in_ptr3 + (tmp25 + 4 * x1), tmp19 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp28 = tmp27 * tmp27
    tmp29 = tmp28 * tmp27
    tmp30 = -3.0
    tmp31 = tmp29 * tmp30
    tmp32 = tl.load(in_ptr2 + (3 + 4 * x1), tmp19 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp33 = tmp32.to(tl.int64)
    tmp34 = tmp33 + tmp22
    tmp35 = tmp33 < 0
    tmp36 = tl.where(tmp35, tmp34, tmp33)
    tl.device_assert((0 <= tl.broadcast_to(tmp36, [XBLOCK])) & (tl.
        broadcast_to(tmp36, [XBLOCK]) < 4) | ~(tmp19 & xmask),
        'index out of bounds: 0 <= tl.broadcast_to(tmp36, [XBLOCK]) < 4')
    tmp38 = tl.load(in_ptr3 + (tmp36 + 4 * x1), tmp19 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp39 = tmp38 * tmp38
    tmp40 = tmp39 * tmp38
    tmp41 = tmp40 * tmp30
    tmp42 = triton_helpers.maximum(tmp31, tmp41)
    tmp43 = tl_math.abs(tmp42)
    tmp44 = tmp43 == tmp9
    tmp45 = tl.where(tmp44, tmp11, tmp42)
    tmp46 = tmp31 - tmp45
    tmp47 = tl_math.exp(tmp46)
    tmp48 = tmp41 - tmp45
    tmp49 = tl_math.exp(tmp48)
    tmp50 = tmp47 + tmp49
    tmp51 = tl_math.log(tmp50)
    tmp52 = tmp51 + tmp45
    tmp53 = tl.full(tmp52.shape, 0.0, tmp52.dtype)
    tmp54 = tl.where(tmp19, tmp52, tmp53)
    tmp55 = tmp0 >= tmp17
    tl.full([1], 3, tl.int64)
    tmp58 = tl.load(in_ptr2 + (3 + 4 * x1), tmp55 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp59 = tmp58.to(tl.int64)
    tmp60 = tmp59 + tmp22
    tmp61 = tmp59 < 0
    tmp62 = tl.where(tmp61, tmp60, tmp59)
    tl.device_assert((0 <= tl.broadcast_to(tmp62, [XBLOCK])) & (tl.
        broadcast_to(tmp62, [XBLOCK]) < 4) | ~(tmp55 & xmask),
        'index out of bounds: 0 <= tl.broadcast_to(tmp62, [XBLOCK]) < 4')
    tmp64 = tl.load(in_ptr3 + (tmp62 + 4 * x1), tmp55 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp65 = tmp64 * tmp64
    tmp66 = tmp65 * tmp64
    tmp67 = tmp66 * tmp30
    tmp68 = tl_math.abs(tmp67)
    tmp69 = tmp68 == tmp9
    tmp70 = tl.where(tmp69, tmp11, tmp67)
    tmp71 = tmp67 - tmp70
    tmp72 = tl_math.exp(tmp71)
    tmp73 = tl_math.log(tmp72)
    tmp74 = tmp73 + tmp70
    tmp75 = tl.full(tmp74.shape, 0.0, tmp74.dtype)
    tmp76 = tl.where(tmp55, tmp74, tmp75)
    tmp77 = tl.where(tmp19, tmp54, tmp76)
    tmp78 = tl.where(tmp4, tmp15, tmp77)
    tl.store(out_ptr0 + x2, tmp78, xmask)


@triton.jit
def triton_per_fused_gather_mean_mul_pow_sub_sum_5(in_out_ptr0, in_ptr0,
    in_ptr1, in_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 4
    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 + (1 + 4 * r0), None, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr2 + 3 * r0, None, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last')
    tmp24 = tl.load(in_ptr2 + (1 + 3 * r0), None, eviction_policy='evict_last')
    tmp27 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last')
    tmp37 = tl.load(in_ptr2 + (2 + 3 * r0), None, eviction_policy='evict_last')
    tmp1 = tmp0.to(tl.int64)
    tmp2 = tl.full([XBLOCK, RBLOCK], 4, tl.int32)
    tmp3 = tmp1 + tmp2
    tmp4 = tmp1 < 0
    tmp5 = tl.where(tmp4, tmp3, tmp1)
    tl.device_assert((0 <= tmp5) & (tmp5 < 4),
        'index out of bounds: 0 <= tmp5 < 4')
    tmp7 = tl.load(in_ptr1 + (tmp5 + 4 * r0), None, eviction_policy=
        'evict_last')
    tmp8 = tmp7 * tmp7
    tmp9 = tmp8 * tmp7
    tmp10 = -3.0
    tmp11 = tmp9 * tmp10
    tmp13 = tmp11 - tmp12
    tmp15 = tmp14.to(tl.int64)
    tmp16 = tmp15 + tmp2
    tmp17 = tmp15 < 0
    tmp18 = tl.where(tmp17, tmp16, tmp15)
    tl.device_assert((0 <= tmp18) & (tmp18 < 4),
        'index out of bounds: 0 <= tmp18 < 4')
    tmp20 = tl.load(in_ptr1 + (tmp18 + 4 * r0), None, eviction_policy=
        'evict_last')
    tmp21 = tmp20 * tmp20
    tmp22 = tmp21 * tmp20
    tmp23 = tmp22 * tmp10
    tmp25 = tmp23 - tmp24
    tmp26 = tmp13 + tmp25
    tmp28 = tmp27.to(tl.int64)
    tmp29 = tmp28 + tmp2
    tmp30 = tmp28 < 0
    tmp31 = tl.where(tmp30, tmp29, tmp28)
    tl.device_assert((0 <= tmp31) & (tmp31 < 4),
        'index out of bounds: 0 <= tmp31 < 4')
    tmp33 = tl.load(in_ptr1 + (tmp31 + 4 * r0), None, eviction_policy=
        'evict_last')
    tmp34 = tmp33 * tmp33
    tmp35 = tmp34 * tmp33
    tmp36 = tmp35 * tmp10
    tmp38 = tmp36 - tmp37
    tmp39 = tmp26 + tmp38
    tmp40 = -1.0
    tmp41 = tmp39 * tmp40
    tmp42 = tl.broadcast_to(tmp41, [XBLOCK, RBLOCK])
    tmp44 = tl.sum(tmp42, 1)[:, None]
    tmp45 = 4.0
    tmp46 = tmp44 / tmp45
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp46, None)


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, 4), (4, 1), torch.float32)
        extern_kernels.mm(arg0_1, reinterpret_tensor(arg0_1, (4, 4), (1, 4),
            0), out=buf0)
        buf1 = buf0
        del buf0
        buf2 = buf1
        del buf1
        get_raw_stream(0)
        triton_poi_fused_add_clamp_mul_sqrt_sub_0[grid(16)](buf2, arg0_1, 
            16, XBLOCK=16, num_warps=1, num_stages=1)
        del arg0_1
        triton_poi_fused_clamp_index_put_lift_fresh_sqrt_1[grid(4)](buf2, 4,
            XBLOCK=4, num_warps=1, num_stages=1)
        buf5 = empty_strided_cuda((4, 4), (4, 1), torch.int16)
        triton_per_fused_mul_pow_sort_2[grid(4)](buf2, buf5, 4, 4, XBLOCK=1,
            num_warps=2, num_stages=1)
        buf6 = buf2
        del buf2
        extern_kernels.mm(arg1_1, reinterpret_tensor(arg1_1, (4, 4), (1, 4),
            0), out=buf6)
        buf7 = buf6
        del buf6
        buf8 = buf7
        del buf7
        triton_poi_fused_add_clamp_mul_sqrt_sub_0[grid(16)](buf8, arg1_1, 
            16, XBLOCK=16, num_warps=1, num_stages=1)
        del arg1_1
        triton_poi_fused_clamp_index_put_lift_fresh_sqrt_1[grid(4)](buf8, 4,
            XBLOCK=4, num_warps=1, num_stages=1)
        buf10 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        buf11 = empty_strided_cuda((4,), (1,), torch.float32)
        triton_poi_fused_gather_logsumexp_mul_pow_3[grid(4)](buf5, buf8,
            buf10, buf11, 4, XBLOCK=4, num_warps=1, num_stages=1)
        buf12 = empty_strided_cuda((4, 3), (3, 1), torch.float32)
        triton_poi_fused_stack_4[grid(12)](buf11, buf10, buf5, buf8, buf12,
            12, XBLOCK=16, num_warps=1, num_stages=1)
        del buf10
        del buf11
        buf14 = empty_strided_cuda((), (), torch.float32)
        buf15 = buf14
        del buf14
        triton_per_fused_gather_mean_mul_pow_sub_sum_5[grid(1)](buf15, buf5,
            buf8, buf12, 1, 4, XBLOCK=1, num_warps=2, num_stages=1)
        del buf12
        del buf5
        del buf8
    return buf15,


def pdist(e, squared=False, eps=1e-12):
    e_square = e.pow(2).sum(dim=1)
    prod = e @ e.t()
    res = (e_square.unsqueeze(1) + e_square.unsqueeze(0) - 2 * prod).clamp(min
        =eps)
    if not squared:
        res = res.sqrt()
    res = res.clone()
    res[range(len(e)), range(len(e))] = 0
    return res


class HardDarkRankNew(nn.Module):

    def __init__(self, alpha=3, beta=3, permute_len=4):
        super().__init__()
        self.alpha = alpha
        self.beta = beta
        self.permute_len = permute_len

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