# 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/eg/ceg5r5lesy4yjcsgwggyxi634wo4m2ibfbfrzibrfm7cykiqvg76.py
# Topologically Sorted Source Nodes: [feature_1], Original ATen: [aten.max_pool2d_with_indices]
# Source node to ATen node mapping:
#   feature_1 => getitem
# Graph fragment:
#   %getitem : [num_users=3] = call_function[target=operator.getitem](args = (%_low_memory_max_pool2d_with_offsets, 0), kwargs = {})
triton_poi_fused_max_pool2d_with_indices_0 = async_compile.triton('triton_poi_fused_max_pool2d_with_indices_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=[4], 
    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), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_max_pool2d_with_indices_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 4, '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_max_pool2d_with_indices_0(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (4*x0), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (2 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (3 + (4*x0)), xmask, eviction_policy='evict_last')
    tmp2 = triton_helpers.maximum(tmp1, tmp0)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp6 = triton_helpers.maximum(tmp5, tmp4)
    tl.store(out_ptr0 + (x0), tmp6, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_6/inductor_cache/uk/cuk5lavfoty5guvxyu3dtcj2ziwvajlbsezoxgszx5nevrcmthnr.py
# Topologically Sorted Source Nodes: [padded_x], Original ATen: [aten.constant_pad_nd]
# Source node to ATen node mapping:
#   padded_x => constant_pad_nd
# Graph fragment:
#   %constant_pad_nd : [num_users=3] = call_function[target=torch.ops.aten.constant_pad_nd.default](args = (%getitem, [1, 1, 1, 1], 0.0), kwargs = {})
triton_poi_fused_constant_pad_nd_1 = async_compile.triton('triton_poi_fused_constant_pad_nd_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), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_constant_pad_nd_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_constant_pad_nd_1(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 18
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = (xindex // 3)
    x0 = xindex % 3
    x2 = xindex
    tmp0 = (-1) + x1
    tmp1 = tl.full([1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = (-1) + x0
    tmp6 = tmp5 >= tmp1
    tmp7 = tl.full([1], 1, tl.int64)
    tmp8 = tmp5 < tmp7
    tmp9 = tmp2 & tmp4
    tmp10 = tmp9 & tmp6
    tmp11 = tmp10 & tmp8
    tmp12 = tl.load(in_ptr0 + ((-1) + x1), tmp11 & xmask, eviction_policy='evict_last', other=0.0)
    tl.store(out_ptr0 + (x2), tmp12, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_6/inductor_cache/5x/c5xvls7xnlknpp2gn4xtpmhjw3qey4npwog52sanzzlugzbe3nuh.py
# Topologically Sorted Source Nodes: [k_out_2, out_1], Original ATen: [aten.cat, aten._softmax]
# Source node to ATen node mapping:
#   k_out_2 => cat
#   out_1 => div, exp, sum_1
# Graph fragment:
#   %cat : [num_users=2] = call_function[target=torch.ops.aten.cat.default](args = ([%add, %add_1], 1), kwargs = {})
#   %scalar_tensor_default : [num_users=2] = call_function[target=torch.ops.aten.scalar_tensor.default](args = (1,), kwargs = {dtype: torch.float32, device: cuda:0, pin_memory: False})
#   %ge_scalar : [num_users=1] = call_function[target=torch.ops.aten.ge.Scalar](args = (%view_2, 0), kwargs = {})
#   %neg_default : [num_users=1] = call_function[target=torch.ops.aten.neg.default](args = (%scalar_tensor_default,), kwargs = {})
#   %where_self : [num_users=2] = call_function[target=torch.ops.aten.where.self](args = (%ge_scalar, %scalar_tensor_default, %neg_default), kwargs = {})
#   %mul_tensor : [num_users=2] = call_function[target=torch.ops.aten.mul.Tensor](args = (%view, %where_self), kwargs = {})
#   %amax_default : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%mul_tensor, [-1], True), kwargs = {})
#   %sub_tensor : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%mul_tensor, %amax_default), kwargs = {})
#   %mul_tensor_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%where_self, %view_2), kwargs = {})
#   %mul_tensor_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_tensor, %mul_tensor_1), kwargs = {})
#   %exp : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%mul_tensor_2,), kwargs = {})
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp, [-1], True), kwargs = {})
#   %div : [num_users=2] = call_function[target=torch.ops.aten.div.Tensor](args = (%exp, %sum_1), kwargs = {})
triton_per_fused__softmax_cat_2 = async_compile.triton('triton_per_fused__softmax_cat_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=[128, 16],
    reduction_hint=ReductionHint.INNER,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: '*fp32', 6: 'i32', 7: '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, 5, 6), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused__softmax_cat_2', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 5, '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_cat_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, out_ptr3, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 80
    rnumel = 9
    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 = rindex < rnumel
    x1 = (xindex // 4)
    r5 = rindex
    x0 = xindex % 4
    r3 = (rindex // 3)
    r2 = rindex % 3
    x4 = xindex
    tmp19 = tl.load(in_ptr3 + (x4), xmask, eviction_policy='evict_last')
    tmp0 = x1
    tmp1 = tl.full([1, 1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = tl.full([1, 1], 10, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (r5 + (3*x0) + (18*x1)), rmask & tmp4 & xmask, other=0.0)
    tmp6 = tl.load(in_ptr1 + (r3 + (3*x1)), rmask & tmp4 & xmask, eviction_policy='evict_last', other=0.0)
    tmp7 = tmp5 + tmp6
    tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype)
    tmp9 = tl.where(tmp4, tmp7, tmp8)
    tmp10 = tmp0 >= tmp3
    tmp11 = tl.full([1, 1], 20, tl.int64)
    tmp12 = tmp0 < tmp11
    tmp13 = tl.load(in_ptr0 + (180 + r5 + (3*x0) + (18*((-10) + x1))), rmask & tmp10 & xmask, other=0.0)
    tmp14 = tl.load(in_ptr2 + (r2 + (3*((-10) + x1))), rmask & tmp10 & xmask, eviction_policy='evict_last', other=0.0)
    tmp15 = tmp13 + tmp14
    tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype)
    tmp17 = tl.where(tmp10, tmp15, tmp16)
    tmp18 = tl.where(tmp4, tmp9, tmp17)
    tmp20 = 0.0
    tmp21 = tmp19 >= tmp20
    tmp22 = 1.0
    tmp23 = -1.0
    tmp24 = tl.where(tmp21, tmp22, tmp23)
    tmp25 = tmp18 * tmp24
    tmp26 = tl.broadcast_to(tmp25, [XBLOCK, RBLOCK])
    tmp28 = tl.where(rmask & xmask, tmp26, float("-inf"))
    tmp29 = triton_helpers.max2(tmp28, 1)[:, None]
    tmp30 = tmp25 - tmp29
    tmp31 = tmp24 * tmp19
    tmp32 = tmp30 * tmp31
    tmp33 = tl_math.exp(tmp32)
    tmp34 = tl.broadcast_to(tmp33, [XBLOCK, RBLOCK])
    tmp36 = tl.where(rmask & xmask, tmp34, 0)
    tmp37 = tl.sum(tmp36, 1)[:, None]
    tmp38 = tmp33 / tmp37
    tl.store(out_ptr0 + (r5 + (9*x4)), tmp18, rmask & xmask)
    tl.store(out_ptr3 + (r5 + (9*x4)), tmp38, rmask & xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_6/inductor_cache/gb/cgbpq6g2egq2fxmxrkb5cl25fh5pxlxvodou3mrtl4672gbnhrm7.py
# Topologically Sorted Source Nodes: [contiguous_1], Original ATen: [aten.clone]
# Source node to ATen node mapping:
#   contiguous_1 => clone
# Graph fragment:
#   %clone : [num_users=1] = call_function[target=torch.ops.aten.clone.default](args = (%unfold_3,), kwargs = {memory_format: torch.contiguous_format})
triton_poi_fused_clone_3 = async_compile.triton('triton_poi_fused_clone_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=[1024], 
    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_clone_3', '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_clone_3(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 720
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 9
    x1 = (xindex // 9) % 4
    x2 = (xindex // 36)
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + (3*x1) + (18*x2)), xmask)
    tl.store(out_ptr0 + (x3), tmp0, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_6/inductor_cache/zc/czcg4krcjbxycgug3jpxbvrq54v7wgydsnqyhluixxyapo3b4ep3.py
# Topologically Sorted Source Nodes: [feature_2], Original ATen: [aten.relu, aten.threshold_backward]
# Source node to ATen node mapping:
#   feature_2 => relu
# Graph fragment:
#   %relu : [num_users=2] = call_function[target=torch.ops.aten.relu.default](args = (%view_7,), kwargs = {})
#   %le : [num_users=1] = call_function[target=torch.ops.aten.le.Scalar](args = (%relu, 0), kwargs = {})
triton_poi_fused_relu_threshold_backward_4 = async_compile.triton('triton_poi_fused_relu_threshold_backward_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=[128], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*i1', 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_relu_threshold_backward_4', '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_relu_threshold_backward_4(in_out_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 80
    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 = tl.full([1], 0, tl.int32)
    tmp2 = triton_helpers.maximum(tmp1, tmp0)
    tmp3 = 0.0
    tmp4 = tmp2 <= tmp3
    tl.store(in_out_ptr0 + (x0), tmp2, xmask)
    tl.store(out_ptr0 + (x0), 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 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4), (4, 1))
    assert_size_stride(primals_2, (20, 1, 1, 1), (1, 1, 1, 1))
    assert_size_stride(primals_3, (20, 1, 1, 1), (1, 1, 1, 1))
    assert_size_stride(primals_4, (20, 1, 1, 1), (1, 1, 1, 1))
    assert_size_stride(primals_5, (10, 1, 1, 3, 1), (3, 3, 3, 1, 1))
    assert_size_stride(primals_6, (10, 1, 1, 1, 3), (3, 3, 3, 3, 1))
    assert_size_stride(primals_7, (80, 20), (20, 1))
    assert_size_stride(primals_8, (80, ), (1, ))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((1, 1, 4, 1), (4, 4, 1, 1), torch.float32)
        # Topologically Sorted Source Nodes: [feature_1], Original ATen: [aten.max_pool2d_with_indices]
        stream0 = get_raw_stream(0)
        triton_poi_fused_max_pool2d_with_indices_0.run(primals_1, buf0, 4, grid=grid(4), stream=stream0)
        del primals_1
        buf1 = empty_strided_cuda((1, 1, 6, 3), (18, 18, 3, 1), torch.float32)
        # Topologically Sorted Source Nodes: [padded_x], Original ATen: [aten.constant_pad_nd]
        triton_poi_fused_constant_pad_nd_1.run(buf0, buf1, 18, grid=grid(18), stream=stream0)
        # Topologically Sorted Source Nodes: [q_out], Original ATen: [aten.convolution]
        buf2 = 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(buf2, (1, 20, 4, 1), (80, 4, 1, 1))
        # Topologically Sorted Source Nodes: [k_out], Original ATen: [aten.convolution]
        buf3 = extern_kernels.convolution(buf1, primals_3, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf3, (1, 20, 6, 3), (360, 18, 3, 1))
        # Topologically Sorted Source Nodes: [v_out], Original ATen: [aten.convolution]
        buf4 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf4, (1, 20, 6, 3), (360, 18, 3, 1))
        buf5 = empty_strided_cuda((1, 20, 4, 1, 3, 3), (720, 36, 9, 9, 3, 1), torch.float32)
        buf8 = empty_strided_cuda((1, 1, 20, 4, 1, 9), (720, 720, 36, 9, 9, 1), torch.float32)
        # Topologically Sorted Source Nodes: [k_out_2, out_1], Original ATen: [aten.cat, aten._softmax]
        triton_per_fused__softmax_cat_2.run(buf3, primals_5, primals_6, buf2, buf5, buf8, 80, 9, grid=grid(80), stream=stream0)
        del buf3
        del primals_5
        del primals_6
        buf9 = empty_strided_cuda((1, 20, 4, 1, 3, 3), (720, 36, 9, 9, 3, 1), torch.float32)
        # Topologically Sorted Source Nodes: [contiguous_1], Original ATen: [aten.clone]
        triton_poi_fused_clone_3.run(buf4, buf9, 720, grid=grid(720), stream=stream0)
        del buf4
        buf10 = empty_strided_cuda((80, 1, 1), (1, 1, 1), torch.float32)
        # Topologically Sorted Source Nodes: [einsum], Original ATen: [aten.bmm]
        extern_kernels.bmm(reinterpret_tensor(buf8, (80, 1, 9), (9, 9, 1), 0), reinterpret_tensor(buf9, (80, 9, 1), (9, 1, 0), 0), out=buf10)
        buf11 = reinterpret_tensor(buf10, (1, 20, 4, 1), (80, 4, 1, 1), 0); del buf10  # reuse
        buf17 = empty_strided_cuda((1, 20, 4, 1), (80, 4, 1, 1), torch.bool)
        # Topologically Sorted Source Nodes: [feature_2], Original ATen: [aten.relu, aten.threshold_backward]
        triton_poi_fused_relu_threshold_backward_4.run(buf11, buf17, 80, grid=grid(80), stream=stream0)
        buf16 = empty_strided_cuda((4, 80), (80, 1), torch.float32)
        buf12 = reinterpret_tensor(buf16, (1, 80), (80, 1), 0)  # alias
        # Topologically Sorted Source Nodes: [linear], Original ATen: [aten.addmm]
        extern_kernels.addmm(primals_8, reinterpret_tensor(buf11, (1, 20), (0, 1), 0), reinterpret_tensor(primals_7, (20, 80), (1, 20), 0), alpha=1, beta=1, out=buf12)
        buf13 = reinterpret_tensor(buf16, (1, 80), (80, 1), 80)  # alias
        # Topologically Sorted Source Nodes: [linear_1], Original ATen: [aten.addmm]
        extern_kernels.addmm(primals_8, reinterpret_tensor(buf11, (1, 20), (0, 1), 20), reinterpret_tensor(primals_7, (20, 80), (1, 20), 0), alpha=1, beta=1, out=buf13)
        buf14 = reinterpret_tensor(buf16, (1, 80), (80, 1), 160)  # alias
        # Topologically Sorted Source Nodes: [linear_2], Original ATen: [aten.addmm]
        extern_kernels.addmm(primals_8, reinterpret_tensor(buf11, (1, 20), (0, 1), 40), reinterpret_tensor(primals_7, (20, 80), (1, 20), 0), alpha=1, beta=1, out=buf14)
        buf15 = reinterpret_tensor(buf16, (1, 80), (80, 1), 240)  # alias
        # Topologically Sorted Source Nodes: [linear_3], Original ATen: [aten.addmm]
        extern_kernels.addmm(primals_8, reinterpret_tensor(buf11, (1, 20), (0, 1), 60), reinterpret_tensor(primals_7, (20, 80), (1, 20), 0), alpha=1, beta=1, out=buf15)
        del primals_8
    return (reinterpret_tensor(buf16, (1, 4, 80), (80, 80, 1), 0), primals_2, primals_3, primals_4, buf0, buf1, buf2, buf5, buf8, reinterpret_tensor(buf11, (1, 20), (20, 1), 0), reinterpret_tensor(buf11, (1, 20), (20, 1), 20), reinterpret_tensor(buf11, (1, 20), (20, 1), 40), reinterpret_tensor(buf11, (1, 20), (20, 1), 60), primals_7, buf17, reinterpret_tensor(buf9, (80, 1, 9), (9, 720, 1), 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, 1), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((20, 1, 1, 1), (1, 1, 1, 1), device='cuda:0', dtype=torch.float32)
    primals_3 = rand_strided((20, 1, 1, 1), (1, 1, 1, 1), device='cuda:0', dtype=torch.float32)
    primals_4 = rand_strided((20, 1, 1, 1), (1, 1, 1, 1), device='cuda:0', dtype=torch.float32)
    primals_5 = rand_strided((10, 1, 1, 3, 1), (3, 3, 3, 1, 1), device='cuda:0', dtype=torch.float32)
    primals_6 = rand_strided((10, 1, 1, 1, 3), (3, 3, 3, 3, 1), device='cuda:0', dtype=torch.float32)
    primals_7 = rand_strided((80, 20), (20, 1), device='cuda:0', dtype=torch.float32)
    primals_8 = rand_strided((80, ), (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 torch
import torch.nn as nn
import torch.nn.functional as F
import torch.nn.init as init


class AttentionConv(nn.Module):

    def __init__(self, in_channels, out_channels, kernel_size, stride=1,
        padding=0, groups=1, bias=False):
        super(AttentionConv, self).__init__()
        self.out_channels = out_channels
        self.kernel_size = kernel_size
        self.stride = stride
        self.padding = padding
        self.groups = groups
        assert self.out_channels % self.groups == 0, 'out_channels should be divided by groups. (example: out_channels: 40, groups: 4)'
        self.rel_h = nn.Parameter(torch.randn(out_channels // 2, 1, 1,
            kernel_size, 1), requires_grad=True)
        self.rel_w = nn.Parameter(torch.randn(out_channels // 2, 1, 1, 1,
            kernel_size), requires_grad=True)
        self.key_conv = nn.Conv2d(in_channels, out_channels, kernel_size=1,
            bias=bias)
        self.query_conv = nn.Conv2d(in_channels, out_channels, kernel_size=
            1, bias=bias)
        self.value_conv = nn.Conv2d(in_channels, out_channels, kernel_size=
            1, bias=bias)
        self.reset_parameters()

    def forward(self, x):
        batch, _channels, height, width = x.size()
        padded_x = F.pad(x, [self.padding, self.padding, self.padding, self
            .padding])
        q_out = self.query_conv(x)
        k_out = self.key_conv(padded_x)
        v_out = self.value_conv(padded_x)
        k_out = k_out.unfold(2, self.kernel_size, self.stride).unfold(3,
            self.kernel_size, self.stride)
        v_out = v_out.unfold(2, self.kernel_size, self.stride).unfold(3,
            self.kernel_size, self.stride)
        k_out_h, k_out_w = k_out.split(self.out_channels // 2, dim=1)
        k_out = torch.cat((k_out_h + self.rel_h, k_out_w + self.rel_w), dim=1)
        k_out = k_out.contiguous().view(batch, self.groups, self.
            out_channels // self.groups, height, width, -1)
        v_out = v_out.contiguous().view(batch, self.groups, self.
            out_channels // self.groups, height, width, -1)
        q_out = q_out.view(batch, self.groups, self.out_channels // self.
            groups, height, width, 1)
        out = q_out * k_out
        out = F.softmax(out, dim=-1)
        out = torch.einsum('bnchwk,bnchwk -> bnchw', out, v_out).view(batch,
            -1, height, width)
        return out

    def reset_parameters(self):
        init.kaiming_normal_(self.key_conv.weight, mode='fan_out',
            nonlinearity='relu')
        init.kaiming_normal_(self.value_conv.weight, mode='fan_out',
            nonlinearity='relu')
        init.kaiming_normal_(self.query_conv.weight, mode='fan_out',
            nonlinearity='relu')
        init.normal_(self.rel_h, 0, 1)
        init.normal_(self.rel_w, 0, 1)


class BaseClassifier(nn.Module):
    _timestep_dimension = 2
    _max_timesteps = 2048
    _value_to_pad = 0

    @staticmethod
    def pad_variable_timesteps(tensor, timestep_dimension=
        _timestep_dimension, max_timesteps=_max_timesteps, value_to_pad=
        _value_to_pad):
        """
        Pads a variable-length tensor to a fixed length along the specified dimension.
        e.g. shape [1, 1, 200, 1280] --> [1, 1, 512, 1280], with dim=2.
        
        timestep_dimension: Dimension to pad along. For shape [a, b, c, d], the respective dims are [0, 1, 2, 3].
        max_timesteps: Number of elements to pad until.
        value_to_pad: Constant value used for padding.
        """
        number_of_timesteps = tensor.size(dim=timestep_dimension)
        assert number_of_timesteps <= max_timesteps, 'Input received that is longer than . Unable to pad.'
        number_of_padded_timesteps = max_timesteps - number_of_timesteps
        padding = [0, 0] * (len(tensor.shape) - timestep_dimension - 1) + [
            0, number_of_padded_timesteps]
        return F.pad(tensor, padding, 'constant', value_to_pad)


class ANNClassifier(BaseClassifier):

    def __init__(self, input_dim):
        super(ANNClassifier, self).__init__()
        self._pool_value = 4
        self.hidden_dim_1 = hidden_dim_1 = 20
        self.linear_input_dim = hidden_dim_1 * input_dim // self._pool_value
        self.out_dim = 80
        attn_hyperparams = {'kernel_size': 3, 'padding': 1}
        self.attn = AttentionConv(1, hidden_dim_1, **attn_hyperparams)
        self.dense = nn.Linear(self.linear_input_dim, self.out_dim)
        self.pool = nn.MaxPool2d((1, self._pool_value))

    def reshape_input(self, feature, group_size):
        down_sample_len = feature.size(1) // group_size
        feature = feature[:, :down_sample_len * group_size, :]
        reshape_feature = feature.reshape(feature.size(0) * down_sample_len,
            group_size * feature.size(2))
        return reshape_feature

    def forward(self, feature):
        feature = feature.unsqueeze(dim=0).unsqueeze(dim=1)
        feature = self.pool(feature)
        feature = self.attn(feature)
        feature = F.relu(feature)
        feature = feature.transpose(0, 1)
        feature = feature.view(-1, self.linear_input_dim)
        feature = torch.stack([self.dense(feature[index].unsqueeze(dim=0)) for
            index in range(feature.size()[0])])
        feature = feature.transpose(0, 1)
        return feature


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


def get_init_inputs():
    return [[], {'input_dim': 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
import torch.nn.init as init
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_max_pool2d_with_indices_0(in_ptr0, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp2 = triton_helpers.maximum(tmp1, tmp0)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp6 = triton_helpers.maximum(tmp5, tmp4)
    tl.store(out_ptr0 + x0, tmp6, xmask)


@triton.jit
def triton_poi_fused_constant_pad_nd_1(in_ptr0, out_ptr0, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 18
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 3
    x0 = xindex % 3
    x2 = xindex
    tmp0 = -1 + x1
    tmp1 = tl.full([1], 0, tl.int64)
    tmp2 = tmp0 >= tmp1
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = -1 + x0
    tmp6 = tmp5 >= tmp1
    tmp7 = tl.full([1], 1, tl.int64)
    tmp8 = tmp5 < tmp7
    tmp9 = tmp2 & tmp4
    tmp10 = tmp9 & tmp6
    tmp11 = tmp10 & tmp8
    tmp12 = tl.load(in_ptr0 + (-1 + x1), tmp11 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tl.store(out_ptr0 + x2, tmp12, xmask)


@triton.jit
def triton_per_fused__softmax_cat_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
    out_ptr0, out_ptr3, xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 80
    rnumel = 9
    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, :]
    rmask = rindex < rnumel
    x1 = xindex // 4
    r5 = rindex
    x0 = xindex % 4
    r3 = rindex // 3
    r2 = rindex % 3
    x4 = xindex
    tmp19 = tl.load(in_ptr3 + x4, xmask, eviction_policy='evict_last')
    tmp0 = x1
    tl.full([1, 1], 0, tl.int64)
    tmp3 = tl.full([1, 1], 10, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (r5 + 3 * x0 + 18 * x1), rmask & tmp4 & xmask,
        other=0.0)
    tmp6 = tl.load(in_ptr1 + (r3 + 3 * x1), rmask & tmp4 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp7 = tmp5 + tmp6
    tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype)
    tmp9 = tl.where(tmp4, tmp7, tmp8)
    tmp10 = tmp0 >= tmp3
    tl.full([1, 1], 20, tl.int64)
    tmp13 = tl.load(in_ptr0 + (180 + r5 + 3 * x0 + 18 * (-10 + x1)), rmask &
        tmp10 & xmask, other=0.0)
    tmp14 = tl.load(in_ptr2 + (r2 + 3 * (-10 + x1)), rmask & tmp10 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp15 = tmp13 + tmp14
    tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype)
    tmp17 = tl.where(tmp10, tmp15, tmp16)
    tmp18 = tl.where(tmp4, tmp9, tmp17)
    tmp20 = 0.0
    tmp21 = tmp19 >= tmp20
    tmp22 = 1.0
    tmp23 = -1.0
    tmp24 = tl.where(tmp21, tmp22, tmp23)
    tmp25 = tmp18 * tmp24
    tmp26 = tl.broadcast_to(tmp25, [XBLOCK, RBLOCK])
    tmp28 = tl.where(rmask & xmask, tmp26, float('-inf'))
    tmp29 = triton_helpers.max2(tmp28, 1)[:, None]
    tmp30 = tmp25 - tmp29
    tmp31 = tmp24 * tmp19
    tmp32 = tmp30 * tmp31
    tmp33 = tl_math.exp(tmp32)
    tmp34 = tl.broadcast_to(tmp33, [XBLOCK, RBLOCK])
    tmp36 = tl.where(rmask & xmask, tmp34, 0)
    tmp37 = tl.sum(tmp36, 1)[:, None]
    tmp38 = tmp33 / tmp37
    tl.store(out_ptr0 + (r5 + 9 * x4), tmp18, rmask & xmask)
    tl.store(out_ptr3 + (r5 + 9 * x4), tmp38, rmask & xmask)


@triton.jit
def triton_poi_fused_clone_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 720
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 9
    x1 = xindex // 9 % 4
    x2 = xindex // 36
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 3 * x1 + 18 * x2), xmask)
    tl.store(out_ptr0 + x3, tmp0, xmask)


@triton.jit
def triton_poi_fused_relu_threshold_backward_4(in_out_ptr0, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 80
    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 = tl.full([1], 0, tl.int32)
    tmp2 = triton_helpers.maximum(tmp1, tmp0)
    tmp3 = 0.0
    tmp4 = tmp2 <= tmp3
    tl.store(in_out_ptr0 + x0, tmp2, xmask)
    tl.store(out_ptr0 + x0, tmp4, 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, 1))
    assert_size_stride(primals_2, (20, 1, 1, 1), (1, 1, 1, 1))
    assert_size_stride(primals_3, (20, 1, 1, 1), (1, 1, 1, 1))
    assert_size_stride(primals_4, (20, 1, 1, 1), (1, 1, 1, 1))
    assert_size_stride(primals_5, (10, 1, 1, 3, 1), (3, 3, 3, 1, 1))
    assert_size_stride(primals_6, (10, 1, 1, 1, 3), (3, 3, 3, 3, 1))
    assert_size_stride(primals_7, (80, 20), (20, 1))
    assert_size_stride(primals_8, (80,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((1, 1, 4, 1), (4, 4, 1, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_max_pool2d_with_indices_0[grid(4)](primals_1, buf0,
            4, XBLOCK=4, num_warps=1, num_stages=1)
        del primals_1
        buf1 = empty_strided_cuda((1, 1, 6, 3), (18, 18, 3, 1), torch.float32)
        triton_poi_fused_constant_pad_nd_1[grid(18)](buf0, buf1, 18, XBLOCK
            =32, num_warps=1, num_stages=1)
        buf2 = 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(buf2, (1, 20, 4, 1), (80, 4, 1, 1))
        buf3 = extern_kernels.convolution(buf1, primals_3, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf3, (1, 20, 6, 3), (360, 18, 3, 1))
        buf4 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf4, (1, 20, 6, 3), (360, 18, 3, 1))
        buf5 = empty_strided_cuda((1, 20, 4, 1, 3, 3), (720, 36, 9, 9, 3, 1
            ), torch.float32)
        buf8 = empty_strided_cuda((1, 1, 20, 4, 1, 9), (720, 720, 36, 9, 9,
            1), torch.float32)
        triton_per_fused__softmax_cat_2[grid(80)](buf3, primals_5,
            primals_6, buf2, buf5, buf8, 80, 9, XBLOCK=1, num_warps=2,
            num_stages=1)
        del buf3
        del primals_5
        del primals_6
        buf9 = empty_strided_cuda((1, 20, 4, 1, 3, 3), (720, 36, 9, 9, 3, 1
            ), torch.float32)
        triton_poi_fused_clone_3[grid(720)](buf4, buf9, 720, XBLOCK=128,
            num_warps=4, num_stages=1)
        del buf4
        buf10 = empty_strided_cuda((80, 1, 1), (1, 1, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf8, (80, 1, 9), (9, 9, 1), 
            0), reinterpret_tensor(buf9, (80, 9, 1), (9, 1, 0), 0), out=buf10)
        buf11 = reinterpret_tensor(buf10, (1, 20, 4, 1), (80, 4, 1, 1), 0)
        del buf10
        buf17 = empty_strided_cuda((1, 20, 4, 1), (80, 4, 1, 1), torch.bool)
        triton_poi_fused_relu_threshold_backward_4[grid(80)](buf11, buf17, 
            80, XBLOCK=128, num_warps=4, num_stages=1)
        buf16 = empty_strided_cuda((4, 80), (80, 1), torch.float32)
        buf12 = reinterpret_tensor(buf16, (1, 80), (80, 1), 0)
        extern_kernels.addmm(primals_8, reinterpret_tensor(buf11, (1, 20),
            (0, 1), 0), reinterpret_tensor(primals_7, (20, 80), (1, 20), 0),
            alpha=1, beta=1, out=buf12)
        buf13 = reinterpret_tensor(buf16, (1, 80), (80, 1), 80)
        extern_kernels.addmm(primals_8, reinterpret_tensor(buf11, (1, 20),
            (0, 1), 20), reinterpret_tensor(primals_7, (20, 80), (1, 20), 0
            ), alpha=1, beta=1, out=buf13)
        buf14 = reinterpret_tensor(buf16, (1, 80), (80, 1), 160)
        extern_kernels.addmm(primals_8, reinterpret_tensor(buf11, (1, 20),
            (0, 1), 40), reinterpret_tensor(primals_7, (20, 80), (1, 20), 0
            ), alpha=1, beta=1, out=buf14)
        buf15 = reinterpret_tensor(buf16, (1, 80), (80, 1), 240)
        extern_kernels.addmm(primals_8, reinterpret_tensor(buf11, (1, 20),
            (0, 1), 60), reinterpret_tensor(primals_7, (20, 80), (1, 20), 0
            ), alpha=1, beta=1, out=buf15)
        del primals_8
    return (reinterpret_tensor(buf16, (1, 4, 80), (80, 80, 1), 0),
        primals_2, primals_3, primals_4, buf0, buf1, buf2, buf5, buf8,
        reinterpret_tensor(buf11, (1, 20), (20, 1), 0), reinterpret_tensor(
        buf11, (1, 20), (20, 1), 20), reinterpret_tensor(buf11, (1, 20), (
        20, 1), 40), reinterpret_tensor(buf11, (1, 20), (20, 1), 60),
        primals_7, buf17, reinterpret_tensor(buf9, (80, 1, 9), (9, 720, 1), 0))


class AttentionConv(nn.Module):

    def __init__(self, in_channels, out_channels, kernel_size, stride=1,
        padding=0, groups=1, bias=False):
        super(AttentionConv, self).__init__()
        self.out_channels = out_channels
        self.kernel_size = kernel_size
        self.stride = stride
        self.padding = padding
        self.groups = groups
        assert self.out_channels % self.groups == 0, 'out_channels should be divided by groups. (example: out_channels: 40, groups: 4)'
        self.rel_h = nn.Parameter(torch.randn(out_channels // 2, 1, 1,
            kernel_size, 1), requires_grad=True)
        self.rel_w = nn.Parameter(torch.randn(out_channels // 2, 1, 1, 1,
            kernel_size), requires_grad=True)
        self.key_conv = nn.Conv2d(in_channels, out_channels, kernel_size=1,
            bias=bias)
        self.query_conv = nn.Conv2d(in_channels, out_channels, kernel_size=
            1, bias=bias)
        self.value_conv = nn.Conv2d(in_channels, out_channels, kernel_size=
            1, bias=bias)
        self.reset_parameters()

    def forward(self, x):
        batch, _channels, height, width = x.size()
        padded_x = F.pad(x, [self.padding, self.padding, self.padding, self
            .padding])
        q_out = self.query_conv(x)
        k_out = self.key_conv(padded_x)
        v_out = self.value_conv(padded_x)
        k_out = k_out.unfold(2, self.kernel_size, self.stride).unfold(3,
            self.kernel_size, self.stride)
        v_out = v_out.unfold(2, self.kernel_size, self.stride).unfold(3,
            self.kernel_size, self.stride)
        k_out_h, k_out_w = k_out.split(self.out_channels // 2, dim=1)
        k_out = torch.cat((k_out_h + self.rel_h, k_out_w + self.rel_w), dim=1)
        k_out = k_out.contiguous().view(batch, self.groups, self.
            out_channels // self.groups, height, width, -1)
        v_out = v_out.contiguous().view(batch, self.groups, self.
            out_channels // self.groups, height, width, -1)
        q_out = q_out.view(batch, self.groups, self.out_channels // self.
            groups, height, width, 1)
        out = q_out * k_out
        out = F.softmax(out, dim=-1)
        out = torch.einsum('bnchwk,bnchwk -> bnchw', out, v_out).view(batch,
            -1, height, width)
        return out

    def reset_parameters(self):
        init.kaiming_normal_(self.key_conv.weight, mode='fan_out',
            nonlinearity='relu')
        init.kaiming_normal_(self.value_conv.weight, mode='fan_out',
            nonlinearity='relu')
        init.kaiming_normal_(self.query_conv.weight, mode='fan_out',
            nonlinearity='relu')
        init.normal_(self.rel_h, 0, 1)
        init.normal_(self.rel_w, 0, 1)


class BaseClassifier(nn.Module):
    _timestep_dimension = 2
    _max_timesteps = 2048
    _value_to_pad = 0

    @staticmethod
    def pad_variable_timesteps(tensor, timestep_dimension=
        _timestep_dimension, max_timesteps=_max_timesteps, value_to_pad=
        _value_to_pad):
        """
        Pads a variable-length tensor to a fixed length along the specified dimension.
        e.g. shape [1, 1, 200, 1280] --> [1, 1, 512, 1280], with dim=2.
        
        timestep_dimension: Dimension to pad along. For shape [a, b, c, d], the respective dims are [0, 1, 2, 3].
        max_timesteps: Number of elements to pad until.
        value_to_pad: Constant value used for padding.
        """
        number_of_timesteps = tensor.size(dim=timestep_dimension)
        assert number_of_timesteps <= max_timesteps, 'Input received that is longer than . Unable to pad.'
        number_of_padded_timesteps = max_timesteps - number_of_timesteps
        padding = [0, 0] * (len(tensor.shape) - timestep_dimension - 1) + [
            0, number_of_padded_timesteps]
        return F.pad(tensor, padding, 'constant', value_to_pad)


class ANNClassifierNew(BaseClassifier):

    def __init__(self, input_dim):
        super(ANNClassifierNew, self).__init__()
        self._pool_value = 4
        self.hidden_dim_1 = hidden_dim_1 = 20
        self.linear_input_dim = hidden_dim_1 * input_dim // self._pool_value
        self.out_dim = 80
        attn_hyperparams = {'kernel_size': 3, 'padding': 1}
        self.attn = AttentionConv(1, hidden_dim_1, **attn_hyperparams)
        self.dense = nn.Linear(self.linear_input_dim, self.out_dim)
        self.pool = nn.MaxPool2d((1, self._pool_value))

    def reshape_input(self, feature, group_size):
        down_sample_len = feature.size(1) // group_size
        feature = feature[:, :down_sample_len * group_size, :]
        reshape_feature = feature.reshape(feature.size(0) * down_sample_len,
            group_size * feature.size(2))
        return reshape_feature

    def forward(self, input_0):
        primals_5 = self.attn.rel_h
        primals_6 = self.attn.rel_w
        primals_2 = self.attn.key_conv.weight
        primals_3 = self.attn.query_conv.weight
        primals_4 = self.attn.value_conv.weight
        primals_7 = self.dense.weight
        primals_8 = self.dense.bias
        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]
