# 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_1/inductor_cache/lj/cljnyjeqdxwdc6kx22wm5wsr5l74zl4oovgwpb47c3bd5f4fyhge.py
# Topologically Sorted Source Nodes: [max_1, x_spatial_mean, max_2, x_width_mean], Original ATen: [aten.max, aten.mean]
# Source node to ATen node mapping:
#   max_1 => max_1
#   max_2 => max_2
#   x_spatial_mean => mean
#   x_width_mean => mean_1
# Graph fragment:
#   %max_1 : [num_users=1] = call_function[target=torch.ops.aten.max.dim](args = (%primals_1, 1), kwargs = {})
#   %mean : [num_users=2] = call_function[target=torch.ops.aten.mean.dim](args = (%primals_1, [1]), kwargs = {})
#   %max_2 : [num_users=1] = call_function[target=torch.ops.aten.max.dim](args = (%getitem, 1), kwargs = {})
#   %mean_1 : [num_users=4] = call_function[target=torch.ops.aten.mean.dim](args = (%mean, [1]), kwargs = {})
triton_poi_fused_max_mean_0 = async_compile.triton('triton_poi_fused_max_mean_0', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

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

@triton_heuristics.pointwise(
    size_hints=[16], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_max_mean_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 16, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', '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_mean_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    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 + (64*x1)), xmask)
    tmp1 = tl.load(in_ptr0 + (16 + x0 + (64*x1)), xmask)
    tmp3 = tl.load(in_ptr0 + (32 + x0 + (64*x1)), xmask)
    tmp5 = tl.load(in_ptr0 + (48 + x0 + (64*x1)), xmask)
    tmp7 = tl.load(in_ptr0 + (4 + x0 + (64*x1)), xmask)
    tmp8 = tl.load(in_ptr0 + (20 + x0 + (64*x1)), xmask)
    tmp10 = tl.load(in_ptr0 + (36 + x0 + (64*x1)), xmask)
    tmp12 = tl.load(in_ptr0 + (52 + x0 + (64*x1)), xmask)
    tmp15 = tl.load(in_ptr0 + (8 + x0 + (64*x1)), xmask)
    tmp16 = tl.load(in_ptr0 + (24 + x0 + (64*x1)), xmask)
    tmp18 = tl.load(in_ptr0 + (40 + x0 + (64*x1)), xmask)
    tmp20 = tl.load(in_ptr0 + (56 + x0 + (64*x1)), xmask)
    tmp23 = tl.load(in_ptr0 + (12 + x0 + (64*x1)), xmask)
    tmp24 = tl.load(in_ptr0 + (28 + x0 + (64*x1)), xmask)
    tmp26 = tl.load(in_ptr0 + (44 + x0 + (64*x1)), xmask)
    tmp28 = tl.load(in_ptr0 + (60 + x0 + (64*x1)), xmask)
    tmp2 = triton_helpers.maximum(tmp0, tmp1)
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp6 = triton_helpers.maximum(tmp4, tmp5)
    tmp9 = triton_helpers.maximum(tmp7, tmp8)
    tmp11 = triton_helpers.maximum(tmp9, tmp10)
    tmp13 = triton_helpers.maximum(tmp11, tmp12)
    tmp14 = triton_helpers.maximum(tmp6, tmp13)
    tmp17 = triton_helpers.maximum(tmp15, tmp16)
    tmp19 = triton_helpers.maximum(tmp17, tmp18)
    tmp21 = triton_helpers.maximum(tmp19, tmp20)
    tmp22 = triton_helpers.maximum(tmp14, tmp21)
    tmp25 = triton_helpers.maximum(tmp23, tmp24)
    tmp27 = triton_helpers.maximum(tmp25, tmp26)
    tmp29 = triton_helpers.maximum(tmp27, tmp28)
    tmp30 = triton_helpers.maximum(tmp22, tmp29)
    tmp31 = tmp0 + tmp1
    tmp32 = tmp31 + tmp3
    tmp33 = tmp32 + tmp5
    tmp34 = 4.0
    tmp35 = tmp33 / tmp34
    tmp36 = tmp7 + tmp8
    tmp37 = tmp36 + tmp10
    tmp38 = tmp37 + tmp12
    tmp39 = tmp38 / tmp34
    tmp40 = tmp35 + tmp39
    tmp41 = tmp15 + tmp16
    tmp42 = tmp41 + tmp18
    tmp43 = tmp42 + tmp20
    tmp44 = tmp43 / tmp34
    tmp45 = tmp40 + tmp44
    tmp46 = tmp23 + tmp24
    tmp47 = tmp46 + tmp26
    tmp48 = tmp47 + tmp28
    tmp49 = tmp48 / tmp34
    tmp50 = tmp45 + tmp49
    tmp51 = tmp50 / tmp34
    tl.store(out_ptr0 + (x2), tmp30, xmask)
    tl.store(out_ptr1 + (x2), tmp51, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/rh/crhhlbr6s3ojf6mmkyc3mc7xkw4kwb4q5kufx3dvze2lphpxoprc.py
# Topologically Sorted Source Nodes: [max_1, x_spatial_mean, max_3, x_height_mean], Original ATen: [aten.max, aten.mean]
# Source node to ATen node mapping:
#   max_1 => max_1
#   max_3 => max_3
#   x_height_mean => mean_2
#   x_spatial_mean => mean
# Graph fragment:
#   %max_1 : [num_users=1] = call_function[target=torch.ops.aten.max.dim](args = (%primals_1, 1), kwargs = {})
#   %mean : [num_users=2] = call_function[target=torch.ops.aten.mean.dim](args = (%primals_1, [1]), kwargs = {})
#   %max_3 : [num_users=1] = call_function[target=torch.ops.aten.max.dim](args = (%getitem, 2), kwargs = {})
#   %mean_2 : [num_users=4] = call_function[target=torch.ops.aten.mean.dim](args = (%mean, [2]), kwargs = {})
triton_poi_fused_max_mean_1 = async_compile.triton('triton_poi_fused_max_mean_1', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

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

@triton_heuristics.pointwise(
    size_hints=[16], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_max_mean_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 16, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', '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_mean_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    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) + (64*x1)), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (16 + (4*x0) + (64*x1)), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (32 + (4*x0) + (64*x1)), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (48 + (4*x0) + (64*x1)), xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr0 + (1 + (4*x0) + (64*x1)), xmask, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr0 + (17 + (4*x0) + (64*x1)), xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr0 + (33 + (4*x0) + (64*x1)), xmask, eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr0 + (49 + (4*x0) + (64*x1)), xmask, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr0 + (2 + (4*x0) + (64*x1)), xmask, eviction_policy='evict_last')
    tmp16 = tl.load(in_ptr0 + (18 + (4*x0) + (64*x1)), xmask, eviction_policy='evict_last')
    tmp18 = tl.load(in_ptr0 + (34 + (4*x0) + (64*x1)), xmask, eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr0 + (50 + (4*x0) + (64*x1)), xmask, eviction_policy='evict_last')
    tmp23 = tl.load(in_ptr0 + (3 + (4*x0) + (64*x1)), xmask, eviction_policy='evict_last')
    tmp24 = tl.load(in_ptr0 + (19 + (4*x0) + (64*x1)), xmask, eviction_policy='evict_last')
    tmp26 = tl.load(in_ptr0 + (35 + (4*x0) + (64*x1)), xmask, eviction_policy='evict_last')
    tmp28 = tl.load(in_ptr0 + (51 + (4*x0) + (64*x1)), xmask, eviction_policy='evict_last')
    tmp2 = triton_helpers.maximum(tmp0, tmp1)
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp6 = triton_helpers.maximum(tmp4, tmp5)
    tmp9 = triton_helpers.maximum(tmp7, tmp8)
    tmp11 = triton_helpers.maximum(tmp9, tmp10)
    tmp13 = triton_helpers.maximum(tmp11, tmp12)
    tmp14 = triton_helpers.maximum(tmp6, tmp13)
    tmp17 = triton_helpers.maximum(tmp15, tmp16)
    tmp19 = triton_helpers.maximum(tmp17, tmp18)
    tmp21 = triton_helpers.maximum(tmp19, tmp20)
    tmp22 = triton_helpers.maximum(tmp14, tmp21)
    tmp25 = triton_helpers.maximum(tmp23, tmp24)
    tmp27 = triton_helpers.maximum(tmp25, tmp26)
    tmp29 = triton_helpers.maximum(tmp27, tmp28)
    tmp30 = triton_helpers.maximum(tmp22, tmp29)
    tmp31 = tmp0 + tmp1
    tmp32 = tmp31 + tmp3
    tmp33 = tmp32 + tmp5
    tmp34 = 4.0
    tmp35 = tmp33 / tmp34
    tmp36 = tmp7 + tmp8
    tmp37 = tmp36 + tmp10
    tmp38 = tmp37 + tmp12
    tmp39 = tmp38 / tmp34
    tmp40 = tmp35 + tmp39
    tmp41 = tmp15 + tmp16
    tmp42 = tmp41 + tmp18
    tmp43 = tmp42 + tmp20
    tmp44 = tmp43 / tmp34
    tmp45 = tmp40 + tmp44
    tmp46 = tmp23 + tmp24
    tmp47 = tmp46 + tmp26
    tmp48 = tmp47 + tmp28
    tmp49 = tmp48 / tmp34
    tmp50 = tmp45 + tmp49
    tmp51 = tmp50 / tmp34
    tl.store(out_ptr0 + (x2), tmp30, xmask)
    tl.store(out_ptr1 + (x2), tmp51, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/fp/cfp6aijow2g5is2smjrqj7kca6itit4xrxs2tseqvxiqv3qu5hs6.py
# Topologically Sorted Source Nodes: [x0_w_s], Original ATen: [aten._softmax]
# Source node to ATen node mapping:
#   x0_w_s => amax, exp, sub
# Graph fragment:
#   %amax : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%mean_1, [1], True), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%mean_1, %amax), kwargs = {})
#   %exp : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub,), kwargs = {})
triton_poi_fused__softmax_2 = async_compile.triton('triton_poi_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.pointwise(
    size_hints=[16], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__softmax_2', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 5, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = (xindex // 4)
    tmp0 = tl.load(in_ptr0 + (x2), xmask)
    tmp1 = tl.load(in_ptr0 + (4*x1), xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (2 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (3 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp3 = triton_helpers.maximum(tmp1, tmp2)
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp0 - tmp7
    tmp9 = tl_math.exp(tmp8)
    tl.store(out_ptr0 + (x2), tmp9, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/bx/cbx4apfrr3crlh45z5s5g364pozucicvtftrh7pt56jdgf4a2jrr.py
# Topologically Sorted Source Nodes: [x0_w_s, mul_1, add_1, y1_w_t], Original ATen: [aten._softmax, aten.mul, aten.add, aten.tanh]
# Source node to ATen node mapping:
#   add_1 => add_1
#   mul_1 => mul_1
#   x0_w_s => div, sum_1
#   y1_w_t => tanh_1
# Graph fragment:
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp, [1], True), kwargs = {})
#   %div : [num_users=2] = call_function[target=torch.ops.aten.div.Tensor](args = (%exp, %sum_1), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mm_1, %div), kwargs = {})
#   %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_1, %primals_5), kwargs = {})
#   %tanh_1 : [num_users=2] = call_function[target=torch.ops.aten.tanh.default](args = (%add_1,), kwargs = {})
triton_poi_fused__softmax_add_mul_tanh_3 = async_compile.triton('triton_poi_fused__softmax_add_mul_tanh_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=[16], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__softmax_add_mul_tanh_3', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 7, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused__softmax_add_mul_tanh_3(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = (xindex // 4)
    x0 = xindex % 4
    tmp0 = tl.load(in_ptr0 + (x2), xmask)
    tmp1 = tl.load(in_ptr0 + (4*x1), xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (2 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (3 + (4*x1)), xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr1 + (x1), xmask, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr2 + (x0), xmask, eviction_policy='evict_last')
    tmp3 = tmp1 + tmp2
    tmp5 = tmp3 + tmp4
    tmp7 = tmp5 + tmp6
    tmp8 = tmp0 / tmp7
    tmp10 = tmp9 * tmp8
    tmp12 = tmp10 + tmp11
    tmp13 = libdevice.tanh(tmp12)
    tl.store(out_ptr0 + (x2), tmp8, xmask)
    tl.store(out_ptr1 + (x2), tmp13, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/dx/cdx4ang72zvdfbxlznrenje56srowdkcyveiz3tbwpxvxwdaqox5.py
# Topologically Sorted Source Nodes: [mul_3, add_3, y0_h_t, mul_5, y2_h_t], Original ATen: [aten.mul, aten.add, aten.tanh]
# Source node to ATen node mapping:
#   add_3 => add_3
#   mul_3 => mul_3
#   mul_5 => mul_5
#   y0_h_t => tanh_2
#   y2_h_t => add_5
# Graph fragment:
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mm_3, %div_1), kwargs = {})
#   %add_3 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_3, %primals_10), kwargs = {})
#   %tanh_2 : [num_users=1] = call_function[target=torch.ops.aten.tanh.default](args = (%add_3,), kwargs = {})
#   %mul_5 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mm_5, %tanh_2), kwargs = {})
#   %add_5 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_5, %primals_13), kwargs = {})
triton_poi_fused_add_mul_tanh_4 = async_compile.triton('triton_poi_fused_add_mul_tanh_4', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

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

@triton_heuristics.pointwise(
    size_hints=[16], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_mul_tanh_4', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 5, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_add_mul_tanh_4(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, xnumel, XBLOCK : tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = (xindex // 4)
    x2 = xindex
    x0 = xindex % 4
    tmp0 = tl.load(in_ptr0 + (x1), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (x1), xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_out_ptr0 + (x2), xmask)
    tmp4 = tl.load(in_ptr2 + (x0), xmask, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr3 + (x0), xmask, eviction_policy='evict_last')
    tmp3 = tmp1 * tmp2
    tmp5 = tmp3 + tmp4
    tmp6 = libdevice.tanh(tmp5)
    tmp7 = tmp0 * tmp6
    tmp9 = tmp7 + tmp8
    tl.store(in_out_ptr0 + (x2), tmp9, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_1/inductor_cache/t5/ct5efyxuuwnr646jfbmmovyebswjv3rmpbb3bfkpc3u4ig2yggqy.py
# Topologically Sorted Source Nodes: [add_6, z], Original ATen: [aten.add, aten.mul]
# Source node to ATen node mapping:
#   add_6 => add_6
#   z => mul_6
# Graph fragment:
#   %add_6 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%unsqueeze, 1), kwargs = {})
#   %mul_6 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%primals_1, %add_6), kwargs = {})
triton_poi_fused_add_mul_5 = async_compile.triton('triton_poi_fused_add_mul_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=[256], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=90, major=9, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=132), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_mul_5', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 2, 'num_reduction': 0, 'backend_hash': 'B098E03CDA7B8ADC90DAFFDF24A2956451D1B13F297756A5DCC209498AA53705', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_add_mul_5(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 16
    x2 = (xindex // 64)
    tmp0 = tl.load(in_ptr0 + (x3), xmask)
    tmp1 = tl.load(in_ptr1 + (x0 + (16*x2)), xmask, eviction_policy='evict_last')
    tmp2 = libdevice.tanh(tmp1)
    tmp3 = 1.0
    tmp4 = tmp2 + tmp3
    tmp5 = tmp0 * tmp4
    tl.store(out_ptr0 + (x3), tmp5, 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, primals_11, primals_12, primals_13 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (4, 1), (1, 1))
    assert_size_stride(primals_3, (4, 1), (1, 1))
    assert_size_stride(primals_4, (1, 4), (4, 1))
    assert_size_stride(primals_5, (1, 4), (4, 1))
    assert_size_stride(primals_6, (4, 1), (1, 1))
    assert_size_stride(primals_7, (1, 4), (4, 1))
    assert_size_stride(primals_8, (4, 1), (1, 1))
    assert_size_stride(primals_9, (4, 1), (1, 1))
    assert_size_stride(primals_10, (1, 4), (4, 1))
    assert_size_stride(primals_11, (1, 4), (4, 1))
    assert_size_stride(primals_12, (4, 1), (1, 1))
    assert_size_stride(primals_13, (1, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [max_1, x_spatial_mean, max_2, x_width_mean], Original ATen: [aten.max, aten.mean]
        stream0 = get_raw_stream(0)
        triton_poi_fused_max_mean_0.run(primals_1, buf0, buf1, 16, grid=grid(16), stream=stream0)
        buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [max_1, x_spatial_mean, max_3, x_height_mean], Original ATen: [aten.max, aten.mean]
        triton_poi_fused_max_mean_1.run(primals_1, buf2, buf3, 16, grid=grid(16), stream=stream0)
        buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [x0_w_s], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_2.run(buf1, buf4, 16, grid=grid(16), stream=stream0)
        buf7 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        # Topologically Sorted Source Nodes: [y1_w], Original ATen: [aten.mm]
        extern_kernels.mm(buf0, primals_3, out=buf7)
        del primals_3
        buf5 = buf0; del buf0  # reuse
        buf8 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [x0_w_s, mul_1, add_1, y1_w_t], Original ATen: [aten._softmax, aten.mul, aten.add, aten.tanh]
        triton_poi_fused__softmax_add_mul_tanh_3.run(buf4, buf7, primals_5, buf5, buf8, 16, grid=grid(16), stream=stream0)
        del primals_5
        buf6 = buf7; del buf7  # reuse
        # Topologically Sorted Source Nodes: [y0_w], Original ATen: [aten.mm]
        extern_kernels.mm(buf1, primals_2, out=buf6)
        del primals_2
        buf9 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        # Topologically Sorted Source Nodes: [y2_w], Original ATen: [aten.mm]
        extern_kernels.mm(buf8, primals_6, out=buf9)
        buf10 = buf4; del buf4  # reuse
        # Topologically Sorted Source Nodes: [x0_h_s], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_2.run(buf3, buf10, 16, grid=grid(16), stream=stream0)
        buf13 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        # Topologically Sorted Source Nodes: [y1_h], Original ATen: [aten.mm]
        extern_kernels.mm(buf2, primals_9, out=buf13)
        del primals_9
        buf11 = buf2; del buf2  # reuse
        buf14 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [x0_h_s, mul_4, add_4, y1_h_t], Original ATen: [aten._softmax, aten.mul, aten.add, aten.tanh]
        triton_poi_fused__softmax_add_mul_tanh_3.run(buf10, buf13, primals_11, buf11, buf14, 16, grid=grid(16), stream=stream0)
        del buf10
        del primals_11
        buf12 = buf13; del buf13  # reuse
        # Topologically Sorted Source Nodes: [y0_h], Original ATen: [aten.mm]
        extern_kernels.mm(buf3, primals_8, out=buf12)
        del primals_8
        buf15 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        # Topologically Sorted Source Nodes: [y2_h], Original ATen: [aten.mm]
        extern_kernels.mm(buf14, primals_12, out=buf15)
        buf16 = buf11; del buf11  # reuse
        # Topologically Sorted Source Nodes: [mul_3, add_3, y0_h_t, mul_5, y2_h_t], Original ATen: [aten.mul, aten.add, aten.tanh]
        triton_poi_fused_add_mul_tanh_4.run(buf16, buf15, buf12, primals_10, primals_13, 16, grid=grid(16), stream=stream0)
        del primals_13
        buf17 = buf5; del buf5  # reuse
        # Topologically Sorted Source Nodes: [mul, add, y0_w_t, mul_2, y2_w_t], Original ATen: [aten.mul, aten.add, aten.tanh]
        triton_poi_fused_add_mul_tanh_4.run(buf17, buf9, buf6, primals_4, primals_7, 16, grid=grid(16), stream=stream0)
        del primals_7
        buf18 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [matmul_6], Original ATen: [aten.bmm]
        extern_kernels.bmm(reinterpret_tensor(buf16, (4, 4, 1), (4, 1, 0), 0), reinterpret_tensor(buf17, (4, 1, 4), (4, 0, 1), 0), out=buf18)
        buf19 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [add_6, z], Original ATen: [aten.add, aten.mul]
        triton_poi_fused_add_mul_5.run(primals_1, buf18, buf19, 256, grid=grid(256), stream=stream0)
    return (buf19, primals_1, primals_4, primals_10, buf1, buf3, buf6, buf8, buf9, buf12, buf14, buf15, buf18, reinterpret_tensor(buf16, (4, 1, 4), (4, 1, 1), 0), reinterpret_tensor(buf17, (4, 4, 1), (4, 1, 4), 0), reinterpret_tensor(primals_12, (1, 4), (1, 1), 0), reinterpret_tensor(primals_6, (1, 4), (1, 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, 4), (64, 16, 4, 1), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((4, 1), (1, 1), device='cuda:0', dtype=torch.float32)
    primals_3 = rand_strided((4, 1), (1, 1), device='cuda:0', dtype=torch.float32)
    primals_4 = rand_strided((1, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    primals_5 = rand_strided((1, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    primals_6 = rand_strided((4, 1), (1, 1), device='cuda:0', dtype=torch.float32)
    primals_7 = rand_strided((1, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    primals_8 = rand_strided((4, 1), (1, 1), device='cuda:0', dtype=torch.float32)
    primals_9 = rand_strided((4, 1), (1, 1), device='cuda:0', dtype=torch.float32)
    primals_10 = rand_strided((1, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    primals_11 = rand_strided((1, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    primals_12 = rand_strided((4, 1), (1, 1), device='cuda:0', dtype=torch.float32)
    primals_13 = rand_strided((1, 4), (4, 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, primals_11, primals_12, primals_13])
    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.parallel
import torch.utils.data.distributed


class SpatialAttentionLayer(nn.Module):

    def __init__(self, spatial_size):
        super(SpatialAttentionLayer, self).__init__()
        self.avg_pool = nn.AdaptiveAvgPool2d(1)
        self.max_pool = nn.AdaptiveMaxPool2d(1)
        self.softmax = nn.Softmax(dim=1)
        self.width_w0 = nn.Parameter(torch.ones(spatial_size, 1),
            requires_grad=True)
        self.width_w1 = nn.Parameter(torch.ones(spatial_size, 1),
            requires_grad=True)
        self.width_w2 = nn.Parameter(torch.ones(spatial_size, 1),
            requires_grad=True)
        self.width_bias0 = nn.Parameter(torch.zeros(1, spatial_size),
            requires_grad=True)
        self.width_bias1 = nn.Parameter(torch.zeros(1, spatial_size),
            requires_grad=True)
        self.width_bias2 = nn.Parameter(torch.zeros(1, spatial_size),
            requires_grad=True)
        self.height_w0 = nn.Parameter(torch.ones(spatial_size, 1),
            requires_grad=True)
        self.height_w1 = nn.Parameter(torch.ones(spatial_size, 1),
            requires_grad=True)
        self.height_w2 = nn.Parameter(torch.ones(spatial_size, 1),
            requires_grad=True)
        self.height_bias0 = nn.Parameter(torch.zeros(1, spatial_size),
            requires_grad=True)
        self.height_bias1 = nn.Parameter(torch.zeros(1, spatial_size),
            requires_grad=True)
        self.height_bias2 = nn.Parameter(torch.zeros(1, spatial_size),
            requires_grad=True)
        nn.init.xavier_uniform_(self.width_w0)
        nn.init.xavier_uniform_(self.width_w1)
        nn.init.xavier_uniform_(self.width_w2)
        nn.init.xavier_uniform_(self.height_w0)
        nn.init.xavier_uniform_(self.height_w1)
        nn.init.xavier_uniform_(self.height_w2)

    def forward(self, x):
        b, _c, h, w = x.size()
        x_spatial_max = torch.max(x, 1)[0]
        x_spatial_mean = torch.mean(x, 1)
        x_width_max = torch.max(x_spatial_max, 1)[0]
        x_width_mean = torch.mean(x_spatial_mean, 1)
        x_height_max = torch.max(x_spatial_max, 2)[0]
        x_height_mean = torch.mean(x_spatial_mean, 2)
        x0_w_s = self.softmax(x_width_mean)
        y0_w = torch.matmul(x_width_mean, self.width_w0)
        y1_w = torch.matmul(x_width_max, self.width_w1)
        y0_w_t = torch.tanh(y0_w * x0_w_s + self.width_bias0)
        y1_w_t = torch.tanh(y1_w * x0_w_s + self.width_bias1)
        y2_w = torch.matmul(y1_w_t, self.width_w2)
        y2_w_t = y2_w * y0_w_t + self.width_bias2
        x0_h_s = self.softmax(x_height_mean)
        y0_h = torch.matmul(x_height_mean, self.height_w0)
        y1_h = torch.matmul(x_height_max, self.height_w1)
        y0_h_t = torch.tanh(y0_h * x0_h_s + self.height_bias0)
        y1_h_t = torch.tanh(y1_h * x0_h_s + self.height_bias1)
        y2_h = torch.matmul(y1_h_t, self.height_w2)
        y2_h_t = y2_h * y0_h_t + self.height_bias2
        spatial = torch.tanh(torch.matmul(y2_h_t.view(b, h, 1), y2_w_t.view
            (b, 1, w))).unsqueeze(1)
        z = x * (spatial + 1)
        return z


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


def get_init_inputs():
    return [[], {'spatial_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
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
import torch.nn as nn
import torch.nn.parallel
import torch.utils.data.distributed
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_mean_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 16
    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 + 64 * x1), xmask)
    tmp1 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask)
    tmp3 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask)
    tmp5 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask)
    tmp7 = tl.load(in_ptr0 + (4 + x0 + 64 * x1), xmask)
    tmp8 = tl.load(in_ptr0 + (20 + x0 + 64 * x1), xmask)
    tmp10 = tl.load(in_ptr0 + (36 + x0 + 64 * x1), xmask)
    tmp12 = tl.load(in_ptr0 + (52 + x0 + 64 * x1), xmask)
    tmp15 = tl.load(in_ptr0 + (8 + x0 + 64 * x1), xmask)
    tmp16 = tl.load(in_ptr0 + (24 + x0 + 64 * x1), xmask)
    tmp18 = tl.load(in_ptr0 + (40 + x0 + 64 * x1), xmask)
    tmp20 = tl.load(in_ptr0 + (56 + x0 + 64 * x1), xmask)
    tmp23 = tl.load(in_ptr0 + (12 + x0 + 64 * x1), xmask)
    tmp24 = tl.load(in_ptr0 + (28 + x0 + 64 * x1), xmask)
    tmp26 = tl.load(in_ptr0 + (44 + x0 + 64 * x1), xmask)
    tmp28 = tl.load(in_ptr0 + (60 + x0 + 64 * x1), xmask)
    tmp2 = triton_helpers.maximum(tmp0, tmp1)
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp6 = triton_helpers.maximum(tmp4, tmp5)
    tmp9 = triton_helpers.maximum(tmp7, tmp8)
    tmp11 = triton_helpers.maximum(tmp9, tmp10)
    tmp13 = triton_helpers.maximum(tmp11, tmp12)
    tmp14 = triton_helpers.maximum(tmp6, tmp13)
    tmp17 = triton_helpers.maximum(tmp15, tmp16)
    tmp19 = triton_helpers.maximum(tmp17, tmp18)
    tmp21 = triton_helpers.maximum(tmp19, tmp20)
    tmp22 = triton_helpers.maximum(tmp14, tmp21)
    tmp25 = triton_helpers.maximum(tmp23, tmp24)
    tmp27 = triton_helpers.maximum(tmp25, tmp26)
    tmp29 = triton_helpers.maximum(tmp27, tmp28)
    tmp30 = triton_helpers.maximum(tmp22, tmp29)
    tmp31 = tmp0 + tmp1
    tmp32 = tmp31 + tmp3
    tmp33 = tmp32 + tmp5
    tmp34 = 4.0
    tmp35 = tmp33 / tmp34
    tmp36 = tmp7 + tmp8
    tmp37 = tmp36 + tmp10
    tmp38 = tmp37 + tmp12
    tmp39 = tmp38 / tmp34
    tmp40 = tmp35 + tmp39
    tmp41 = tmp15 + tmp16
    tmp42 = tmp41 + tmp18
    tmp43 = tmp42 + tmp20
    tmp44 = tmp43 / tmp34
    tmp45 = tmp40 + tmp44
    tmp46 = tmp23 + tmp24
    tmp47 = tmp46 + tmp26
    tmp48 = tmp47 + tmp28
    tmp49 = tmp48 / tmp34
    tmp50 = tmp45 + tmp49
    tmp51 = tmp50 / tmp34
    tl.store(out_ptr0 + x2, tmp30, xmask)
    tl.store(out_ptr1 + x2, tmp51, xmask)


@triton.jit
def triton_poi_fused_max_mean_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 16
    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 + 64 * x1), xmask, eviction_policy=
        'evict_last')
    tmp1 = tl.load(in_ptr0 + (16 + 4 * x0 + 64 * x1), xmask,
        eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (32 + 4 * x0 + 64 * x1), xmask,
        eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (48 + 4 * x0 + 64 * x1), xmask,
        eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr0 + (1 + 4 * x0 + 64 * x1), xmask, eviction_policy
        ='evict_last')
    tmp8 = tl.load(in_ptr0 + (17 + 4 * x0 + 64 * x1), xmask,
        eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr0 + (33 + 4 * x0 + 64 * x1), xmask,
        eviction_policy='evict_last')
    tmp12 = tl.load(in_ptr0 + (49 + 4 * x0 + 64 * x1), xmask,
        eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr0 + (2 + 4 * x0 + 64 * x1), xmask,
        eviction_policy='evict_last')
    tmp16 = tl.load(in_ptr0 + (18 + 4 * x0 + 64 * x1), xmask,
        eviction_policy='evict_last')
    tmp18 = tl.load(in_ptr0 + (34 + 4 * x0 + 64 * x1), xmask,
        eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr0 + (50 + 4 * x0 + 64 * x1), xmask,
        eviction_policy='evict_last')
    tmp23 = tl.load(in_ptr0 + (3 + 4 * x0 + 64 * x1), xmask,
        eviction_policy='evict_last')
    tmp24 = tl.load(in_ptr0 + (19 + 4 * x0 + 64 * x1), xmask,
        eviction_policy='evict_last')
    tmp26 = tl.load(in_ptr0 + (35 + 4 * x0 + 64 * x1), xmask,
        eviction_policy='evict_last')
    tmp28 = tl.load(in_ptr0 + (51 + 4 * x0 + 64 * x1), xmask,
        eviction_policy='evict_last')
    tmp2 = triton_helpers.maximum(tmp0, tmp1)
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp6 = triton_helpers.maximum(tmp4, tmp5)
    tmp9 = triton_helpers.maximum(tmp7, tmp8)
    tmp11 = triton_helpers.maximum(tmp9, tmp10)
    tmp13 = triton_helpers.maximum(tmp11, tmp12)
    tmp14 = triton_helpers.maximum(tmp6, tmp13)
    tmp17 = triton_helpers.maximum(tmp15, tmp16)
    tmp19 = triton_helpers.maximum(tmp17, tmp18)
    tmp21 = triton_helpers.maximum(tmp19, tmp20)
    tmp22 = triton_helpers.maximum(tmp14, tmp21)
    tmp25 = triton_helpers.maximum(tmp23, tmp24)
    tmp27 = triton_helpers.maximum(tmp25, tmp26)
    tmp29 = triton_helpers.maximum(tmp27, tmp28)
    tmp30 = triton_helpers.maximum(tmp22, tmp29)
    tmp31 = tmp0 + tmp1
    tmp32 = tmp31 + tmp3
    tmp33 = tmp32 + tmp5
    tmp34 = 4.0
    tmp35 = tmp33 / tmp34
    tmp36 = tmp7 + tmp8
    tmp37 = tmp36 + tmp10
    tmp38 = tmp37 + tmp12
    tmp39 = tmp38 / tmp34
    tmp40 = tmp35 + tmp39
    tmp41 = tmp15 + tmp16
    tmp42 = tmp41 + tmp18
    tmp43 = tmp42 + tmp20
    tmp44 = tmp43 / tmp34
    tmp45 = tmp40 + tmp44
    tmp46 = tmp23 + tmp24
    tmp47 = tmp46 + tmp26
    tmp48 = tmp47 + tmp28
    tmp49 = tmp48 / tmp34
    tmp50 = tmp45 + tmp49
    tmp51 = tmp50 / tmp34
    tl.store(out_ptr0 + x2, tmp30, xmask)
    tl.store(out_ptr1 + x2, tmp51, xmask)


@triton.jit
def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp3 = triton_helpers.maximum(tmp1, tmp2)
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp0 - tmp7
    tmp9 = tl_math.exp(tmp8)
    tl.store(out_ptr0 + x2, tmp9, xmask)


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


@triton.jit
def triton_poi_fused_add_mul_tanh_4(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2,
    in_ptr3, xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 4
    x2 = xindex
    x0 = xindex % 4
    tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_out_ptr0 + x2, xmask)
    tmp4 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
    tmp3 = tmp1 * tmp2
    tmp5 = tmp3 + tmp4
    tmp6 = libdevice.tanh(tmp5)
    tmp7 = tmp0 * tmp6
    tmp9 = tmp7 + tmp8
    tl.store(in_out_ptr0 + x2, tmp9, xmask)


@triton.jit
def triton_poi_fused_add_mul_5(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 16
    x2 = xindex // 64
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr1 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp2 = libdevice.tanh(tmp1)
    tmp3 = 1.0
    tmp4 = tmp2 + tmp3
    tmp5 = tmp0 * tmp4
    tl.store(out_ptr0 + x3, tmp5, xmask)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
        primals_13) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (4, 1), (1, 1))
    assert_size_stride(primals_3, (4, 1), (1, 1))
    assert_size_stride(primals_4, (1, 4), (4, 1))
    assert_size_stride(primals_5, (1, 4), (4, 1))
    assert_size_stride(primals_6, (4, 1), (1, 1))
    assert_size_stride(primals_7, (1, 4), (4, 1))
    assert_size_stride(primals_8, (4, 1), (1, 1))
    assert_size_stride(primals_9, (4, 1), (1, 1))
    assert_size_stride(primals_10, (1, 4), (4, 1))
    assert_size_stride(primals_11, (1, 4), (4, 1))
    assert_size_stride(primals_12, (4, 1), (1, 1))
    assert_size_stride(primals_13, (1, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_max_mean_0[grid(16)](primals_1, buf0, buf1, 16,
            XBLOCK=16, num_warps=1, num_stages=1)
        buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused_max_mean_1[grid(16)](primals_1, buf2, buf3, 16,
            XBLOCK=16, num_warps=1, num_stages=1)
        buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused__softmax_2[grid(16)](buf1, buf4, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        buf7 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        extern_kernels.mm(buf0, primals_3, out=buf7)
        del primals_3
        buf5 = buf0
        del buf0
        buf8 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused__softmax_add_mul_tanh_3[grid(16)](buf4, buf7,
            primals_5, buf5, buf8, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del primals_5
        buf6 = buf7
        del buf7
        extern_kernels.mm(buf1, primals_2, out=buf6)
        del primals_2
        buf9 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        extern_kernels.mm(buf8, primals_6, out=buf9)
        buf10 = buf4
        del buf4
        triton_poi_fused__softmax_2[grid(16)](buf3, buf10, 16, XBLOCK=16,
            num_warps=1, num_stages=1)
        buf13 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        extern_kernels.mm(buf2, primals_9, out=buf13)
        del primals_9
        buf11 = buf2
        del buf2
        buf14 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused__softmax_add_mul_tanh_3[grid(16)](buf10, buf13,
            primals_11, buf11, buf14, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del buf10
        del primals_11
        buf12 = buf13
        del buf13
        extern_kernels.mm(buf3, primals_8, out=buf12)
        del primals_8
        buf15 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
        extern_kernels.mm(buf14, primals_12, out=buf15)
        buf16 = buf11
        del buf11
        triton_poi_fused_add_mul_tanh_4[grid(16)](buf16, buf15, buf12,
            primals_10, primals_13, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del primals_13
        buf17 = buf5
        del buf5
        triton_poi_fused_add_mul_tanh_4[grid(16)](buf17, buf9, buf6,
            primals_4, primals_7, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del primals_7
        buf18 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf16, (4, 4, 1), (4, 1, 0), 
            0), reinterpret_tensor(buf17, (4, 1, 4), (4, 0, 1), 0), out=buf18)
        buf19 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_add_mul_5[grid(256)](primals_1, buf18, buf19, 256,
            XBLOCK=128, num_warps=4, num_stages=1)
    return (buf19, primals_1, primals_4, primals_10, buf1, buf3, buf6, buf8,
        buf9, buf12, buf14, buf15, buf18, reinterpret_tensor(buf16, (4, 1, 
        4), (4, 1, 1), 0), reinterpret_tensor(buf17, (4, 4, 1), (4, 1, 4), 
        0), reinterpret_tensor(primals_12, (1, 4), (1, 1), 0),
        reinterpret_tensor(primals_6, (1, 4), (1, 1), 0))


class SpatialAttentionLayerNew(nn.Module):

    def __init__(self, spatial_size):
        super(SpatialAttentionLayerNew, self).__init__()
        self.avg_pool = nn.AdaptiveAvgPool2d(1)
        self.max_pool = nn.AdaptiveMaxPool2d(1)
        self.softmax = nn.Softmax(dim=1)
        self.width_w0 = nn.Parameter(torch.ones(spatial_size, 1),
            requires_grad=True)
        self.width_w1 = nn.Parameter(torch.ones(spatial_size, 1),
            requires_grad=True)
        self.width_w2 = nn.Parameter(torch.ones(spatial_size, 1),
            requires_grad=True)
        self.width_bias0 = nn.Parameter(torch.zeros(1, spatial_size),
            requires_grad=True)
        self.width_bias1 = nn.Parameter(torch.zeros(1, spatial_size),
            requires_grad=True)
        self.width_bias2 = nn.Parameter(torch.zeros(1, spatial_size),
            requires_grad=True)
        self.height_w0 = nn.Parameter(torch.ones(spatial_size, 1),
            requires_grad=True)
        self.height_w1 = nn.Parameter(torch.ones(spatial_size, 1),
            requires_grad=True)
        self.height_w2 = nn.Parameter(torch.ones(spatial_size, 1),
            requires_grad=True)
        self.height_bias0 = nn.Parameter(torch.zeros(1, spatial_size),
            requires_grad=True)
        self.height_bias1 = nn.Parameter(torch.zeros(1, spatial_size),
            requires_grad=True)
        self.height_bias2 = nn.Parameter(torch.zeros(1, spatial_size),
            requires_grad=True)
        nn.init.xavier_uniform_(self.width_w0)
        nn.init.xavier_uniform_(self.width_w1)
        nn.init.xavier_uniform_(self.width_w2)
        nn.init.xavier_uniform_(self.height_w0)
        nn.init.xavier_uniform_(self.height_w1)
        nn.init.xavier_uniform_(self.height_w2)

    def forward(self, input_0):
        primals_2 = self.width_w0
        primals_3 = self.width_w1
        primals_6 = self.width_w2
        primals_4 = self.width_bias0
        primals_5 = self.width_bias1
        primals_7 = self.width_bias2
        primals_8 = self.height_w0
        primals_9 = self.height_w1
        primals_12 = self.height_w2
        primals_10 = self.height_bias0
        primals_11 = self.height_bias1
        primals_13 = self.height_bias2
        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, primals_11, primals_12, primals_13])
        return output[0]
