# 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_6/inductor_cache/gc/cgc45kwad4gupx6biccdqvpw57omugy4kbj5dfnfrh5axcqpbopx.py
# Topologically Sorted Source Nodes: [reshape], Original ATen: [aten.view]
# Source node to ATen node mapping:
#   reshape => view
# Graph fragment:
#   %view : [num_users=2] = call_function[target=torch.ops.aten.reshape.default](args = (%primals_1, [-1, 4, 4, 4]), kwargs = {})
triton_poi_fused_view_0 = async_compile.triton('triton_poi_fused_view_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=[64, 16], tile_hint=TileHint.SQUARE,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 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, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_view_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_view_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK : tl.constexpr, XBLOCK : tl.constexpr):
    ynumel = 64
    xnumel = 16
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    ymask = yindex < ynumel
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y3 = yindex
    y0 = yindex % 4
    y1 = (yindex // 4)
    tmp0 = tl.load(in_ptr0 + (x2 + (16*y3)), xmask & ymask, eviction_policy='evict_last')
    tl.store(out_ptr0 + (y0 + (4*x2) + (64*y1)), tmp0, xmask & ymask)
''', device_str='cuda')


# kernel path: runs/run_shard_6/inductor_cache/km/ckmmiyidiri2ickdcaxau2pdllh3zoibpargnantmq6ez2vbn52m.py
# Topologically Sorted Source Nodes: [y, sum_1], Original ATen: [aten.convolution, aten.sum]
# Source node to ATen node mapping:
#   sum_1 => sum_1
#   y => convolution
# Graph fragment:
#   %convolution : [num_users=3] = call_function[target=torch.ops.aten.convolution.default](args = (%view, %primals_2, None, [1, 1], [0, 0], [1, 1], False, [0, 0], 1), kwargs = {})
#   %sum_1 : [num_users=2] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%convolution, [2, 3]), kwargs = {})
triton_per_fused_convolution_sum_1 = async_compile.triton('triton_per_fused_convolution_sum_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.persistent_reduction(
    size_hints=[16384, 16],
    reduction_hint=ReductionHint.DEFAULT,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32', 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_per_fused_convolution_sum_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, '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_convolution_sum_1(in_ptr0, out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 16000
    rnumel = 16
    RBLOCK: tl.constexpr = 16
    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)
    r2 = rindex
    x0 = xindex % 1000
    x1 = (xindex // 1000)
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + (1000*r2) + (16000*x1)), xmask, other=0.0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp3 = tl.where(xmask, tmp1, 0)
    tmp4 = tl.sum(tmp3, 1)[:, None]
    tl.store(out_ptr0 + (r2 + (16*x3)), tmp0, xmask)
    tl.store(out_ptr1 + (x3), tmp4, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_6/inductor_cache/fl/cfl7afxnikesdu6th4ezymsaxkzxlo6m7w55gmmolvkrd6ke7n4y.py
# Topologically Sorted Source Nodes: [prob_vector], Original ATen: [aten._softmax]
# Source node to ATen node mapping:
#   prob_vector => amax, div, exp, sub, sum_2
# Graph fragment:
#   %amax : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%sum_1, [1], True), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%sum_1, %amax), kwargs = {})
#   %exp : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub,), kwargs = {})
#   %sum_2 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp, [1], True), kwargs = {})
#   %div : [num_users=5] = call_function[target=torch.ops.aten.div.Tensor](args = (%exp, %sum_2), kwargs = {})
triton_per_fused__softmax_2 = async_compile.triton('triton_per_fused__softmax_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=[16, 1024],
    reduction_hint=ReductionHint.INNER,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 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, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused__softmax_2', 'mutated_arg_names': [], 'no_x_dim': True, 'num_load': 1, 'num_reduction': 2, '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__softmax_2(in_ptr0, out_ptr2, xnumel, rnumel):
    xnumel = 16
    XBLOCK: tl.constexpr = 1
    rnumel = 1000
    RBLOCK: tl.constexpr = 1024
    xoffset = tl.program_id(0) * XBLOCK
    xindex = tl.full([1], xoffset, tl.int32)
    xmask = tl.full([RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[:]
    roffset = 0
    rmask = rindex < rnumel
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + (1000*x0)), rmask, other=0.0)
    tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
    tmp3 = tl.where(rmask, tmp1, float("-inf"))
    tmp4 = triton_helpers.promote_to_tensor(triton_helpers.max2(tmp3, 0))
    tmp5 = tmp0 - tmp4
    tmp6 = tl_math.exp(tmp5)
    tmp7 = tl.broadcast_to(tmp6, [RBLOCK])
    tmp9 = tl.where(rmask, tmp7, 0)
    tmp10 = triton_helpers.promote_to_tensor(tl.sum(tmp9, 0))
    tmp11 = tmp6 / tmp10
    tl.store(out_ptr2 + (r1 + (1000*x0)), tmp11, rmask)
''', device_str='cuda')


# kernel path: runs/run_shard_6/inductor_cache/hk/chkuvs3opcjdjocy3cx76nv76j5knfexkf6xll6uqpxmdtqsd7we.py
# Topologically Sorted Source Nodes: [attention_map_1], Original ATen: [aten._softmax]
# Source node to ATen node mapping:
#   attention_map_1 => amax_1, div_1, exp_1, sub_1, sum_3
# Graph fragment:
#   %amax_1 : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%mm, [1], True), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%mm, %amax_1), kwargs = {})
#   %exp_1 : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub_1,), kwargs = {})
#   %sum_3 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp_1, [1], True), kwargs = {})
#   %div_1 : [num_users=2] = call_function[target=torch.ops.aten.div.Tensor](args = (%exp_1, %sum_3), kwargs = {})
triton_per_fused__softmax_3 = async_compile.triton('triton_per_fused__softmax_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.persistent_reduction(
    size_hints=[16, 16],
    reduction_hint=ReductionHint.INNER,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 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, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused__softmax_3', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, 'num_reduction': 2, '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__softmax_3(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    rnumel = 16
    RBLOCK: tl.constexpr = 16
    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 + (16*x0)), xmask, other=0.0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp3 = tl.where(xmask, tmp1, float("-inf"))
    tmp4 = triton_helpers.max2(tmp3, 1)[:, None]
    tmp5 = tmp0 - tmp4
    tmp6 = tl_math.exp(tmp5)
    tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
    tmp9 = tl.where(xmask, tmp7, 0)
    tmp10 = tl.sum(tmp9, 1)[:, None]
    tmp11 = tmp6 / tmp10
    tl.store(out_ptr2 + (r1 + (16*x0)), tmp11, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_6/inductor_cache/j6/cj6kp56qmmrmyprbqnwlbrp3hyb7egoa6gfjkwoffi4wgzuxuxp3.py
# Topologically Sorted Source Nodes: [prob_vector_1, prob_vector_2], Original ATen: [aten.add, aten._softmax]
# Source node to ATen node mapping:
#   prob_vector_1 => add
#   prob_vector_2 => amax_2, div_2, exp_2, sub_2, sum_4
# Graph fragment:
#   %add_tensor : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mm_default, %primals_10), kwargs = {})
#   %add : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%div, %add_tensor), kwargs = {})
#   %amax_2 : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%add, [1], True), kwargs = {})
#   %sub_2 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add, %amax_2), kwargs = {})
#   %exp_2 : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub_2,), kwargs = {})
#   %sum_4 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp_2, [1], True), kwargs = {})
#   %div_2 : [num_users=2] = call_function[target=torch.ops.aten.div.Tensor](args = (%exp_2, %sum_4), kwargs = {})
triton_per_fused__softmax_add_4 = async_compile.triton('triton_per_fused__softmax_add_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.persistent_reduction(
    size_hints=[16, 1024],
    reduction_hint=ReductionHint.INNER,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 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': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused__softmax_add_4', 'mutated_arg_names': [], 'no_x_dim': True, 'num_load': 3, 'num_reduction': 2, '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__softmax_add_4(in_ptr0, in_ptr1, in_ptr2, out_ptr2, xnumel, rnumel):
    xnumel = 16
    XBLOCK: tl.constexpr = 1
    rnumel = 1000
    RBLOCK: tl.constexpr = 1024
    xoffset = tl.program_id(0) * XBLOCK
    xindex = tl.full([1], xoffset, tl.int32)
    xmask = tl.full([RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[:]
    roffset = 0
    rmask = rindex < rnumel
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + (1000*x0)), rmask, other=0.0)
    tmp1 = tl.load(in_ptr1 + (r1 + (1000*x0)), rmask, other=0.0)
    tmp2 = tl.load(in_ptr2 + (r1), rmask, eviction_policy='evict_last', other=0.0)
    tmp3 = tmp1 + tmp2
    tmp4 = tmp0 + tmp3
    tmp5 = tl.broadcast_to(tmp4, [RBLOCK])
    tmp7 = tl.where(rmask, tmp5, float("-inf"))
    tmp8 = triton_helpers.promote_to_tensor(triton_helpers.max2(tmp7, 0))
    tmp9 = tmp4 - tmp8
    tmp10 = tl_math.exp(tmp9)
    tmp11 = tl.broadcast_to(tmp10, [RBLOCK])
    tmp13 = tl.where(rmask, tmp11, 0)
    tmp14 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0))
    tmp15 = tmp10 / tmp14
    tl.store(out_ptr2 + (r1 + (1000*x0)), tmp15, rmask)
''', device_str='cuda')


# kernel path: runs/run_shard_6/inductor_cache/pc/cpc3boprutgyzqv62cebjnyisvurtt4awzmvb2d2wtwj6ssk7dd5.py
# Topologically Sorted Source Nodes: [mul, weighted_mask], Original ATen: [aten.mul, aten.sum]
# Source node to ATen node mapping:
#   mul => mul
#   weighted_mask => sum_5
# Graph fragment:
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%unsqueeze_1, %convolution), kwargs = {})
#   %sum_5 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul, [1], True), kwargs = {})
triton_red_fused_mul_sum_5 = async_compile.triton('triton_red_fused_mul_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.reduction(
    size_hints=[2048, 128],
    reduction_hint=ReductionHint.OUTER,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32', 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_red_fused_mul_sum_5', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 2, '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_red_fused_mul_sum_5(in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel, XBLOCK : tl.constexpr, RBLOCK : tl.constexpr):
    xnumel = 2048
    rnumel = 125
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rbase = tl.arange(0, RBLOCK)[None, :]
    x1 = (xindex // 16)
    x0 = xindex % 16
    _tmp4 = tl.full([XBLOCK, RBLOCK], 0, tl.float32)
    x3 = xindex
    for roffset in range(0, rnumel, RBLOCK):
        rindex = roffset + rbase
        rmask = rindex < rnumel
        r2 = rindex
        tmp0 = tl.load(in_ptr0 + (r2 + (125*x1)), rmask, eviction_policy='evict_last', other=0.0)
        tmp1 = tl.load(in_ptr1 + (x0 + (16*r2) + (2000*x1)), rmask, eviction_policy='evict_last', other=0.0)
        tmp2 = tmp0 * tmp1
        tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
        tmp5 = _tmp4 + tmp3
        _tmp4 = tl.where(rmask, tmp5, _tmp4)
    tmp4 = tl.sum(_tmp4, 1)[:, None]
    tl.store(out_ptr0 + (x3), tmp4, None)
''', device_str='cuda')


# kernel path: runs/run_shard_6/inductor_cache/ae/caepc2m3vq4zca7xmucvrh6nzgapqowox7fjyocrzcreanyqsoxf.py
# Topologically Sorted Source Nodes: [mul, weighted_mask], Original ATen: [aten.mul, aten.sum]
# Source node to ATen node mapping:
#   mul => mul
#   weighted_mask => sum_5
# Graph fragment:
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%unsqueeze_1, %convolution), kwargs = {})
#   %sum_5 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul, [1], True), kwargs = {})
triton_per_fused_mul_sum_6 = async_compile.triton('triton_per_fused_mul_sum_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.persistent_reduction(
    size_hints=[256, 8],
    reduction_hint=ReductionHint.OUTER_TINY,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 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, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_mul_sum_6', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 1, '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_mul_sum_6(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 256
    rnumel = 8
    RBLOCK: tl.constexpr = 8
    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)
    r2 = rindex
    x0 = xindex % 16
    x1 = (xindex // 16)
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + (16*r2) + (128*x1)), xmask, other=0.0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp3 = tl.where(xmask, tmp1, 0)
    tmp4 = tl.sum(tmp3, 1)[:, None]
    tl.store(out_ptr0 + (x3), tmp4, 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, primals_9, primals_10 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1))
    assert_size_stride(primals_2, (1000, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_3, (333, 1000), (1000, 1))
    assert_size_stride(primals_4, (333, ), (1, ))
    assert_size_stride(primals_5, (333, 1000), (1000, 1))
    assert_size_stride(primals_6, (333, ), (1, ))
    assert_size_stride(primals_7, (333, 1000), (1000, 1))
    assert_size_stride(primals_8, (333, ), (1, ))
    assert_size_stride(primals_9, (1000, 333), (333, 1))
    assert_size_stride(primals_10, (1000, ), (1, ))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((16, 4, 4, 4), (64, 1, 16, 4), torch.float32)
        # Topologically Sorted Source Nodes: [reshape], Original ATen: [aten.view]
        stream0 = get_raw_stream(0)
        triton_poi_fused_view_0.run(primals_1, buf0, 64, 16, grid=grid(64, 16), stream=stream0)
        del primals_1
        # Topologically Sorted Source Nodes: [y], Original ATen: [aten.convolution]
        buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf1, (16, 1000, 4, 4), (16000, 1, 4000, 1000))
        buf2 = empty_strided_cuda((16, 1000, 4, 4), (16000, 16, 4, 1), torch.float32)
        buf3 = empty_strided_cuda((16, 1000), (1000, 1), torch.float32)
        # Topologically Sorted Source Nodes: [y, sum_1], Original ATen: [aten.convolution, aten.sum]
        triton_per_fused_convolution_sum_1.run(buf1, buf2, buf3, 16000, 16, grid=grid(16000), stream=stream0)
        del buf1
        buf6 = empty_strided_cuda((16, 1000), (1000, 1), torch.float32)
        # Topologically Sorted Source Nodes: [prob_vector], Original ATen: [aten._softmax]
        triton_per_fused__softmax_2.run(buf3, buf6, 16, 1000, grid=grid(16), stream=stream0)
        buf7 = empty_strided_cuda((16, 333), (333, 1), torch.float32)
        # Topologically Sorted Source Nodes: [x_t], Original ATen: [aten.addmm]
        extern_kernels.addmm(primals_4, buf6, reinterpret_tensor(primals_3, (1000, 333), (1, 1000), 0), alpha=1, beta=1, out=buf7)
        del primals_4
        buf8 = empty_strided_cuda((16, 333), (333, 1), torch.float32)
        # Topologically Sorted Source Nodes: [x_ph], Original ATen: [aten.addmm]
        extern_kernels.addmm(primals_6, buf6, reinterpret_tensor(primals_5, (1000, 333), (1, 1000), 0), alpha=1, beta=1, out=buf8)
        del primals_6
        buf9 = empty_strided_cuda((16, 333), (333, 1), torch.float32)
        # Topologically Sorted Source Nodes: [x_psi], Original ATen: [aten.addmm]
        extern_kernels.addmm(primals_8, buf6, reinterpret_tensor(primals_7, (1000, 333), (1, 1000), 0), alpha=1, beta=1, out=buf9)
        del primals_8
        buf10 = empty_strided_cuda((16, 16), (16, 1), torch.float32)
        # Topologically Sorted Source Nodes: [attention_map], Original ATen: [aten.mm]
        extern_kernels.mm(buf8, reinterpret_tensor(buf7, (333, 16), (1, 333), 0), out=buf10)
        buf13 = empty_strided_cuda((16, 16), (16, 1), torch.float32)
        # Topologically Sorted Source Nodes: [attention_map_1], Original ATen: [aten._softmax]
        triton_per_fused__softmax_3.run(buf10, buf13, 16, 16, grid=grid(16), stream=stream0)
        buf14 = empty_strided_cuda((16, 333), (333, 1), torch.float32)
        # Topologically Sorted Source Nodes: [x_add], Original ATen: [aten.mm]
        extern_kernels.mm(buf13, buf9, out=buf14)
        buf15 = buf3; del buf3  # reuse
        # Topologically Sorted Source Nodes: [], Original ATen: []
        extern_kernels.mm(buf14, reinterpret_tensor(primals_9, (333, 1000), (1, 333), 0), out=buf15)
        buf18 = empty_strided_cuda((16, 1000), (1000, 1), torch.float32)
        # Topologically Sorted Source Nodes: [prob_vector_1, prob_vector_2], Original ATen: [aten.add, aten._softmax]
        triton_per_fused__softmax_add_4.run(buf6, buf15, primals_10, buf18, 16, 1000, grid=grid(16), stream=stream0)
        del buf15
        del primals_10
        buf19 = empty_strided_cuda((16, 1, 4, 4, 8), (128, 2048, 4, 1, 16), torch.float32)
        # Topologically Sorted Source Nodes: [mul, weighted_mask], Original ATen: [aten.mul, aten.sum]
        triton_red_fused_mul_sum_5.run(buf18, buf2, buf19, 2048, 125, grid=grid(2048), stream=stream0)
        buf20 = reinterpret_tensor(buf10, (16, 1, 4, 4), (16, 16, 4, 1), 0); del buf10  # reuse
        # Topologically Sorted Source Nodes: [mul, weighted_mask], Original ATen: [aten.mul, aten.sum]
        triton_per_fused_mul_sum_6.run(buf19, buf20, 256, 8, grid=grid(256), stream=stream0)
        del buf19
        buf23 = empty_strided_cuda((16, 1, 16), (16, 16, 1), torch.float32)
        # Topologically Sorted Source Nodes: [softmax_3], Original ATen: [aten._softmax]
        triton_per_fused__softmax_3.run(buf20, buf23, 16, 16, grid=grid(16), stream=stream0)
        del buf20
    return (reinterpret_tensor(buf23, (16, 1, 4, 4), (16, 16, 4, 1), 0), buf18, buf6, buf2, primals_2, buf0, buf2, buf6, buf8, buf13, buf14, buf18, buf23, primals_9, reinterpret_tensor(buf9, (333, 16), (1, 333), 0), buf7, primals_7, primals_5, primals_3, )


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, 4), (256, 64, 16, 4, 1), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((1000, 4, 1, 1), (4, 1, 1, 1), device='cuda:0', dtype=torch.float32)
    primals_3 = rand_strided((333, 1000), (1000, 1), device='cuda:0', dtype=torch.float32)
    primals_4 = rand_strided((333, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_5 = rand_strided((333, 1000), (1000, 1), device='cuda:0', dtype=torch.float32)
    primals_6 = rand_strided((333, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_7 = rand_strided((333, 1000), (1000, 1), device='cuda:0', dtype=torch.float32)
    primals_8 = rand_strided((333, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_9 = rand_strided((1000, 333), (333, 1), device='cuda:0', dtype=torch.float32)
    primals_10 = rand_strided((1000, ), (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, primals_9, primals_10])
    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


class VectorAttention(nn.Module):
    """vector attention"""

    def __init__(self, input_dim, hidden_dim):
        super(VectorAttention, self).__init__()
        self.theta = nn.Linear(input_dim, hidden_dim)
        self.phi = nn.Linear(input_dim, hidden_dim)
        self.psi = nn.Linear(input_dim, hidden_dim)
        self.recover = nn.Linear(hidden_dim, input_dim)

    def forward(self, x):
        x_t = self.theta(x)
        x_ph = self.phi(x)
        x_psi = self.psi(x)
        attention_map = torch.matmul(x_ph, torch.transpose(x_t, 0, 1))
        attention_map = attention_map
        attention_map = F.softmax(attention_map, dim=1)
        x_add = torch.matmul(attention_map, x_psi)
        x_add = self.recover(x_add)
        return x + x_add


class GenerateMask(nn.Module):
    """
    sparsify by 1x1 conv and apply gumbel softmax
    """

    def __init__(self, ch, resolution, or_cadidate=1000, no_attention=False):
        super(GenerateMask, self).__init__()
        self.conv = nn.Conv2d(ch, or_cadidate, kernel_size=1, padding=0,
            bias=False)
        self.relu = nn.ReLU()
        self.no_attention = no_attention
        if not self.no_attention:
            self.prob_attention = VectorAttention(input_dim=or_cadidate,
                hidden_dim=or_cadidate // 3)

    def forward(self, x):
        """
        input x: [n, L, c, kernel, kernel]
        output mask: [n * L, 1, h, w]
        """
        n, L, c, h, w = x.shape
        y = self.conv(x.reshape(-1, c, h, w))
        prob_vector = F.softmax(y.sum((2, 3)), dim=1)
        prob_vector_previous = prob_vector
        if not self.no_attention:
            prob_vector = self.prob_attention(prob_vector)
        prob_vector = F.softmax(prob_vector)
        weighted_mask = (prob_vector[:, :, None, None] * y).sum((1,),
            keepdim=True)
        weighted_mask = F.softmax(weighted_mask.view(n * L, 1, h * w), dim=2
            ).view(n * L, 1, h, w)
        return weighted_mask, prob_vector, prob_vector_previous, y


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


def get_init_inputs():
    return [[], {'ch': 4, 'resolution': 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
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
import torch.nn.functional as F
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_view_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    ynumel = 64
    xnumel = 16
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    ymask = yindex < ynumel
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y3 = yindex
    y0 = yindex % 4
    y1 = yindex // 4
    tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask & ymask, eviction_policy
        ='evict_last')
    tl.store(out_ptr0 + (y0 + 4 * x2 + 64 * y1), tmp0, xmask & ymask)


@triton.jit
def triton_per_fused_convolution_sum_1(in_ptr0, out_ptr0, out_ptr1, xnumel,
    rnumel, XBLOCK: tl.constexpr):
    xnumel = 16000
    RBLOCK: tl.constexpr = 16
    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)
    r2 = rindex
    x0 = xindex % 1000
    x1 = xindex // 1000
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 1000 * r2 + 16000 * x1), xmask, other=0.0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp3 = tl.where(xmask, tmp1, 0)
    tmp4 = tl.sum(tmp3, 1)[:, None]
    tl.store(out_ptr0 + (r2 + 16 * x3), tmp0, xmask)
    tl.store(out_ptr1 + x3, tmp4, xmask)


@triton.jit
def triton_per_fused__softmax_2(in_ptr0, out_ptr2, xnumel, rnumel):
    XBLOCK: tl.constexpr = 1
    rnumel = 1000
    RBLOCK: tl.constexpr = 1024
    xoffset = tl.program_id(0) * XBLOCK
    xindex = tl.full([1], xoffset, tl.int32)
    tl.full([RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[:]
    rmask = rindex < rnumel
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + 1000 * x0), rmask, other=0.0)
    tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
    tmp3 = tl.where(rmask, tmp1, float('-inf'))
    tmp4 = triton_helpers.promote_to_tensor(triton_helpers.max2(tmp3, 0))
    tmp5 = tmp0 - tmp4
    tmp6 = tl_math.exp(tmp5)
    tmp7 = tl.broadcast_to(tmp6, [RBLOCK])
    tmp9 = tl.where(rmask, tmp7, 0)
    tmp10 = triton_helpers.promote_to_tensor(tl.sum(tmp9, 0))
    tmp11 = tmp6 / tmp10
    tl.store(out_ptr2 + (r1 + 1000 * x0), tmp11, rmask)


@triton.jit
def triton_per_fused__softmax_3(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK:
    tl.constexpr):
    xnumel = 16
    RBLOCK: tl.constexpr = 16
    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 + 16 * x0), xmask, other=0.0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp3 = tl.where(xmask, tmp1, float('-inf'))
    tmp4 = triton_helpers.max2(tmp3, 1)[:, None]
    tmp5 = tmp0 - tmp4
    tmp6 = tl_math.exp(tmp5)
    tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
    tmp9 = tl.where(xmask, tmp7, 0)
    tmp10 = tl.sum(tmp9, 1)[:, None]
    tmp11 = tmp6 / tmp10
    tl.store(out_ptr2 + (r1 + 16 * x0), tmp11, xmask)


@triton.jit
def triton_per_fused__softmax_add_4(in_ptr0, in_ptr1, in_ptr2, out_ptr2,
    xnumel, rnumel):
    XBLOCK: tl.constexpr = 1
    rnumel = 1000
    RBLOCK: tl.constexpr = 1024
    xoffset = tl.program_id(0) * XBLOCK
    xindex = tl.full([1], xoffset, tl.int32)
    tl.full([RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[:]
    rmask = rindex < rnumel
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + 1000 * x0), rmask, other=0.0)
    tmp1 = tl.load(in_ptr1 + (r1 + 1000 * x0), rmask, other=0.0)
    tmp2 = tl.load(in_ptr2 + r1, rmask, eviction_policy='evict_last', other=0.0
        )
    tmp3 = tmp1 + tmp2
    tmp4 = tmp0 + tmp3
    tmp5 = tl.broadcast_to(tmp4, [RBLOCK])
    tmp7 = tl.where(rmask, tmp5, float('-inf'))
    tmp8 = triton_helpers.promote_to_tensor(triton_helpers.max2(tmp7, 0))
    tmp9 = tmp4 - tmp8
    tmp10 = tl_math.exp(tmp9)
    tmp11 = tl.broadcast_to(tmp10, [RBLOCK])
    tmp13 = tl.where(rmask, tmp11, 0)
    tmp14 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0))
    tmp15 = tmp10 / tmp14
    tl.store(out_ptr2 + (r1 + 1000 * x0), tmp15, rmask)


@triton.jit
def triton_red_fused_mul_sum_5(in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel,
    XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
    rnumel = 125
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rbase = tl.arange(0, RBLOCK)[None, :]
    x1 = xindex // 16
    x0 = xindex % 16
    _tmp4 = tl.full([XBLOCK, RBLOCK], 0, tl.float32)
    x3 = xindex
    for roffset in range(0, rnumel, RBLOCK):
        rindex = roffset + rbase
        rmask = rindex < rnumel
        r2 = rindex
        tmp0 = tl.load(in_ptr0 + (r2 + 125 * x1), rmask, eviction_policy=
            'evict_last', other=0.0)
        tmp1 = tl.load(in_ptr1 + (x0 + 16 * r2 + 2000 * x1), rmask,
            eviction_policy='evict_last', other=0.0)
        tmp2 = tmp0 * tmp1
        tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
        tmp5 = _tmp4 + tmp3
        _tmp4 = tl.where(rmask, tmp5, _tmp4)
    tmp4 = tl.sum(_tmp4, 1)[:, None]
    tl.store(out_ptr0 + x3, tmp4, None)


@triton.jit
def triton_per_fused_mul_sum_6(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK:
    tl.constexpr):
    xnumel = 256
    RBLOCK: tl.constexpr = 8
    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)
    r2 = rindex
    x0 = xindex % 16
    x1 = xindex // 16
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 16 * r2 + 128 * x1), xmask, other=0.0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp3 = tl.where(xmask, tmp1, 0)
    tmp4 = tl.sum(tmp3, 1)[:, None]
    tl.store(out_ptr0 + x3, tmp4, xmask)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9, primals_10) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1))
    assert_size_stride(primals_2, (1000, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_3, (333, 1000), (1000, 1))
    assert_size_stride(primals_4, (333,), (1,))
    assert_size_stride(primals_5, (333, 1000), (1000, 1))
    assert_size_stride(primals_6, (333,), (1,))
    assert_size_stride(primals_7, (333, 1000), (1000, 1))
    assert_size_stride(primals_8, (333,), (1,))
    assert_size_stride(primals_9, (1000, 333), (333, 1))
    assert_size_stride(primals_10, (1000,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((16, 4, 4, 4), (64, 1, 16, 4), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_view_0[grid(64, 16)](primals_1, buf0, 64, 16,
            XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
        del primals_1
        buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf1, (16, 1000, 4, 4), (16000, 1, 4000, 1000))
        buf2 = empty_strided_cuda((16, 1000, 4, 4), (16000, 16, 4, 1),
            torch.float32)
        buf3 = empty_strided_cuda((16, 1000), (1000, 1), torch.float32)
        triton_per_fused_convolution_sum_1[grid(16000)](buf1, buf2, buf3, 
            16000, 16, XBLOCK=32, num_warps=4, num_stages=1)
        del buf1
        buf6 = empty_strided_cuda((16, 1000), (1000, 1), torch.float32)
        triton_per_fused__softmax_2[grid(16)](buf3, buf6, 16, 1000,
            num_warps=8, num_stages=1)
        buf7 = empty_strided_cuda((16, 333), (333, 1), torch.float32)
        extern_kernels.addmm(primals_4, buf6, reinterpret_tensor(primals_3,
            (1000, 333), (1, 1000), 0), alpha=1, beta=1, out=buf7)
        del primals_4
        buf8 = empty_strided_cuda((16, 333), (333, 1), torch.float32)
        extern_kernels.addmm(primals_6, buf6, reinterpret_tensor(primals_5,
            (1000, 333), (1, 1000), 0), alpha=1, beta=1, out=buf8)
        del primals_6
        buf9 = empty_strided_cuda((16, 333), (333, 1), torch.float32)
        extern_kernels.addmm(primals_8, buf6, reinterpret_tensor(primals_7,
            (1000, 333), (1, 1000), 0), alpha=1, beta=1, out=buf9)
        del primals_8
        buf10 = empty_strided_cuda((16, 16), (16, 1), torch.float32)
        extern_kernels.mm(buf8, reinterpret_tensor(buf7, (333, 16), (1, 333
            ), 0), out=buf10)
        buf13 = empty_strided_cuda((16, 16), (16, 1), torch.float32)
        triton_per_fused__softmax_3[grid(16)](buf10, buf13, 16, 16, XBLOCK=
            8, num_warps=2, num_stages=1)
        buf14 = empty_strided_cuda((16, 333), (333, 1), torch.float32)
        extern_kernels.mm(buf13, buf9, out=buf14)
        buf15 = buf3
        del buf3
        extern_kernels.mm(buf14, reinterpret_tensor(primals_9, (333, 1000),
            (1, 333), 0), out=buf15)
        buf18 = empty_strided_cuda((16, 1000), (1000, 1), torch.float32)
        triton_per_fused__softmax_add_4[grid(16)](buf6, buf15, primals_10,
            buf18, 16, 1000, num_warps=8, num_stages=1)
        del buf15
        del primals_10
        buf19 = empty_strided_cuda((16, 1, 4, 4, 8), (128, 2048, 4, 1, 16),
            torch.float32)
        triton_red_fused_mul_sum_5[grid(2048)](buf18, buf2, buf19, 2048, 
            125, XBLOCK=64, RBLOCK=8, num_warps=4, num_stages=1)
        buf20 = reinterpret_tensor(buf10, (16, 1, 4, 4), (16, 16, 4, 1), 0)
        del buf10
        triton_per_fused_mul_sum_6[grid(256)](buf19, buf20, 256, 8, XBLOCK=
            64, num_warps=4, num_stages=1)
        del buf19
        buf23 = empty_strided_cuda((16, 1, 16), (16, 16, 1), torch.float32)
        triton_per_fused__softmax_3[grid(16)](buf20, buf23, 16, 16, XBLOCK=
            8, num_warps=2, num_stages=1)
        del buf20
    return (reinterpret_tensor(buf23, (16, 1, 4, 4), (16, 16, 4, 1), 0),
        buf18, buf6, buf2, primals_2, buf0, buf2, buf6, buf8, buf13, buf14,
        buf18, buf23, primals_9, reinterpret_tensor(buf9, (333, 16), (1, 
        333), 0), buf7, primals_7, primals_5, primals_3)


class VectorAttention(nn.Module):
    """vector attention"""

    def __init__(self, input_dim, hidden_dim):
        super(VectorAttention, self).__init__()
        self.theta = nn.Linear(input_dim, hidden_dim)
        self.phi = nn.Linear(input_dim, hidden_dim)
        self.psi = nn.Linear(input_dim, hidden_dim)
        self.recover = nn.Linear(hidden_dim, input_dim)

    def forward(self, x):
        x_t = self.theta(x)
        x_ph = self.phi(x)
        x_psi = self.psi(x)
        attention_map = torch.matmul(x_ph, torch.transpose(x_t, 0, 1))
        attention_map = attention_map
        attention_map = F.softmax(attention_map, dim=1)
        x_add = torch.matmul(attention_map, x_psi)
        x_add = self.recover(x_add)
        return x + x_add


class GenerateMaskNew(nn.Module):
    """
    sparsify by 1x1 conv and apply gumbel softmax
    """

    def __init__(self, ch, resolution, or_cadidate=1000, no_attention=False):
        super(GenerateMaskNew, self).__init__()
        self.conv = nn.Conv2d(ch, or_cadidate, kernel_size=1, padding=0,
            bias=False)
        self.relu = nn.ReLU()
        self.no_attention = no_attention
        if not self.no_attention:
            self.prob_attention = VectorAttention(input_dim=or_cadidate,
                hidden_dim=or_cadidate // 3)

    def forward(self, input_0):
        primals_2 = self.conv.weight
        primals_3 = self.prob_attention.theta.weight
        primals_4 = self.prob_attention.theta.bias
        primals_5 = self.prob_attention.phi.weight
        primals_6 = self.prob_attention.phi.bias
        primals_7 = self.prob_attention.psi.weight
        primals_8 = self.prob_attention.psi.bias
        primals_9 = self.prob_attention.recover.weight
        primals_10 = self.prob_attention.recover.bias
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9, primals_10])
        return output[0], output[1], output[2], output[3]
