# 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/ar/carmia3wh3a4soirr2hwld2ewi75pvcghm4jka76mzx45462dleq.py
# Topologically Sorted Source Nodes: [g1], Original ATen: [aten.clone, aten._unsafe_view]
# Source node to ATen node mapping:
#   g1 => clone, view
# Graph fragment:
#   %clone : [num_users=1] = call_function[target=torch.ops.aten.clone.default](args = (%slice_2,), kwargs = {memory_format: torch.contiguous_format})
#   %view : [num_users=2] = call_function[target=torch.ops.aten.reshape.default](args = (%clone, [8, 4]), kwargs = {})
triton_poi_fused__unsafe_view_clone_0 = async_compile.triton('triton_poi_fused__unsafe_view_clone_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=[32], 
    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__unsafe_view_clone_0', '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},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused__unsafe_view_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 32
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 4
    x1 = (xindex // 4)
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + (4*(x1 % 2)) + (16*(x1 // 2))), xmask)
    tl.store(out_ptr0 + (x2), tmp0, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/ht/chtw7yb2aeiwqf7e6wcciqo5cs7snfwq55c2zmy7756abjt5odwg.py
# Topologically Sorted Source Nodes: [g2], Original ATen: [aten.clone, aten._unsafe_view]
# Source node to ATen node mapping:
#   g2 => clone_1, view_2
# Graph fragment:
#   %clone_1 : [num_users=1] = call_function[target=torch.ops.aten.clone.default](args = (%slice_4,), kwargs = {memory_format: torch.contiguous_format})
#   %view_2 : [num_users=2] = call_function[target=torch.ops.aten.reshape.default](args = (%clone_1, [8, 4]), kwargs = {})
triton_poi_fused__unsafe_view_clone_1 = async_compile.triton('triton_poi_fused__unsafe_view_clone_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=[32], 
    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__unsafe_view_clone_1', '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},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused__unsafe_view_clone_1(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 32
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 4
    x1 = (xindex // 4)
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (4 + x0 + (4*(x1 % 2)) + (16*(x1 // 2))), xmask)
    tl.store(out_ptr0 + (x2), tmp0, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/6y/c6yrrdc2nauu5gzytu6guntvth4pajjmsnsfsjwimejql5e62rme.py
# Topologically Sorted Source Nodes: [g3], Original ATen: [aten.clone, aten._unsafe_view]
# Source node to ATen node mapping:
#   g3 => clone_2, view_4
# Graph fragment:
#   %clone_2 : [num_users=1] = call_function[target=torch.ops.aten.clone.default](args = (%slice_6,), kwargs = {memory_format: torch.contiguous_format})
#   %view_4 : [num_users=2] = call_function[target=torch.ops.aten.reshape.default](args = (%clone_2, [8, 4]), kwargs = {})
triton_poi_fused__unsafe_view_clone_2 = async_compile.triton('triton_poi_fused__unsafe_view_clone_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=[32], 
    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__unsafe_view_clone_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},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused__unsafe_view_clone_2(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 32
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 4
    x1 = (xindex // 4)
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (8 + x0 + (4*(x1 % 2)) + (16*(x1 // 2))), xmask)
    tl.store(out_ptr0 + (x2), tmp0, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/u5/cu54wdpiiawrisqv7ugmuf666653hkp2zredg43wlga6qn64lsbl.py
# Topologically Sorted Source Nodes: [mul, temp01], Original ATen: [aten.mul]
# Source node to ATen node mapping:
#   mul => mul
#   temp01 => mul_1
# Graph fragment:
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%view_1, %view_3), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul, %view_5), 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=[4096], 
    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_mul_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_mul_3(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 3168
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (x0), xmask)
    tmp1 = tl.load(in_ptr1 + (x0), xmask)
    tmp3 = tl.load(in_ptr2 + (x0), xmask)
    tmp2 = tmp0 * tmp1
    tmp4 = tmp2 * tmp3
    tl.store(out_ptr0 + (x0), tmp4, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/oj/cojedjn2cyrz3u5rpahykrfq5sui4tyzd4aus2aip6rvwrpymfzj.py
# Topologically Sorted Source Nodes: [temp02], Original ATen: [aten.mul]
# Source node to ATen node mapping:
#   temp02 => mul_2, mul_3
# Graph fragment:
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%permute, %permute_1), kwargs = {})
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%permute_2, %mul_2), kwargs = {})
triton_poi_fused_mul_4 = async_compile.triton('triton_poi_fused_mul_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=[32768], 
    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_mul_4', '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_mul_4(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 25344
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x5 = xindex % 1584
    x0 = xindex % 396
    x3 = (xindex // 6336)
    x2 = (xindex // 1584) % 4
    x4 = (xindex // 1584)
    tmp0 = tl.load(in_ptr0 + (x5), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (x0 + (396*x3)), xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr2 + (x0 + (396*x2)), xmask, eviction_policy='evict_last')
    tmp3 = tmp1 * tmp2
    tmp4 = tmp0 * tmp3
    tl.store(out_ptr0 + (x5 + (1600*x4)), tmp4, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/jy/cjyih4xrikzd7ipfrh25genasic2vujoqtxwqanglf4xqxvltqos.py
# Topologically Sorted Source Nodes: [score], Original ATen: [aten.bmm, aten.transpose]
# Source node to ATen node mapping:
#   score => bmm
# Graph fragment:
#   %bmm : [num_users=1] = call_function[target=torch.ops.aten.bmm.default](args = (%view_6, %view_7), kwargs = {})
#   %permute_10 : [num_users=1] = call_function[target=torch.ops.aten.permute.default](args = (%view_7, [0, 2, 1]), kwargs = {})
triton_poi_fused_bmm_transpose_5 = async_compile.triton('triton_poi_fused_bmm_transpose_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=[32768], 
    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_bmm_transpose_5', '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},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_bmm_transpose_5(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK : tl.constexpr):
    xnumel = 25344
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 396
    x1 = (xindex // 396)
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + (396*(x1 % 4)) + (1600*(x1 // 4))), xmask)
    tl.store(out_ptr0 + (x2), tmp0, xmask)
    tl.store(out_ptr1 + (x2), tmp0, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_7/inductor_cache/4g/c4guh5fiotlbffthmqf7v7xrn4nvwh2cb5ppnveaklu6nk2lqe3f.py
# Topologically Sorted Source Nodes: [score_1], Original ATen: [aten.div]
# Source node to ATen node mapping:
#   score_1 => div
# Graph fragment:
#   %div : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%view_9, 19.8997487421324), kwargs = {})
triton_poi_fused_div_6 = async_compile.triton('triton_poi_fused_div_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=[512], 
    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, 1), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_div_6', 'mutated_arg_names': ['in_out_ptr0'], '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},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_div_6(in_out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 512
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_out_ptr0 + (x0), xmask)
    tmp1 = 0.050251890762960605
    tmp2 = tmp0 * tmp1
    tl.store(in_out_ptr0 + (x0), tmp2, xmask)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_2, (4, 396), (396, 1))
    assert_size_stride(primals_3, (4, 396), (396, 1))
    assert_size_stride(primals_4, (4, 396), (396, 1))
    assert_size_stride(primals_5, (4, 20), (20, 1))
    assert_size_stride(primals_6, (20, 396), (396, 1))
    assert_size_stride(primals_7, (20, 396), (396, 1))
    assert_size_stride(primals_8, (20, 396), (396, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((8, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [g1], Original ATen: [aten.clone, aten._unsafe_view]
        stream0 = get_raw_stream(0)
        triton_poi_fused__unsafe_view_clone_0.run(primals_1, buf0, 32, grid=grid(32), stream=stream0)
        buf1 = empty_strided_cuda((8, 396), (396, 1), torch.float32)
        # Topologically Sorted Source Nodes: [g1], Original ATen: [aten.mm]
        extern_kernels.mm(buf0, primals_2, out=buf1)
        del primals_2
        buf2 = empty_strided_cuda((8, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [g2], Original ATen: [aten.clone, aten._unsafe_view]
        triton_poi_fused__unsafe_view_clone_1.run(primals_1, buf2, 32, grid=grid(32), stream=stream0)
        buf3 = empty_strided_cuda((8, 396), (396, 1), torch.float32)
        # Topologically Sorted Source Nodes: [g2], Original ATen: [aten.mm]
        extern_kernels.mm(buf2, primals_3, out=buf3)
        del primals_3
        buf4 = empty_strided_cuda((8, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [g3], Original ATen: [aten.clone, aten._unsafe_view]
        triton_poi_fused__unsafe_view_clone_2.run(primals_1, buf4, 32, grid=grid(32), stream=stream0)
        del primals_1
        buf5 = empty_strided_cuda((8, 396), (396, 1), torch.float32)
        # Topologically Sorted Source Nodes: [g3], Original ATen: [aten.mm]
        extern_kernels.mm(buf4, primals_4, out=buf5)
        del primals_4
        buf6 = empty_strided_cuda((4, 396), (396, 1), torch.float32)
        # Topologically Sorted Source Nodes: [g4], Original ATen: [aten.mm]
        extern_kernels.mm(primals_5, primals_6, out=buf6)
        buf7 = empty_strided_cuda((4, 396), (396, 1), torch.float32)
        # Topologically Sorted Source Nodes: [g5], Original ATen: [aten.mm]
        extern_kernels.mm(primals_5, primals_7, out=buf7)
        buf8 = empty_strided_cuda((4, 396), (396, 1), torch.float32)
        # Topologically Sorted Source Nodes: [g6], Original ATen: [aten.mm]
        extern_kernels.mm(primals_5, primals_8, out=buf8)
        buf9 = empty_strided_cuda((4, 2, 396), (792, 396, 1), torch.float32)
        # Topologically Sorted Source Nodes: [mul, temp01], Original ATen: [aten.mul]
        triton_poi_fused_mul_3.run(buf1, buf3, buf5, buf9, 3168, grid=grid(3168), stream=stream0)
        buf10 = empty_strided_cuda((4, 4, 4, 396), (6400, 1600, 396, 1), torch.float32)
        # Topologically Sorted Source Nodes: [temp02], Original ATen: [aten.mul]
        triton_poi_fused_mul_4.run(buf8, buf6, buf7, buf10, 25344, grid=grid(25344), stream=stream0)
        buf11 = empty_strided_cuda((1, 396, 64), (25344, 1, 396), torch.float32)
        buf14 = empty_strided_cuda((1, 64, 396), (25344, 396, 1), torch.float32)
        # Topologically Sorted Source Nodes: [score], Original ATen: [aten.bmm, aten.transpose]
        triton_poi_fused_bmm_transpose_5.run(buf10, buf11, buf14, 25344, grid=grid(25344), stream=stream0)
        del buf10
        buf12 = empty_strided_cuda((1, 8, 64), (512, 64, 1), torch.float32)
        # Topologically Sorted Source Nodes: [score], Original ATen: [aten.bmm]
        extern_kernels.bmm(reinterpret_tensor(buf9, (1, 8, 396), (0, 396, 1), 0), buf11, out=buf12)
        del buf11
        buf13 = reinterpret_tensor(buf12, (4, 2, 4, 4, 4), (128, 64, 16, 4, 1), 0); del buf12  # reuse
        # Topologically Sorted Source Nodes: [score_1], Original ATen: [aten.div]
        triton_poi_fused_div_6.run(buf13, 512, grid=grid(512), stream=stream0)
    return (buf13, buf1, buf3, buf5, buf6, buf7, buf8, reinterpret_tensor(buf9, (1, 396, 8), (3168, 1, 396), 0), buf14, reinterpret_tensor(primals_5, (20, 4), (1, 20), 0), reinterpret_tensor(primals_8, (396, 20), (1, 396), 0), reinterpret_tensor(primals_7, (396, 20), (1, 396), 0), reinterpret_tensor(primals_6, (396, 20), (1, 396), 0), reinterpret_tensor(buf4, (4, 8), (1, 4), 0), reinterpret_tensor(buf2, (4, 8), (1, 4), 0), reinterpret_tensor(buf0, (4, 8), (1, 4), 0), )


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), (16, 4, 1), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((4, 396), (396, 1), device='cuda:0', dtype=torch.float32)
    primals_3 = rand_strided((4, 396), (396, 1), device='cuda:0', dtype=torch.float32)
    primals_4 = rand_strided((4, 396), (396, 1), device='cuda:0', dtype=torch.float32)
    primals_5 = rand_strided((4, 20), (20, 1), device='cuda:0', dtype=torch.float32)
    primals_6 = rand_strided((20, 396), (396, 1), device='cuda:0', dtype=torch.float32)
    primals_7 = rand_strided((20, 396), (396, 1), device='cuda:0', dtype=torch.float32)
    primals_8 = rand_strided((20, 396), (396, 1), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8])
    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 math
import torch
import torch.nn as nn
import torch.utils.data.dataloader
import torch.nn


class HexaLinearScore(nn.Module):
    """
    Outer product version of hexalinear function for sequence labeling.
    """

    def __init__(self, wemb_size, tagset_size, temb_size=20, rank=396, std=
        0.1545, normalization=True, **kwargs):
        """
        Args:
            wemb_size: word embedding hidden size
            tagset_size: tag set size
            temb_size: tag embedding size
            rank: rank of the weight tensor
            std: standard deviation of the tensor
        """
        super(HexaLinearScore, self).__init__()
        self.wemb_size = wemb_size
        self.tagset_size = tagset_size
        self.temb_size = temb_size
        self.rank = rank
        self.std = std
        self.normalization = normalization
        self.tag_emd = nn.Parameter(torch.Tensor(self.tagset_size, self.
            temb_size))
        self.W1 = nn.Parameter(torch.Tensor(self.wemb_size, self.rank))
        self.W2 = nn.Parameter(torch.Tensor(self.wemb_size, self.rank))
        self.W3 = nn.Parameter(torch.Tensor(self.wemb_size, self.rank))
        self.T1 = nn.Parameter(torch.Tensor(self.temb_size, self.rank))
        self.T2 = nn.Parameter(torch.Tensor(self.temb_size, self.rank))
        self.T3 = nn.Parameter(torch.Tensor(self.temb_size, self.rank))
        self.rand_init()
        self

    def rand_init(self):
        """random initialization
        """
        nn.init.uniform_(self.tag_emd, a=math.sqrt(6 / self.temb_size), b=
            math.sqrt(6 / self.temb_size))
        nn.init.normal_(self.T1, std=self.std)
        nn.init.normal_(self.T2, std=self.std)
        nn.init.normal_(self.T3, std=self.std)
        nn.init.normal_(self.W1, std=self.std)
        nn.init.normal_(self.W2, std=self.std)
        nn.init.normal_(self.W3, std=self.std)

    def forward(self, word_emb):
        """
        Args:
            word_emb: [batch, sent_length, wemb_size]
        Returns: Tensor
            [batch, sent_length-window_size, tagset_size, tagset_size]
        """
        assert word_emb.size(2
            ) == self.wemb_size, 'batch sizes of encoder and decoder are requires to be equal.'
        g1 = torch.matmul(word_emb[:, :-2], self.W1)
        g2 = torch.matmul(word_emb[:, 1:-1], self.W2)
        g3 = torch.matmul(word_emb[:, 2:], self.W3)
        g4 = torch.matmul(self.tag_emd, self.T1)
        g5 = torch.matmul(self.tag_emd, self.T2)
        g6 = torch.matmul(self.tag_emd, self.T3)
        temp01 = g1 * g2 * g3
        temp02 = torch.einsum('ak,bk,ck->abck', [g4, g5, g6])
        score = torch.einsum('nmk,abck->nmabc', [temp01, temp02])
        if self.normalization:
            score = score / math.sqrt(self.rank)
        return score


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


def get_init_inputs():
    return [[], {'wemb_size': 4, 'tagset_size': 4}]

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
import math
import torch.nn as nn
import torch.utils.data.dataloader
import torch.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__unsafe_view_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 32
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 4
    x1 = xindex // 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 4 * (x1 % 2) + 16 * (x1 // 2)), xmask)
    tl.store(out_ptr0 + x2, tmp0, xmask)


@triton.jit
def triton_poi_fused__unsafe_view_clone_1(in_ptr0, out_ptr0, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 32
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 4
    x1 = xindex // 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (4 + x0 + 4 * (x1 % 2) + 16 * (x1 // 2)), xmask)
    tl.store(out_ptr0 + x2, tmp0, xmask)


@triton.jit
def triton_poi_fused__unsafe_view_clone_2(in_ptr0, out_ptr0, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 32
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 4
    x1 = xindex // 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (8 + x0 + 4 * (x1 % 2) + 16 * (x1 // 2)), xmask)
    tl.store(out_ptr0 + x2, tmp0, xmask)


@triton.jit
def triton_poi_fused_mul_3(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 3168
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask)
    tmp3 = tl.load(in_ptr2 + x0, xmask)
    tmp2 = tmp0 * tmp1
    tmp4 = tmp2 * tmp3
    tl.store(out_ptr0 + x0, tmp4, xmask)


@triton.jit
def triton_poi_fused_mul_4(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 25344
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x5 = xindex % 1584
    x0 = xindex % 396
    x3 = xindex // 6336
    x2 = xindex // 1584 % 4
    x4 = xindex // 1584
    tmp0 = tl.load(in_ptr0 + x5, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (x0 + 396 * x3), xmask, eviction_policy=
        'evict_last')
    tmp2 = tl.load(in_ptr2 + (x0 + 396 * x2), xmask, eviction_policy=
        'evict_last')
    tmp3 = tmp1 * tmp2
    tmp4 = tmp0 * tmp3
    tl.store(out_ptr0 + (x5 + 1600 * x4), tmp4, xmask)


@triton.jit
def triton_poi_fused_bmm_transpose_5(in_ptr0, out_ptr0, out_ptr1, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 25344
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 396
    x1 = xindex // 396
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 396 * (x1 % 4) + 1600 * (x1 // 4)), xmask)
    tl.store(out_ptr0 + x2, tmp0, xmask)
    tl.store(out_ptr1 + x2, tmp0, xmask)


@triton.jit
def triton_poi_fused_div_6(in_out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 512
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_out_ptr0 + x0, xmask)
    tmp1 = 0.050251890762960605
    tmp2 = tmp0 * tmp1
    tl.store(in_out_ptr0 + x0, tmp2, xmask)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_2, (4, 396), (396, 1))
    assert_size_stride(primals_3, (4, 396), (396, 1))
    assert_size_stride(primals_4, (4, 396), (396, 1))
    assert_size_stride(primals_5, (4, 20), (20, 1))
    assert_size_stride(primals_6, (20, 396), (396, 1))
    assert_size_stride(primals_7, (20, 396), (396, 1))
    assert_size_stride(primals_8, (20, 396), (396, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((8, 4), (4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused__unsafe_view_clone_0[grid(32)](primals_1, buf0, 32,
            XBLOCK=32, num_warps=1, num_stages=1)
        buf1 = empty_strided_cuda((8, 396), (396, 1), torch.float32)
        extern_kernels.mm(buf0, primals_2, out=buf1)
        del primals_2
        buf2 = empty_strided_cuda((8, 4), (4, 1), torch.float32)
        triton_poi_fused__unsafe_view_clone_1[grid(32)](primals_1, buf2, 32,
            XBLOCK=32, num_warps=1, num_stages=1)
        buf3 = empty_strided_cuda((8, 396), (396, 1), torch.float32)
        extern_kernels.mm(buf2, primals_3, out=buf3)
        del primals_3
        buf4 = empty_strided_cuda((8, 4), (4, 1), torch.float32)
        triton_poi_fused__unsafe_view_clone_2[grid(32)](primals_1, buf4, 32,
            XBLOCK=32, num_warps=1, num_stages=1)
        del primals_1
        buf5 = empty_strided_cuda((8, 396), (396, 1), torch.float32)
        extern_kernels.mm(buf4, primals_4, out=buf5)
        del primals_4
        buf6 = empty_strided_cuda((4, 396), (396, 1), torch.float32)
        extern_kernels.mm(primals_5, primals_6, out=buf6)
        buf7 = empty_strided_cuda((4, 396), (396, 1), torch.float32)
        extern_kernels.mm(primals_5, primals_7, out=buf7)
        buf8 = empty_strided_cuda((4, 396), (396, 1), torch.float32)
        extern_kernels.mm(primals_5, primals_8, out=buf8)
        buf9 = empty_strided_cuda((4, 2, 396), (792, 396, 1), torch.float32)
        triton_poi_fused_mul_3[grid(3168)](buf1, buf3, buf5, buf9, 3168,
            XBLOCK=128, num_warps=4, num_stages=1)
        buf10 = empty_strided_cuda((4, 4, 4, 396), (6400, 1600, 396, 1),
            torch.float32)
        triton_poi_fused_mul_4[grid(25344)](buf8, buf6, buf7, buf10, 25344,
            XBLOCK=128, num_warps=4, num_stages=1)
        buf11 = empty_strided_cuda((1, 396, 64), (25344, 1, 396), torch.float32
            )
        buf14 = empty_strided_cuda((1, 64, 396), (25344, 396, 1), torch.float32
            )
        triton_poi_fused_bmm_transpose_5[grid(25344)](buf10, buf11, buf14, 
            25344, XBLOCK=128, num_warps=4, num_stages=1)
        del buf10
        buf12 = empty_strided_cuda((1, 8, 64), (512, 64, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf9, (1, 8, 396), (0, 396, 1
            ), 0), buf11, out=buf12)
        del buf11
        buf13 = reinterpret_tensor(buf12, (4, 2, 4, 4, 4), (128, 64, 16, 4,
            1), 0)
        del buf12
        triton_poi_fused_div_6[grid(512)](buf13, 512, XBLOCK=256, num_warps
            =4, num_stages=1)
    return buf13, buf1, buf3, buf5, buf6, buf7, buf8, reinterpret_tensor(buf9,
        (1, 396, 8), (3168, 1, 396), 0), buf14, reinterpret_tensor(primals_5,
        (20, 4), (1, 20), 0), reinterpret_tensor(primals_8, (396, 20), (1, 
        396), 0), reinterpret_tensor(primals_7, (396, 20), (1, 396), 0
        ), reinterpret_tensor(primals_6, (396, 20), (1, 396), 0
        ), reinterpret_tensor(buf4, (4, 8), (1, 4), 0), reinterpret_tensor(buf2
        , (4, 8), (1, 4), 0), reinterpret_tensor(buf0, (4, 8), (1, 4), 0)


class HexaLinearScoreNew(nn.Module):
    """
    Outer product version of hexalinear function for sequence labeling.
    """

    def __init__(self, wemb_size, tagset_size, temb_size=20, rank=396, std=
        0.1545, normalization=True, **kwargs):
        """
        Args:
            wemb_size: word embedding hidden size
            tagset_size: tag set size
            temb_size: tag embedding size
            rank: rank of the weight tensor
            std: standard deviation of the tensor
        """
        super(HexaLinearScoreNew, self).__init__()
        self.wemb_size = wemb_size
        self.tagset_size = tagset_size
        self.temb_size = temb_size
        self.rank = rank
        self.std = std
        self.normalization = normalization
        self.tag_emd = nn.Parameter(torch.Tensor(self.tagset_size, self.
            temb_size))
        self.W1 = nn.Parameter(torch.Tensor(self.wemb_size, self.rank))
        self.W2 = nn.Parameter(torch.Tensor(self.wemb_size, self.rank))
        self.W3 = nn.Parameter(torch.Tensor(self.wemb_size, self.rank))
        self.T1 = nn.Parameter(torch.Tensor(self.temb_size, self.rank))
        self.T2 = nn.Parameter(torch.Tensor(self.temb_size, self.rank))
        self.T3 = nn.Parameter(torch.Tensor(self.temb_size, self.rank))
        self.rand_init()
        self

    def rand_init(self):
        """random initialization
        """
        nn.init.uniform_(self.tag_emd, a=math.sqrt(6 / self.temb_size), b=
            math.sqrt(6 / self.temb_size))
        nn.init.normal_(self.T1, std=self.std)
        nn.init.normal_(self.T2, std=self.std)
        nn.init.normal_(self.T3, std=self.std)
        nn.init.normal_(self.W1, std=self.std)
        nn.init.normal_(self.W2, std=self.std)
        nn.init.normal_(self.W3, std=self.std)

    def forward(self, input_0):
        primals_5 = self.tag_emd
        primals_2 = self.W1
        primals_3 = self.W2
        primals_4 = self.W3
        primals_6 = self.T1
        primals_7 = self.T2
        primals_8 = self.T3
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8])
        return output[0]
