# AOT ID: ['0_forward']
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/um/cum65j23qchrjf5dndblqgbw6zomhgwfj2obfidtgy7b5j3zwklm.py
# Topologically Sorted Source Nodes: [c], Original ATen: [aten._softmax]
# Source node to ATen node mapping:
#   c => amax, exp, sub
# Graph fragment:
#   %amax : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%primals_2, [1], True), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%primals_2, %amax), kwargs = {})
#   %exp : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub,), kwargs = {})
triton_poi_fused__softmax_0 = async_compile.triton('triton_poi_fused__softmax_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__softmax_0', '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__softmax_0(in_ptr0, out_ptr0, 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_ptr0 + (4*x1), xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (2 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (3 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp3 = triton_helpers.maximum(tmp1, tmp2)
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp0 - tmp7
    tmp9 = tl_math.exp(tmp8)
    tl.store(out_ptr0 + (x2), tmp9, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/wk/cwk2wao7opapqbjj7klnqrd6tgist3ts3nc5veryzhzstwpx7d4l.py
# Topologically Sorted Source Nodes: [c], Original ATen: [aten._softmax]
# Source node to ATen node mapping:
#   c => div, sum_1
# Graph fragment:
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp, [1], True), kwargs = {})
#   %div : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%exp, %sum_1), kwargs = {})
triton_poi_fused__softmax_1 = async_compile.triton('triton_poi_fused__softmax_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=[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__softmax_1', '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__softmax_1(in_ptr0, out_ptr0, 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_ptr0 + (4*x1), xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (2 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (3 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp3 = tmp1 + tmp2
    tmp5 = tmp3 + tmp4
    tmp7 = tmp5 + tmp6
    tmp8 = tmp0 / tmp7
    tl.store(out_ptr0 + (x2), tmp8, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/aj/cajnfn4dfbc6usnkqebmhnks35kkrodsrc3gynfsb56b5tcpnit4.py
# Topologically Sorted Source Nodes: [mul, s], Original ATen: [aten.mul, aten.sum]
# Source node to ATen node mapping:
#   mul => mul
#   s => sum_2
# Graph fragment:
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%unsqueeze, %primals_1), kwargs = {})
#   %sum_2 : [num_users=2] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul, [1]), kwargs = {})
triton_poi_fused_mul_sum_2 = async_compile.triton('triton_poi_fused_mul_sum_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.pointwise(
    size_hints=[64], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 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, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_mul_sum_2', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 8, '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_mul_sum_2(in_ptr0, in_ptr1, 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
    x2 = (xindex // 16)
    x3 = xindex % 16
    x4 = xindex
    tmp0 = tl.load(in_ptr0 + (x1), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (x3 + (64*x2)), xmask)
    tmp3 = tl.load(in_ptr0 + (4 + x1), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr1 + (16 + x3 + (64*x2)), xmask)
    tmp7 = tl.load(in_ptr0 + (8 + x1), xmask, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr1 + (32 + x3 + (64*x2)), xmask)
    tmp11 = tl.load(in_ptr0 + (12 + x1), xmask, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr1 + (48 + x3 + (64*x2)), xmask)
    tmp2 = tmp0 * tmp1
    tmp5 = tmp3 * tmp4
    tmp6 = tmp2 + tmp5
    tmp9 = tmp7 * tmp8
    tmp10 = tmp6 + tmp9
    tmp13 = tmp11 * tmp12
    tmp14 = tmp10 + tmp13
    tl.store(out_ptr0 + (x4), tmp14, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/6c/c6cxitoinplot2lb2nsqjxcfvoeulhjikauaic44zgpmnhn6m6dm.py
# Topologically Sorted Source Nodes: [x], Original ATen: [aten.mul]
# Source node to ATen node mapping:
#   x => mul_1
# Graph fragment:
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sum_2, %view), kwargs = {})
triton_poi_fused_mul_3 = async_compile.triton('triton_poi_fused_mul_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=[64], 
    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_mul_3', '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_mul_3(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 64
    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_ptr0 + (4*x1), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (1 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (2 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr0 + (3 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp2 = tmp1 * tmp1
    tmp4 = tmp3 * tmp3
    tmp5 = tmp2 + tmp4
    tmp7 = tmp6 * tmp6
    tmp8 = tmp5 + tmp7
    tmp10 = tmp9 * tmp9
    tmp11 = tmp8 + tmp10
    tmp12 = 1.0
    tmp13 = tmp11 + tmp12
    tmp14 = tmp11 / tmp13
    tmp15 = libdevice.sqrt(tmp11)
    tmp16 = tmp14 / tmp15
    tmp17 = tmp0 * tmp16
    tl.store(out_ptr0 + (x2), tmp17, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/tz/ctzkrdbwmdk4havssadppcim4uiewy6wtjyndwqkx4keavz6xu6j.py
# Topologically Sorted Source Nodes: [mul_2, sum_3, b_batch_1], Original ATen: [aten.mul, aten.sum, aten.add]
# Source node to ATen node mapping:
#   b_batch_1 => add_1
#   mul_2 => mul_2
#   sum_3 => sum_4
# Graph fragment:
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%primals_1, %unsqueeze_1), kwargs = {})
#   %sum_4 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_2, [-1]), kwargs = {})
#   %add_1 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%expand, %sum_4), kwargs = {})
triton_poi_fused_add_mul_sum_4 = async_compile.triton('triton_poi_fused_add_mul_sum_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=[64], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 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, 4), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_mul_sum_4', 'mutated_arg_names': [], '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_mul_sum_4(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex % 16
    x4 = xindex
    x0 = xindex % 4
    x2 = (xindex // 16)
    tmp0 = tl.load(in_ptr0 + (x3), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (4*x4), xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr2 + ((4*x0) + (16*x2)), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr1 + (1 + (4*x4)), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr2 + (1 + (4*x0) + (16*x2)), xmask, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr1 + (2 + (4*x4)), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr2 + (2 + (4*x0) + (16*x2)), xmask, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr1 + (3 + (4*x4)), xmask, eviction_policy='evict_last')
    tmp13 = tl.load(in_ptr2 + (3 + (4*x0) + (16*x2)), xmask, eviction_policy='evict_last')
    tmp3 = tmp1 * tmp2
    tmp6 = tmp4 * tmp5
    tmp7 = tmp3 + tmp6
    tmp10 = tmp8 * tmp9
    tmp11 = tmp7 + tmp10
    tmp14 = tmp12 * tmp13
    tmp15 = tmp11 + tmp14
    tmp16 = tmp0 + tmp15
    tl.store(out_ptr0 + (x4), tmp16, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/j7/cj7mv2k5l2kigfluq2rwwpouckm4oow7jia7wwvjogp3qlr23xwv.py
# Topologically Sorted Source Nodes: [softmax_1], Original ATen: [aten._softmax]
# Source node to ATen node mapping:
#   softmax_1 => amax_1, exp_1, sub_1
# Graph fragment:
#   %amax_1 : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%view_1, [1], True), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%view_1, %amax_1), kwargs = {})
#   %exp_1 : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub_1,), kwargs = {})
triton_poi_fused__softmax_5 = async_compile.triton('triton_poi_fused__softmax_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.pointwise(
    size_hints=[64], 
    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__softmax_5', '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__softmax_5(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 64
    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_ptr0 + (4*x1), xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (2 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (3 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp3 = triton_helpers.maximum(tmp1, tmp2)
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp0 - tmp7
    tmp9 = tl_math.exp(tmp8)
    tl.store(out_ptr0 + (x2), tmp9, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/b4/cb4vdtviarmy2ckmxjdkc3dnwp4gssl3dh4u4col3s2illvdpvql.py
# Topologically Sorted Source Nodes: [softmax_1], Original ATen: [aten._softmax]
# Source node to ATen node mapping:
#   softmax_1 => div_3, sum_5
# Graph fragment:
#   %sum_5 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp_1, [1], True), kwargs = {})
#   %div_3 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%exp_1, %sum_5), kwargs = {})
triton_poi_fused__softmax_6 = async_compile.triton('triton_poi_fused__softmax_6', '''
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=[64], 
    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__softmax_6', '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__softmax_6(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 64
    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_ptr0 + (4*x1), xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (2 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (3 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp3 = tmp1 + tmp2
    tmp5 = tmp3 + tmp4
    tmp7 = tmp5 + tmp6
    tmp8 = tmp0 / tmp7
    tl.store(out_ptr0 + (x2), tmp8, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/hk/chkymnmrtvm26agoxolleunayy4vpu2ntpnerpf3vgesh7nmasco.py
# Topologically Sorted Source Nodes: [mul_3, s_1], Original ATen: [aten.mul, aten.sum]
# Source node to ATen node mapping:
#   mul_3 => mul_3
#   s_1 => sum_6
# Graph fragment:
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%view_2, %primals_1), kwargs = {})
#   %sum_6 : [num_users=2] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_3, [1]), kwargs = {})
triton_poi_fused_mul_sum_7 = async_compile.triton('triton_poi_fused_mul_sum_7', '''
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=[64], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 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, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_mul_sum_7', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 8, '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_mul_sum_7(in_ptr0, in_ptr1, 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
    x2 = (xindex // 16)
    x3 = xindex % 16
    x4 = xindex
    tmp0 = tl.load(in_ptr0 + (x1 + (16*x2)), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (x3 + (64*x2)), xmask)
    tmp3 = tl.load(in_ptr0 + (4 + x1 + (16*x2)), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr1 + (16 + x3 + (64*x2)), xmask)
    tmp7 = tl.load(in_ptr0 + (8 + x1 + (16*x2)), xmask, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr1 + (32 + x3 + (64*x2)), xmask)
    tmp11 = tl.load(in_ptr0 + (12 + x1 + (16*x2)), xmask, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr1 + (48 + x3 + (64*x2)), xmask)
    tmp2 = tmp0 * tmp1
    tmp5 = tmp3 * tmp4
    tmp6 = tmp2 + tmp5
    tmp9 = tmp7 * tmp8
    tmp10 = tmp6 + tmp9
    tmp13 = tmp11 * tmp12
    tmp14 = tmp10 + tmp13
    tl.store(out_ptr0 + (x4), tmp14, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/wy/cwy6nwovy7yqtkn7mqqun5gnuovqjt4rhesigmga3qlwtxqxvuoo.py
# Topologically Sorted Source Nodes: [mul_5, sum_6, b_batch_2], Original ATen: [aten.mul, aten.sum, aten.add]
# Source node to ATen node mapping:
#   b_batch_2 => add_3
#   mul_5 => mul_5
#   sum_6 => sum_8
# Graph fragment:
#   %mul_5 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%primals_1, %unsqueeze_2), kwargs = {})
#   %sum_8 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_5, [-1]), kwargs = {})
#   %add_3 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_1, %sum_8), kwargs = {})
triton_poi_fused_add_mul_sum_8 = async_compile.triton('triton_poi_fused_add_mul_sum_8', '''
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=[64], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 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, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_mul_sum_8', '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_mul_sum_8(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK : tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 4
    x2 = (xindex // 16)
    tmp0 = tl.load(in_out_ptr0 + (x3), xmask)
    tmp1 = tl.load(in_ptr0 + (4*x3), xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr1 + ((4*x0) + (16*x2)), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (1 + (4*x3)), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr1 + (1 + (4*x0) + (16*x2)), xmask, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr0 + (2 + (4*x3)), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr1 + (2 + (4*x0) + (16*x2)), xmask, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr0 + (3 + (4*x3)), xmask, eviction_policy='evict_last')
    tmp13 = tl.load(in_ptr1 + (3 + (4*x0) + (16*x2)), xmask, eviction_policy='evict_last')
    tmp3 = tmp1 * tmp2
    tmp6 = tmp4 * tmp5
    tmp7 = tmp3 + tmp6
    tmp10 = tmp8 * tmp9
    tmp11 = tmp7 + tmp10
    tmp14 = tmp12 * tmp13
    tmp15 = tmp11 + tmp14
    tmp16 = tmp0 + tmp15
    tl.store(in_out_ptr0 + (x3), tmp16, xmask)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

def call(args):
    primals_1, primals_2 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (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: [c], Original ATen: [aten._softmax]
        stream0 = get_raw_stream(0)
        triton_poi_fused__softmax_0.run(primals_2, buf0, 16, grid=grid(16), stream=stream0)
        buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [c], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_1.run(buf0, buf1, 16, grid=grid(16), stream=stream0)
        del buf0
        buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [mul, s], Original ATen: [aten.mul, aten.sum]
        triton_poi_fused_mul_sum_2.run(buf1, primals_1, buf2, 64, grid=grid(64), stream=stream0)
        del buf1
        buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [x], Original ATen: [aten.mul]
        triton_poi_fused_mul_3.run(buf2, buf3, 64, grid=grid(64), stream=stream0)
        buf4 = buf2; del buf2  # reuse
        # Topologically Sorted Source Nodes: [mul_2, sum_3, b_batch_1], Original ATen: [aten.mul, aten.sum, aten.add]
        triton_poi_fused_add_mul_sum_4.run(primals_2, primals_1, buf3, buf4, 64, grid=grid(64), stream=stream0)
        buf5 = reinterpret_tensor(buf3, (16, 4), (4, 1), 0); del buf3  # reuse
        # Topologically Sorted Source Nodes: [softmax_1], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_5.run(buf4, buf5, 64, grid=grid(64), stream=stream0)
        buf6 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [softmax_1], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_6.run(buf5, buf6, 64, grid=grid(64), stream=stream0)
        buf7 = reinterpret_tensor(buf5, (4, 4, 4), (16, 4, 1), 0); del buf5  # reuse
        # Topologically Sorted Source Nodes: [mul_3, s_1], Original ATen: [aten.mul, aten.sum]
        triton_poi_fused_mul_sum_7.run(buf6, primals_1, buf7, 64, grid=grid(64), stream=stream0)
        buf8 = reinterpret_tensor(buf6, (4, 4, 4), (16, 4, 1), 0); del buf6  # reuse
        # Topologically Sorted Source Nodes: [x_1], Original ATen: [aten.mul]
        triton_poi_fused_mul_3.run(buf7, buf8, 64, grid=grid(64), stream=stream0)
        buf9 = buf4; del buf4  # reuse
        # Topologically Sorted Source Nodes: [mul_5, sum_6, b_batch_2], Original ATen: [aten.mul, aten.sum, aten.add]
        triton_poi_fused_add_mul_sum_8.run(buf9, primals_1, buf8, 64, grid=grid(64), stream=stream0)
        buf10 = reinterpret_tensor(buf8, (16, 4), (4, 1), 0); del buf8  # reuse
        # Topologically Sorted Source Nodes: [softmax_2], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_5.run(buf9, buf10, 64, grid=grid(64), stream=stream0)
        buf11 = reinterpret_tensor(buf7, (16, 4), (4, 1), 0); del buf7  # reuse
        # Topologically Sorted Source Nodes: [softmax_2], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_6.run(buf10, buf11, 64, grid=grid(64), stream=stream0)
        buf12 = reinterpret_tensor(buf10, (4, 4, 4), (16, 4, 1), 0); del buf10  # reuse
        # Topologically Sorted Source Nodes: [mul_6, s_2], Original ATen: [aten.mul, aten.sum]
        triton_poi_fused_mul_sum_7.run(buf11, primals_1, buf12, 64, grid=grid(64), stream=stream0)
        buf13 = reinterpret_tensor(buf11, (4, 4, 4), (16, 4, 1), 0); del buf11  # reuse
        # Topologically Sorted Source Nodes: [x_2], Original ATen: [aten.mul]
        triton_poi_fused_mul_3.run(buf12, buf13, 64, grid=grid(64), stream=stream0)
        buf14 = buf9; del buf9  # reuse
        # Topologically Sorted Source Nodes: [mul_8, sum_9, b_batch_3], Original ATen: [aten.mul, aten.sum, aten.add]
        triton_poi_fused_add_mul_sum_8.run(buf14, primals_1, buf13, 64, grid=grid(64), stream=stream0)
        buf15 = reinterpret_tensor(buf13, (16, 4), (4, 1), 0); del buf13  # reuse
        # Topologically Sorted Source Nodes: [softmax_3], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_5.run(buf14, buf15, 64, grid=grid(64), stream=stream0)
        buf16 = reinterpret_tensor(buf12, (16, 4), (4, 1), 0); del buf12  # reuse
        # Topologically Sorted Source Nodes: [softmax_3], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_6.run(buf15, buf16, 64, grid=grid(64), stream=stream0)
        buf17 = reinterpret_tensor(buf15, (4, 4, 4), (16, 4, 1), 0); del buf15  # reuse
        # Topologically Sorted Source Nodes: [mul_9, s_3], Original ATen: [aten.mul, aten.sum]
        triton_poi_fused_mul_sum_7.run(buf16, primals_1, buf17, 64, grid=grid(64), stream=stream0)
        buf18 = reinterpret_tensor(buf16, (4, 4, 4), (16, 4, 1), 0); del buf16  # reuse
        # Topologically Sorted Source Nodes: [x_3], Original ATen: [aten.mul]
        triton_poi_fused_mul_3.run(buf17, buf18, 64, grid=grid(64), stream=stream0)
        del buf17
        buf19 = buf14; del buf14  # reuse
        # Topologically Sorted Source Nodes: [mul_11, sum_12, b_batch_4], Original ATen: [aten.mul, aten.sum, aten.add]
        triton_poi_fused_add_mul_sum_8.run(buf19, primals_1, buf18, 64, grid=grid(64), stream=stream0)
        buf20 = reinterpret_tensor(buf18, (16, 4), (4, 1), 0); del buf18  # reuse
        # Topologically Sorted Source Nodes: [softmax_4], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_5.run(buf19, buf20, 64, grid=grid(64), stream=stream0)
        buf21 = reinterpret_tensor(buf19, (16, 4), (4, 1), 0); del buf19  # reuse
        # Topologically Sorted Source Nodes: [softmax_4], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_6.run(buf20, buf21, 64, grid=grid(64), stream=stream0)
        buf22 = reinterpret_tensor(buf20, (4, 4, 4), (16, 4, 1), 0); del buf20  # reuse
        # Topologically Sorted Source Nodes: [mul_12, s_4], Original ATen: [aten.mul, aten.sum]
        triton_poi_fused_mul_sum_7.run(buf21, primals_1, buf22, 64, grid=grid(64), stream=stream0)
        buf23 = reinterpret_tensor(buf21, (4, 4, 4), (16, 4, 1), 0); del buf21  # reuse
        # Topologically Sorted Source Nodes: [x_4], Original ATen: [aten.mul]
        triton_poi_fused_mul_3.run(buf22, buf23, 64, grid=grid(64), stream=stream0)
        del buf22
    return (buf23, primals_1, primals_2, )


def benchmark_compiled_module(times=10, repeat=10):
    from torch._dynamo.testing import rand_strided
    from torch._inductor.utils import print_performance
    primals_1 = rand_strided((4, 4, 4, 4), (64, 16, 4, 1), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((4, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([primals_1, primals_2])
    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
import torch.nn.functional as F


def squash(x):
    lengths2 = x.pow(2).sum(dim=2)
    lengths = lengths2.sqrt()
    x = x * (lengths2 / (1 + lengths2) / lengths).view(x.size(0), x.size(1), 1)
    return x


class AgreementRouting(nn.Module):

    def __init__(self, input_caps, output_caps, n_iterations):
        super(AgreementRouting, self).__init__()
        self.n_iterations = n_iterations
        self.b = nn.Parameter(torch.zeros((input_caps, output_caps)))

    def forward(self, u_predict):
        batch_size, input_caps, output_caps, _output_dim = u_predict.size()
        c = F.softmax(self.b)
        s = (c.unsqueeze(2) * u_predict).sum(dim=1)
        v = squash(s)
        if self.n_iterations > 0:
            b_batch = self.b.expand((batch_size, input_caps, output_caps))
            for r in range(self.n_iterations):
                v = v.unsqueeze(1)
                b_batch = b_batch + (u_predict * v).sum(-1)
                c = F.softmax(b_batch.view(-1, output_caps)).view(-1,
                    input_caps, output_caps, 1)
                s = (c * u_predict).sum(dim=1)
                v = squash(s)
        return v


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


def get_init_inputs():
    return [[], {'input_caps': 4, 'output_caps': 4, 'n_iterations': 4}]

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
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_0(in_ptr0, out_ptr0, 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_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp3 = triton_helpers.maximum(tmp1, tmp2)
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp0 - tmp7
    tmp9 = tl_math.exp(tmp8)
    tl.store(out_ptr0 + x2, tmp9, xmask)


@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, 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_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp3 = tmp1 + tmp2
    tmp5 = tmp3 + tmp4
    tmp7 = tmp5 + tmp6
    tmp8 = tmp0 / tmp7
    tl.store(out_ptr0 + x2, tmp8, xmask)


@triton.jit
def triton_poi_fused_mul_sum_2(in_ptr0, in_ptr1, 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
    x2 = xindex // 16
    x3 = xindex % 16
    x4 = xindex
    tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (x3 + 64 * x2), xmask)
    tmp3 = tl.load(in_ptr0 + (4 + x1), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr1 + (16 + x3 + 64 * x2), xmask)
    tmp7 = tl.load(in_ptr0 + (8 + x1), xmask, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr1 + (32 + x3 + 64 * x2), xmask)
    tmp11 = tl.load(in_ptr0 + (12 + x1), xmask, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr1 + (48 + x3 + 64 * x2), xmask)
    tmp2 = tmp0 * tmp1
    tmp5 = tmp3 * tmp4
    tmp6 = tmp2 + tmp5
    tmp9 = tmp7 * tmp8
    tmp10 = tmp6 + tmp9
    tmp13 = tmp11 * tmp12
    tmp14 = tmp10 + tmp13
    tl.store(out_ptr0 + x4, tmp14, xmask)


@triton.jit
def triton_poi_fused_mul_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    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_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp2 = tmp1 * tmp1
    tmp4 = tmp3 * tmp3
    tmp5 = tmp2 + tmp4
    tmp7 = tmp6 * tmp6
    tmp8 = tmp5 + tmp7
    tmp10 = tmp9 * tmp9
    tmp11 = tmp8 + tmp10
    tmp12 = 1.0
    tmp13 = tmp11 + tmp12
    tmp14 = tmp11 / tmp13
    tmp15 = libdevice.sqrt(tmp11)
    tmp16 = tmp14 / tmp15
    tmp17 = tmp0 * tmp16
    tl.store(out_ptr0 + x2, tmp17, xmask)


@triton.jit
def triton_poi_fused_add_mul_sum_4(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex % 16
    x4 = xindex
    x0 = xindex % 4
    x2 = xindex // 16
    tmp0 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + 4 * x4, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr2 + (4 * x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp4 = tl.load(in_ptr1 + (1 + 4 * x4), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr2 + (1 + 4 * x0 + 16 * x2), xmask, eviction_policy
        ='evict_last')
    tmp8 = tl.load(in_ptr1 + (2 + 4 * x4), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr2 + (2 + 4 * x0 + 16 * x2), xmask, eviction_policy
        ='evict_last')
    tmp12 = tl.load(in_ptr1 + (3 + 4 * x4), xmask, eviction_policy='evict_last'
        )
    tmp13 = tl.load(in_ptr2 + (3 + 4 * x0 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp3 = tmp1 * tmp2
    tmp6 = tmp4 * tmp5
    tmp7 = tmp3 + tmp6
    tmp10 = tmp8 * tmp9
    tmp11 = tmp7 + tmp10
    tmp14 = tmp12 * tmp13
    tmp15 = tmp11 + tmp14
    tmp16 = tmp0 + tmp15
    tl.store(out_ptr0 + x4, tmp16, xmask)


@triton.jit
def triton_poi_fused__softmax_5(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 64
    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_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp3 = triton_helpers.maximum(tmp1, tmp2)
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp0 - tmp7
    tmp9 = tl_math.exp(tmp8)
    tl.store(out_ptr0 + x2, tmp9, xmask)


@triton.jit
def triton_poi_fused__softmax_6(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 64
    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_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp3 = tmp1 + tmp2
    tmp5 = tmp3 + tmp4
    tmp7 = tmp5 + tmp6
    tmp8 = tmp0 / tmp7
    tl.store(out_ptr0 + x2, tmp8, xmask)


@triton.jit
def triton_poi_fused_mul_sum_7(in_ptr0, in_ptr1, 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
    x2 = xindex // 16
    x3 = xindex % 16
    x4 = xindex
    tmp0 = tl.load(in_ptr0 + (x1 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp1 = tl.load(in_ptr1 + (x3 + 64 * x2), xmask)
    tmp3 = tl.load(in_ptr0 + (4 + x1 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp4 = tl.load(in_ptr1 + (16 + x3 + 64 * x2), xmask)
    tmp7 = tl.load(in_ptr0 + (8 + x1 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp8 = tl.load(in_ptr1 + (32 + x3 + 64 * x2), xmask)
    tmp11 = tl.load(in_ptr0 + (12 + x1 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp12 = tl.load(in_ptr1 + (48 + x3 + 64 * x2), xmask)
    tmp2 = tmp0 * tmp1
    tmp5 = tmp3 * tmp4
    tmp6 = tmp2 + tmp5
    tmp9 = tmp7 * tmp8
    tmp10 = tmp6 + tmp9
    tmp13 = tmp11 * tmp12
    tmp14 = tmp10 + tmp13
    tl.store(out_ptr0 + x4, tmp14, xmask)


@triton.jit
def triton_poi_fused_add_mul_sum_8(in_out_ptr0, in_ptr0, in_ptr1, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 4
    x2 = xindex // 16
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + 4 * x3, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr1 + (4 * x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp4 = tl.load(in_ptr0 + (1 + 4 * x3), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr1 + (1 + 4 * x0 + 16 * x2), xmask, eviction_policy
        ='evict_last')
    tmp8 = tl.load(in_ptr0 + (2 + 4 * x3), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr1 + (2 + 4 * x0 + 16 * x2), xmask, eviction_policy
        ='evict_last')
    tmp12 = tl.load(in_ptr0 + (3 + 4 * x3), xmask, eviction_policy='evict_last'
        )
    tmp13 = tl.load(in_ptr1 + (3 + 4 * x0 + 16 * x2), xmask,
        eviction_policy='evict_last')
    tmp3 = tmp1 * tmp2
    tmp6 = tmp4 * tmp5
    tmp7 = tmp3 + tmp6
    tmp10 = tmp8 * tmp9
    tmp11 = tmp7 + tmp10
    tmp14 = tmp12 * tmp13
    tmp15 = tmp11 + tmp14
    tmp16 = tmp0 + tmp15
    tl.store(in_out_ptr0 + x3, tmp16, xmask)


def call(args):
    primals_1, primals_2 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused__softmax_0[grid(16)](primals_2, buf0, 16, XBLOCK=
            16, num_warps=1, num_stages=1)
        buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused__softmax_1[grid(16)](buf0, buf1, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        del buf0
        buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_mul_sum_2[grid(64)](buf1, primals_1, buf2, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        del buf1
        buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_mul_3[grid(64)](buf2, buf3, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf4 = buf2
        del buf2
        triton_poi_fused_add_mul_sum_4[grid(64)](primals_2, primals_1, buf3,
            buf4, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf5 = reinterpret_tensor(buf3, (16, 4), (4, 1), 0)
        del buf3
        triton_poi_fused__softmax_5[grid(64)](buf4, buf5, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf6 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        triton_poi_fused__softmax_6[grid(64)](buf5, buf6, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf7 = reinterpret_tensor(buf5, (4, 4, 4), (16, 4, 1), 0)
        del buf5
        triton_poi_fused_mul_sum_7[grid(64)](buf6, primals_1, buf7, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        buf8 = reinterpret_tensor(buf6, (4, 4, 4), (16, 4, 1), 0)
        del buf6
        triton_poi_fused_mul_3[grid(64)](buf7, buf8, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf9 = buf4
        del buf4
        triton_poi_fused_add_mul_sum_8[grid(64)](buf9, primals_1, buf8, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        buf10 = reinterpret_tensor(buf8, (16, 4), (4, 1), 0)
        del buf8
        triton_poi_fused__softmax_5[grid(64)](buf9, buf10, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf11 = reinterpret_tensor(buf7, (16, 4), (4, 1), 0)
        del buf7
        triton_poi_fused__softmax_6[grid(64)](buf10, buf11, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf12 = reinterpret_tensor(buf10, (4, 4, 4), (16, 4, 1), 0)
        del buf10
        triton_poi_fused_mul_sum_7[grid(64)](buf11, primals_1, buf12, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        buf13 = reinterpret_tensor(buf11, (4, 4, 4), (16, 4, 1), 0)
        del buf11
        triton_poi_fused_mul_3[grid(64)](buf12, buf13, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf14 = buf9
        del buf9
        triton_poi_fused_add_mul_sum_8[grid(64)](buf14, primals_1, buf13, 
            64, XBLOCK=64, num_warps=1, num_stages=1)
        buf15 = reinterpret_tensor(buf13, (16, 4), (4, 1), 0)
        del buf13
        triton_poi_fused__softmax_5[grid(64)](buf14, buf15, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf16 = reinterpret_tensor(buf12, (16, 4), (4, 1), 0)
        del buf12
        triton_poi_fused__softmax_6[grid(64)](buf15, buf16, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf17 = reinterpret_tensor(buf15, (4, 4, 4), (16, 4, 1), 0)
        del buf15
        triton_poi_fused_mul_sum_7[grid(64)](buf16, primals_1, buf17, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        buf18 = reinterpret_tensor(buf16, (4, 4, 4), (16, 4, 1), 0)
        del buf16
        triton_poi_fused_mul_3[grid(64)](buf17, buf18, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        del buf17
        buf19 = buf14
        del buf14
        triton_poi_fused_add_mul_sum_8[grid(64)](buf19, primals_1, buf18, 
            64, XBLOCK=64, num_warps=1, num_stages=1)
        buf20 = reinterpret_tensor(buf18, (16, 4), (4, 1), 0)
        del buf18
        triton_poi_fused__softmax_5[grid(64)](buf19, buf20, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf21 = reinterpret_tensor(buf19, (16, 4), (4, 1), 0)
        del buf19
        triton_poi_fused__softmax_6[grid(64)](buf20, buf21, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf22 = reinterpret_tensor(buf20, (4, 4, 4), (16, 4, 1), 0)
        del buf20
        triton_poi_fused_mul_sum_7[grid(64)](buf21, primals_1, buf22, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        buf23 = reinterpret_tensor(buf21, (4, 4, 4), (16, 4, 1), 0)
        del buf21
        triton_poi_fused_mul_3[grid(64)](buf22, buf23, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        del buf22
    return buf23, primals_1, primals_2


def squash(x):
    lengths2 = x.pow(2).sum(dim=2)
    lengths = lengths2.sqrt()
    x = x * (lengths2 / (1 + lengths2) / lengths).view(x.size(0), x.size(1), 1)
    return x


class AgreementRoutingNew(nn.Module):

    def __init__(self, input_caps, output_caps, n_iterations):
        super(AgreementRoutingNew, self).__init__()
        self.n_iterations = n_iterations
        self.b = nn.Parameter(torch.zeros((input_caps, output_caps)))

    def forward(self, input_0):
        primals_2 = self.b
        primals_1 = input_0
        output = call([primals_1, primals_2])
        return output[0]
