# 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_4/inductor_cache/vb/cvbgw3bw5twe7wijv7hbwqjfna72bvmog6omyzelmf2srgxeawya.py
# Topologically Sorted Source Nodes: [mean, sub, mul, std, add, truediv, norm], Original ATen: [aten.mean, aten.sub, aten.mul, aten.std, aten.add, aten.div]
# Source node to ATen node mapping:
#   add => add
#   mean => mean
#   mul => mul
#   norm => add_1
#   std => sqrt, var
#   sub => sub
#   truediv => div
# Graph fragment:
#   %mean : [num_users=2] = call_function[target=torch.ops.aten.mean.dim](args = (%primals_2, [-1], True), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%primals_2, %mean), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%primals_1, %sub), kwargs = {})
#   %var : [num_users=1] = call_function[target=torch.ops.aten.var.correction](args = (%primals_2, [-1]), kwargs = {correction: 1.0, keepdim: True})
#   %sqrt : [num_users=1] = call_function[target=torch.ops.aten.sqrt.default](args = (%var,), kwargs = {})
#   %add : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%sqrt, 1e-06), kwargs = {})
#   %div : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%mul, %add), kwargs = {})
#   %add_1 : [num_users=4] = call_function[target=torch.ops.aten.add.Tensor](args = (%div, %primals_3), kwargs = {})
triton_per_fused_add_div_mean_mul_std_sub_0 = async_compile.triton('triton_per_fused_add_div_mean_mul_std_sub_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.persistent_reduction(
    size_hints=[4, 512],
    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, 7), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_add_div_mean_mul_std_sub_0', 'mutated_arg_names': ['in_out_ptr0', 'in_out_ptr1'], 'no_x_dim': True, 'num_load': 3, 'num_reduction': 4, '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_add_div_mean_mul_std_sub_0(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, rnumel):
    xnumel = 4
    XBLOCK: tl.constexpr = 1
    rnumel = 400
    RBLOCK: tl.constexpr = 512
    xoffset = tl.program_id(0) * XBLOCK
    xindex = tl.full([1], xoffset, tl.int32)
    xmask = tl.full([RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[:]
    roffset = 0
    rmask = rindex < rnumel
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + (400*x0)), rmask, other=0.0)
    tmp26 = tl.load(in_ptr1 + (r1), rmask, eviction_policy='evict_last', other=0.0)
    tmp30 = tl.load(in_ptr2 + (r1), rmask, eviction_policy='evict_last', other=0.0)
    tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
    tmp3 = tl.where(rmask, tmp1, 0)
    tmp4 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0))
    tmp6 = tl.broadcast_to(tmp1, [RBLOCK])
    tmp8 = tl.where(rmask, tmp6, 0)
    tmp9 = triton_helpers.promote_to_tensor(tl.sum(tmp8, 0))
    tmp10 = tl.full([1], 400, tl.int32)
    tmp11 = tmp10.to(tl.float32)
    tmp12 = tmp9 / tmp11
    tmp13 = tmp1 - tmp12
    tmp14 = tmp13 * tmp13
    tmp15 = tl.broadcast_to(tmp14, [RBLOCK])
    tmp17 = tl.where(rmask, tmp15, 0)
    tmp18 = triton_helpers.promote_to_tensor(tl.sum(tmp17, 0))
    tmp19 = 400.0
    tmp20 = tmp4 / tmp19
    tmp21 = 399.0
    tmp22 = tmp18 / tmp21
    tmp23 = libdevice.sqrt(tmp22)
    tmp24 = 1e-06
    tmp25 = tmp23 + tmp24
    tmp27 = tmp0 - tmp20
    tmp28 = tmp26 * tmp27
    tmp29 = tmp28 / tmp25
    tmp31 = tmp29 + tmp30
    tl.debug_barrier()
    tl.store(in_out_ptr0 + (x0), tmp20, None)
    tl.debug_barrier()
    tl.store(in_out_ptr1 + (x0), tmp25, None)
    tl.store(out_ptr0 + (r1 + (400*x0)), tmp31, rmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/uu/cuuctcdy4k7vy5x25cov7dx4vkiebrp3v4culsqkq25uy54lopi7.py
# Topologically Sorted Source Nodes: [new_x, mean_1, sub_1, mul_1, std_1, add_3, truediv_2, norm_1], Original ATen: [aten.add, aten.mean, aten.sub, aten.mul, aten.std, aten.div]
# Source node to ATen node mapping:
#   add_3 => add_3
#   mean_1 => mean_1
#   mul_1 => mul_1
#   new_x => add_2
#   norm_1 => add_4
#   std_1 => sqrt_1, var_1
#   sub_1 => sub_2
#   truediv_2 => div_3
# Graph fragment:
#   %add_2 : [num_users=4] = call_function[target=torch.ops.aten.add.Tensor](args = (%primals_2, %view_11), kwargs = {})
#   %mean_1 : [num_users=2] = call_function[target=torch.ops.aten.mean.dim](args = (%add_2, [-1], True), kwargs = {})
#   %sub_2 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_2, %mean_1), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%primals_12, %sub_2), kwargs = {})
#   %var_1 : [num_users=1] = call_function[target=torch.ops.aten.var.correction](args = (%add_2, [-1]), kwargs = {correction: 1.0, keepdim: True})
#   %sqrt_1 : [num_users=2] = call_function[target=torch.ops.aten.sqrt.default](args = (%var_1,), kwargs = {})
#   %add_3 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sqrt_1, 1e-06), kwargs = {})
#   %div_3 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%mul_1, %add_3), kwargs = {})
#   %add_4 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%div_3, %primals_13), kwargs = {})
triton_red_fused_add_div_mean_mul_std_sub_1 = async_compile.triton('triton_red_fused_add_div_mean_mul_std_sub_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.reduction(
    size_hints=[16, 512],
    reduction_hint=ReductionHint.DEFAULT,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: '*fp32', 6: '*fp32', 7: 'i32', 8: '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, 7, 8), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_red_fused_add_div_mean_mul_std_sub_1', 'mutated_arg_names': ['in_out_ptr0', 'in_out_ptr1'], 'no_x_dim': False, 'num_load': 6, '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_red_fused_add_div_mean_mul_std_sub_1(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, rnumel, XBLOCK : tl.constexpr, RBLOCK : tl.constexpr):
    xnumel = 16
    rnumel = 400
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rbase = tl.arange(0, RBLOCK)[None, :]
    x0 = xindex % 4
    x1 = (xindex // 4)
    _tmp4 = tl.full([XBLOCK, RBLOCK], 0, tl.float32)
    x3 = xindex
    tmp6_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
    tmp6_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
    tmp6_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
    for roffset in range(0, rnumel, RBLOCK):
        rindex = roffset + rbase
        rmask = rindex < rnumel
        r2 = rindex
        tmp0 = tl.load(in_ptr0 + (r2 + (400*x0)), rmask & xmask, eviction_policy='evict_last', other=0.0)
        tmp1 = tl.load(in_ptr1 + (r2 + (400*x1)), rmask & xmask, eviction_policy='evict_last', other=0.0)
        tmp2 = tmp0 + tmp1
        tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
        tmp5 = _tmp4 + tmp3
        _tmp4 = tl.where(rmask & xmask, tmp5, _tmp4)
        tmp6_mean_next, tmp6_m2_next, tmp6_weight_next = triton_helpers.welford_reduce(
            tmp3, tmp6_mean, tmp6_m2, tmp6_weight, roffset == 0
        )
        tmp6_mean = tl.where(rmask & xmask, tmp6_mean_next, tmp6_mean)
        tmp6_m2 = tl.where(rmask & xmask, tmp6_m2_next, tmp6_m2)
        tmp6_weight = tl.where(rmask & xmask, tmp6_weight_next, tmp6_weight)
    tmp4 = tl.sum(_tmp4, 1)[:, None]
    tmp6_tmp, tmp7_tmp, tmp8_tmp = triton_helpers.welford(
        tmp6_mean, tmp6_m2, tmp6_weight, 1
    )
    tmp6 = tmp6_tmp[:, None]
    tmp7 = tmp7_tmp[:, None]
    tmp8 = tmp8_tmp[:, None]
    tmp9 = 400.0
    tmp10 = tmp4 / tmp9
    tmp11 = 399.0
    tmp12 = tmp7 / tmp11
    tmp13 = libdevice.sqrt(tmp12)
    tl.debug_barrier()
    tl.store(in_out_ptr0 + (x3), tmp10, xmask)
    tl.debug_barrier()
    tl.store(in_out_ptr1 + (x3), tmp13, xmask)
    for roffset in range(0, rnumel, RBLOCK):
        rindex = roffset + rbase
        rmask = rindex < rnumel
        r2 = rindex
        tmp14 = tl.load(in_ptr2 + (r2), rmask, eviction_policy='evict_last', other=0.0)
        tmp15 = tl.load(in_ptr0 + (r2 + (400*x0)), rmask & xmask, eviction_policy='evict_last', other=0.0)
        tmp16 = tl.load(in_ptr1 + (r2 + (400*x1)), rmask & xmask, eviction_policy='evict_last', other=0.0)
        tmp23 = tl.load(in_ptr3 + (r2), rmask, eviction_policy='evict_last', other=0.0)
        tmp17 = tmp15 + tmp16
        tmp18 = tmp17 - tmp10
        tmp19 = tmp14 * tmp18
        tmp20 = 1e-06
        tmp21 = tmp13 + tmp20
        tmp22 = tmp19 / tmp21
        tmp24 = tmp22 + tmp23
        tl.store(out_ptr0 + (r2 + (400*x3)), tmp24, rmask & xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/tm/ctmri6ixjpwzyx3nvgosen6iogsrb36vudlunt2utq22ypfkkdtq.py
# Topologically Sorted Source Nodes: [relu], Original ATen: [aten.relu, aten.threshold_backward]
# Source node to ATen node mapping:
#   relu => relu
# Graph fragment:
#   %relu : [num_users=2] = call_function[target=torch.ops.aten.relu.default](args = (%view_13,), kwargs = {})
#   %le : [num_users=1] = call_function[target=torch.ops.aten.le.Scalar](args = (%relu, 0), kwargs = {})
triton_poi_fused_relu_threshold_backward_2 = async_compile.triton('triton_poi_fused_relu_threshold_backward_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=[32768], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*i1', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_relu_threshold_backward_2', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 2, '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_2(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 32768
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = tl.full([XBLOCK], True, tl.int1)
    x2 = xindex
    x0 = xindex % 2048
    tmp0 = tl.load(in_out_ptr0 + (x2), None)
    tmp1 = tl.load(in_ptr0 + (x0), None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp5 = 0.0
    tmp6 = tmp4 <= tmp5
    tl.store(in_out_ptr0 + (x2), tmp4, None)
    tl.store(out_ptr0 + (x2), tmp6, None)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/4v/c4vyok55cbfbixgdxg6l2snqf6dof4md2cfwim4jvcj4ggvjfyfs.py
# Topologically Sorted Source Nodes: [new_x, new_x_1], Original ATen: [aten.add]
# Source node to ATen node mapping:
#   new_x => add_2
#   new_x_1 => add_5
# Graph fragment:
#   %add_2 : [num_users=4] = call_function[target=torch.ops.aten.add.Tensor](args = (%primals_2, %view_11), kwargs = {})
#   %add_5 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_2, %view_15), kwargs = {})
triton_poi_fused_add_3 = async_compile.triton('triton_poi_fused_add_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=[8192], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_3', 'mutated_arg_names': ['in_out_ptr0'], '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_add_3(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK : tl.constexpr):
    xnumel = 6400
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex % 1600
    x0 = xindex % 400
    x2 = (xindex // 1600)
    x4 = xindex
    tmp0 = tl.load(in_ptr0 + (x3), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (x0 + (400*x2)), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_out_ptr0 + (x4), xmask)
    tmp4 = tl.load(in_ptr2 + (x0), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp5 = tmp3 + tmp4
    tmp6 = tmp2 + tmp5
    tl.store(in_out_ptr0 + (x4), tmp6, 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, primals_14, primals_15, primals_16, primals_17 = args
    args.clear()
    assert_size_stride(primals_1, (400, ), (1, ))
    assert_size_stride(primals_2, (4, 400), (400, 1))
    assert_size_stride(primals_3, (400, ), (1, ))
    assert_size_stride(primals_4, (400, 400), (400, 1))
    assert_size_stride(primals_5, (400, ), (1, ))
    assert_size_stride(primals_6, (400, 400), (400, 1))
    assert_size_stride(primals_7, (400, ), (1, ))
    assert_size_stride(primals_8, (400, 400), (400, 1))
    assert_size_stride(primals_9, (400, ), (1, ))
    assert_size_stride(primals_10, (400, 400), (400, 1))
    assert_size_stride(primals_11, (400, ), (1, ))
    assert_size_stride(primals_12, (400, ), (1, ))
    assert_size_stride(primals_13, (400, ), (1, ))
    assert_size_stride(primals_14, (2048, 400), (400, 1))
    assert_size_stride(primals_15, (2048, ), (1, ))
    assert_size_stride(primals_16, (400, 2048), (2048, 1))
    assert_size_stride(primals_17, (400, ), (1, ))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        buf3 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        buf1 = reinterpret_tensor(buf0, (4, 1), (1, 1), 0); del buf0  # reuse
        buf5 = reinterpret_tensor(buf3, (4, 1), (1, 1), 0); del buf3  # reuse
        buf6 = empty_strided_cuda((4, 400), (400, 1), torch.float32)
        # Topologically Sorted Source Nodes: [mean, sub, mul, std, add, truediv, norm], Original ATen: [aten.mean, aten.sub, aten.mul, aten.std, aten.add, aten.div]
        stream0 = get_raw_stream(0)
        triton_per_fused_add_div_mean_mul_std_sub_0.run(buf1, buf5, primals_2, primals_1, primals_3, buf6, 4, 400, grid=grid(4), stream=stream0)
        del primals_1
        del primals_3
        buf7 = empty_strided_cuda((4, 400), (400, 1), torch.float32)
        # Topologically Sorted Source Nodes: [linear], Original ATen: [aten.addmm]
        extern_kernels.addmm(primals_5, buf6, reinterpret_tensor(primals_4, (400, 400), (1, 400), 0), alpha=1, beta=1, out=buf7)
        del primals_5
        buf8 = empty_strided_cuda((4, 400), (400, 1), torch.float32)
        # Topologically Sorted Source Nodes: [linear_1], Original ATen: [aten.addmm]
        extern_kernels.addmm(primals_7, buf6, reinterpret_tensor(primals_6, (400, 400), (1, 400), 0), alpha=1, beta=1, out=buf8)
        del primals_7
        buf9 = empty_strided_cuda((4, 400), (400, 1), torch.float32)
        # Topologically Sorted Source Nodes: [linear_2], Original ATen: [aten.addmm]
        extern_kernels.addmm(primals_9, buf6, reinterpret_tensor(primals_8, (400, 400), (1, 400), 0), alpha=1, beta=1, out=buf9)
        del primals_9
        # Topologically Sorted Source Nodes: [], Original ATen: []
        buf10 = torch.ops.aten._scaled_dot_product_efficient_attention.default(reinterpret_tensor(buf8, (4, 4, 1, 100), (400, 100, 400, 1), 0), reinterpret_tensor(buf7, (4, 4, 1, 100), (400, 100, 400, 1), 0), reinterpret_tensor(buf9, (4, 4, 1, 100), (400, 100, 400, 1), 0), None, True, scale=0.1)
        buf11 = buf10[0]
        buf12 = buf10[1]
        buf13 = buf10[2]
        buf14 = buf10[3]
        del buf10
        buf15 = empty_strided_cuda((4, 400), (400, 1), torch.float32)
        # Topologically Sorted Source Nodes: [output_1], Original ATen: [aten.addmm]
        extern_kernels.addmm(primals_11, reinterpret_tensor(buf11, (4, 400), (400, 1), 0), reinterpret_tensor(primals_10, (400, 400), (1, 400), 0), alpha=1, beta=1, out=buf15)
        del primals_11
        buf16 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
        buf19 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
        buf17 = reinterpret_tensor(buf16, (4, 4, 1), (4, 1, 1), 0); del buf16  # reuse
        buf21 = reinterpret_tensor(buf19, (4, 4, 1), (4, 1, 1), 0); del buf19  # reuse
        buf22 = empty_strided_cuda((4, 4, 400), (1600, 400, 1), torch.float32)
        # Topologically Sorted Source Nodes: [new_x, mean_1, sub_1, mul_1, std_1, add_3, truediv_2, norm_1], Original ATen: [aten.add, aten.mean, aten.sub, aten.mul, aten.std, aten.div]
        triton_red_fused_add_div_mean_mul_std_sub_1.run(buf17, buf21, primals_2, buf15, primals_12, primals_13, buf22, 16, 400, grid=grid(16), stream=stream0)
        del primals_13
        buf23 = empty_strided_cuda((16, 2048), (2048, 1), torch.float32)
        # Topologically Sorted Source Nodes: [], Original ATen: []
        extern_kernels.mm(reinterpret_tensor(buf22, (16, 400), (400, 1), 0), reinterpret_tensor(primals_14, (400, 2048), (1, 400), 0), out=buf23)
        buf24 = reinterpret_tensor(buf23, (4, 4, 2048), (8192, 2048, 1), 0); del buf23  # reuse
        buf27 = empty_strided_cuda((4, 4, 2048), (8192, 2048, 1), torch.bool)
        # Topologically Sorted Source Nodes: [relu], Original ATen: [aten.relu, aten.threshold_backward]
        triton_poi_fused_relu_threshold_backward_2.run(buf24, primals_15, buf27, 32768, grid=grid(32768), stream=stream0)
        del primals_15
        buf25 = empty_strided_cuda((16, 400), (400, 1), torch.float32)
        # Topologically Sorted Source Nodes: [], Original ATen: []
        extern_kernels.mm(reinterpret_tensor(buf24, (16, 2048), (2048, 1), 0), reinterpret_tensor(primals_16, (2048, 400), (1, 2048), 0), out=buf25)
        buf26 = reinterpret_tensor(buf25, (4, 4, 400), (1600, 400, 1), 0); del buf25  # reuse
        # Topologically Sorted Source Nodes: [new_x, new_x_1], Original ATen: [aten.add]
        triton_poi_fused_add_3.run(buf26, primals_2, buf15, primals_17, 6400, grid=grid(6400), stream=stream0)
        del primals_17
    return (buf26, primals_2, primals_12, buf1, buf5, buf6, reinterpret_tensor(buf7, (4, 4, 1, 100), (400, 100, 400, 1), 0), reinterpret_tensor(buf8, (4, 4, 1, 100), (400, 100, 400, 1), 0), reinterpret_tensor(buf9, (4, 4, 1, 100), (400, 100, 400, 1), 0), buf11, buf12, buf13, buf14, buf15, buf17, buf21, reinterpret_tensor(buf22, (16, 400), (400, 1), 0), reinterpret_tensor(buf24, (16, 2048), (2048, 1), 0), primals_16, buf27, primals_14, primals_10, primals_8, primals_6, primals_4, )


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((400, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((4, 400), (400, 1), device='cuda:0', dtype=torch.float32)
    primals_3 = rand_strided((400, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_4 = rand_strided((400, 400), (400, 1), device='cuda:0', dtype=torch.float32)
    primals_5 = rand_strided((400, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_6 = rand_strided((400, 400), (400, 1), device='cuda:0', dtype=torch.float32)
    primals_7 = rand_strided((400, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_8 = rand_strided((400, 400), (400, 1), device='cuda:0', dtype=torch.float32)
    primals_9 = rand_strided((400, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_10 = rand_strided((400, 400), (400, 1), device='cuda:0', dtype=torch.float32)
    primals_11 = rand_strided((400, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_12 = rand_strided((400, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_13 = rand_strided((400, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_14 = rand_strided((2048, 400), (400, 1), device='cuda:0', dtype=torch.float32)
    primals_15 = rand_strided((2048, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_16 = rand_strided((400, 2048), (2048, 1), device='cuda:0', dtype=torch.float32)
    primals_17 = rand_strided((400, ), (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, primals_14, primals_15, primals_16, primals_17])
    return print_performance(fn, times=times, repeat=repeat)


if __name__ == "__main__":
    from torch._inductor.wrapper_benchmark import compiled_module_main
    compiled_module_main('None', benchmark_compiled_module)

import math
import torch
import torch.nn as nn
import torch.nn.functional as F


def attention(q, k, v, d_k, mask=None, dropout=None):
    scores = torch.matmul(q, k.transpose(-2, -1)) / math.sqrt(d_k)
    if mask is not None:
        mask = mask.unsqueeze(1)
        scores = scores.masked_fill(mask == 0, -1000000000.0)
    scores = F.softmax(scores, dim=-1)
    if dropout is not None:
        scores = dropout(scores)
    output = torch.matmul(scores, v)
    return output


class FeedForward(nn.Module):

    def __init__(self, d_model, d_ff=2048, dropout=0.1):
        super().__init__()
        self.linear_1 = nn.Linear(d_model, d_ff)
        self.dropout = nn.Dropout(dropout)
        self.linear_2 = nn.Linear(d_ff, d_model)

    def forward(self, x):
        x = self.dropout(F.relu(self.linear_1(x)))
        x = self.linear_2(x)
        return x


class MultiHeadAttention(nn.Module):

    def __init__(self, heads, d_model, dropout=0.1):
        super().__init__()
        self.d_model = d_model
        self.d_k = d_model // heads
        self.h = heads
        self.q_linear = nn.Linear(d_model, d_model)
        self.v_linear = nn.Linear(d_model, d_model)
        self.k_linear = nn.Linear(d_model, d_model)
        self.dropout = nn.Dropout(dropout)
        self.out = nn.Linear(d_model, d_model)

    def forward(self, q, k, v, mask=None):
        bs = q.size(0)
        k = self.k_linear(k).view(bs, -1, self.h, self.d_k)
        q = self.q_linear(q).view(bs, -1, self.h, self.d_k)
        v = self.v_linear(v).view(bs, -1, self.h, self.d_k)
        k = k.transpose(1, 2)
        q = q.transpose(1, 2)
        v = v.transpose(1, 2)
        scores = attention(q, k, v, self.d_k, mask, self.dropout)
        concat = scores.transpose(1, 2).contiguous().view(bs, -1, self.d_model)
        output = self.out(concat)
        return output


class Norm(nn.Module):

    def __init__(self, d_model, eps=1e-06):
        super().__init__()
        self.size = d_model
        self.alpha = nn.Parameter(torch.ones(self.size))
        self.bias = nn.Parameter(torch.zeros(self.size))
        self.eps = eps

    def forward(self, x):
        norm = self.alpha * (x - x.mean(dim=-1, keepdim=True)) / (x.std(dim
            =-1, keepdim=True) + self.eps) + self.bias
        return norm


class Building_Block(nn.Module):

    def __init__(self, input_features, hidden_features, num_heads, dropout):
        super(Building_Block, self).__init__()
        self.input_features = input_features
        self.hidden_features = hidden_features
        self.embed_dim = 100 * self.hidden_features
        self.attn = MultiHeadAttention(num_heads, self.embed_dim, dropout)
        self.pos_ffn = FeedForward(self.embed_dim, dropout=dropout)
        self.norm_1 = Norm(self.embed_dim)
        self.norm_2 = Norm(self.embed_dim)
        self.dropout_1 = nn.Dropout(dropout)
        self.dropout_2 = nn.Dropout(dropout)

    def forward(self, x):
        x2 = self.norm_1(x)
        new_x = x + self.dropout_1(self.attn(x2, x2, x2))
        x2 = self.norm_2(new_x)
        new_x = new_x + self.dropout_2(self.pos_ffn(x2))
        return new_x


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


def get_init_inputs():
    return [[], {'input_features': 4, 'hidden_features': 4, 'num_heads': 4,
        'dropout': 0.5}]

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
import math
import torch.nn as nn
import torch.nn.functional as F
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_per_fused_add_div_mean_mul_std_sub_0(in_out_ptr0, in_out_ptr1,
    in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, rnumel):
    XBLOCK: tl.constexpr = 1
    rnumel = 400
    RBLOCK: tl.constexpr = 512
    xoffset = tl.program_id(0) * XBLOCK
    xindex = tl.full([1], xoffset, tl.int32)
    tl.full([RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[:]
    rmask = rindex < rnumel
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + 400 * x0), rmask, other=0.0)
    tmp26 = tl.load(in_ptr1 + r1, rmask, eviction_policy='evict_last',
        other=0.0)
    tmp30 = tl.load(in_ptr2 + r1, rmask, eviction_policy='evict_last',
        other=0.0)
    tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
    tmp3 = tl.where(rmask, tmp1, 0)
    tmp4 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0))
    tmp6 = tl.broadcast_to(tmp1, [RBLOCK])
    tmp8 = tl.where(rmask, tmp6, 0)
    tmp9 = triton_helpers.promote_to_tensor(tl.sum(tmp8, 0))
    tmp10 = tl.full([1], 400, tl.int32)
    tmp11 = tmp10.to(tl.float32)
    tmp12 = tmp9 / tmp11
    tmp13 = tmp1 - tmp12
    tmp14 = tmp13 * tmp13
    tmp15 = tl.broadcast_to(tmp14, [RBLOCK])
    tmp17 = tl.where(rmask, tmp15, 0)
    tmp18 = triton_helpers.promote_to_tensor(tl.sum(tmp17, 0))
    tmp19 = 400.0
    tmp20 = tmp4 / tmp19
    tmp21 = 399.0
    tmp22 = tmp18 / tmp21
    tmp23 = libdevice.sqrt(tmp22)
    tmp24 = 1e-06
    tmp25 = tmp23 + tmp24
    tmp27 = tmp0 - tmp20
    tmp28 = tmp26 * tmp27
    tmp29 = tmp28 / tmp25
    tmp31 = tmp29 + tmp30
    tl.debug_barrier()
    tl.store(in_out_ptr0 + x0, tmp20, None)
    tl.debug_barrier()
    tl.store(in_out_ptr1 + x0, tmp25, None)
    tl.store(out_ptr0 + (r1 + 400 * x0), tmp31, rmask)


@triton.jit
def triton_red_fused_add_div_mean_mul_std_sub_1(in_out_ptr0, in_out_ptr1,
    in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, rnumel, XBLOCK:
    tl.constexpr, RBLOCK: tl.constexpr):
    xnumel = 16
    rnumel = 400
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rbase = tl.arange(0, RBLOCK)[None, :]
    x0 = xindex % 4
    x1 = xindex // 4
    _tmp4 = tl.full([XBLOCK, RBLOCK], 0, tl.float32)
    x3 = xindex
    tmp6_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
    tmp6_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
    tmp6_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
    for roffset in range(0, rnumel, RBLOCK):
        rindex = roffset + rbase
        rmask = rindex < rnumel
        r2 = rindex
        tmp0 = tl.load(in_ptr0 + (r2 + 400 * x0), rmask & xmask,
            eviction_policy='evict_last', other=0.0)
        tmp1 = tl.load(in_ptr1 + (r2 + 400 * x1), rmask & xmask,
            eviction_policy='evict_last', other=0.0)
        tmp2 = tmp0 + tmp1
        tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
        tmp5 = _tmp4 + tmp3
        _tmp4 = tl.where(rmask & xmask, tmp5, _tmp4)
        tmp6_mean_next, tmp6_m2_next, tmp6_weight_next = (triton_helpers.
            welford_reduce(tmp3, tmp6_mean, tmp6_m2, tmp6_weight, roffset == 0)
            )
        tmp6_mean = tl.where(rmask & xmask, tmp6_mean_next, tmp6_mean)
        tmp6_m2 = tl.where(rmask & xmask, tmp6_m2_next, tmp6_m2)
        tmp6_weight = tl.where(rmask & xmask, tmp6_weight_next, tmp6_weight)
    tmp4 = tl.sum(_tmp4, 1)[:, None]
    tmp6_tmp, tmp7_tmp, tmp8_tmp = triton_helpers.welford(tmp6_mean,
        tmp6_m2, tmp6_weight, 1)
    tmp6_tmp[:, None]
    tmp7 = tmp7_tmp[:, None]
    tmp8_tmp[:, None]
    tmp9 = 400.0
    tmp10 = tmp4 / tmp9
    tmp11 = 399.0
    tmp12 = tmp7 / tmp11
    tmp13 = libdevice.sqrt(tmp12)
    tl.debug_barrier()
    tl.store(in_out_ptr0 + x3, tmp10, xmask)
    tl.debug_barrier()
    tl.store(in_out_ptr1 + x3, tmp13, xmask)
    for roffset in range(0, rnumel, RBLOCK):
        rindex = roffset + rbase
        rmask = rindex < rnumel
        r2 = rindex
        tmp14 = tl.load(in_ptr2 + r2, rmask, eviction_policy='evict_last',
            other=0.0)
        tmp15 = tl.load(in_ptr0 + (r2 + 400 * x0), rmask & xmask,
            eviction_policy='evict_last', other=0.0)
        tmp16 = tl.load(in_ptr1 + (r2 + 400 * x1), rmask & xmask,
            eviction_policy='evict_last', other=0.0)
        tmp23 = tl.load(in_ptr3 + r2, rmask, eviction_policy='evict_last',
            other=0.0)
        tmp17 = tmp15 + tmp16
        tmp18 = tmp17 - tmp10
        tmp19 = tmp14 * tmp18
        tmp20 = 1e-06
        tmp21 = tmp13 + tmp20
        tmp22 = tmp19 / tmp21
        tmp24 = tmp22 + tmp23
        tl.store(out_ptr0 + (r2 + 400 * x3), tmp24, rmask & xmask)


@triton.jit
def triton_poi_fused_relu_threshold_backward_2(in_out_ptr0, in_ptr0,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x2 = xindex
    x0 = xindex % 2048
    tmp0 = tl.load(in_out_ptr0 + x2, None)
    tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tmp5 = 0.0
    tmp6 = tmp4 <= tmp5
    tl.store(in_out_ptr0 + x2, tmp4, None)
    tl.store(out_ptr0 + x2, tmp6, None)


@triton.jit
def triton_poi_fused_add_3(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 6400
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex % 1600
    x0 = xindex % 400
    x2 = xindex // 1600
    x4 = xindex
    tmp0 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (x0 + 400 * x2), xmask, eviction_policy=
        'evict_last')
    tmp3 = tl.load(in_out_ptr0 + x4, xmask)
    tmp4 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp5 = tmp3 + tmp4
    tmp6 = tmp2 + tmp5
    tl.store(in_out_ptr0 + x4, tmp6, 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, primals_14, primals_15, primals_16, primals_17) = args
    args.clear()
    assert_size_stride(primals_1, (400,), (1,))
    assert_size_stride(primals_2, (4, 400), (400, 1))
    assert_size_stride(primals_3, (400,), (1,))
    assert_size_stride(primals_4, (400, 400), (400, 1))
    assert_size_stride(primals_5, (400,), (1,))
    assert_size_stride(primals_6, (400, 400), (400, 1))
    assert_size_stride(primals_7, (400,), (1,))
    assert_size_stride(primals_8, (400, 400), (400, 1))
    assert_size_stride(primals_9, (400,), (1,))
    assert_size_stride(primals_10, (400, 400), (400, 1))
    assert_size_stride(primals_11, (400,), (1,))
    assert_size_stride(primals_12, (400,), (1,))
    assert_size_stride(primals_13, (400,), (1,))
    assert_size_stride(primals_14, (2048, 400), (400, 1))
    assert_size_stride(primals_15, (2048,), (1,))
    assert_size_stride(primals_16, (400, 2048), (2048, 1))
    assert_size_stride(primals_17, (400,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        buf3 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
        buf1 = reinterpret_tensor(buf0, (4, 1), (1, 1), 0)
        del buf0
        buf5 = reinterpret_tensor(buf3, (4, 1), (1, 1), 0)
        del buf3
        buf6 = empty_strided_cuda((4, 400), (400, 1), torch.float32)
        get_raw_stream(0)
        triton_per_fused_add_div_mean_mul_std_sub_0[grid(4)](buf1, buf5,
            primals_2, primals_1, primals_3, buf6, 4, 400, num_warps=4,
            num_stages=1)
        del primals_1
        del primals_3
        buf7 = empty_strided_cuda((4, 400), (400, 1), torch.float32)
        extern_kernels.addmm(primals_5, buf6, reinterpret_tensor(primals_4,
            (400, 400), (1, 400), 0), alpha=1, beta=1, out=buf7)
        del primals_5
        buf8 = empty_strided_cuda((4, 400), (400, 1), torch.float32)
        extern_kernels.addmm(primals_7, buf6, reinterpret_tensor(primals_6,
            (400, 400), (1, 400), 0), alpha=1, beta=1, out=buf8)
        del primals_7
        buf9 = empty_strided_cuda((4, 400), (400, 1), torch.float32)
        extern_kernels.addmm(primals_9, buf6, reinterpret_tensor(primals_8,
            (400, 400), (1, 400), 0), alpha=1, beta=1, out=buf9)
        del primals_9
        buf10 = torch.ops.aten._scaled_dot_product_efficient_attention.default(
            reinterpret_tensor(buf8, (4, 4, 1, 100), (400, 100, 400, 1), 0),
            reinterpret_tensor(buf7, (4, 4, 1, 100), (400, 100, 400, 1), 0),
            reinterpret_tensor(buf9, (4, 4, 1, 100), (400, 100, 400, 1), 0),
            None, True, scale=0.1)
        buf11 = buf10[0]
        buf12 = buf10[1]
        buf13 = buf10[2]
        buf14 = buf10[3]
        del buf10
        buf15 = empty_strided_cuda((4, 400), (400, 1), torch.float32)
        extern_kernels.addmm(primals_11, reinterpret_tensor(buf11, (4, 400),
            (400, 1), 0), reinterpret_tensor(primals_10, (400, 400), (1, 
            400), 0), alpha=1, beta=1, out=buf15)
        del primals_11
        buf16 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
        buf19 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
        buf17 = reinterpret_tensor(buf16, (4, 4, 1), (4, 1, 1), 0)
        del buf16
        buf21 = reinterpret_tensor(buf19, (4, 4, 1), (4, 1, 1), 0)
        del buf19
        buf22 = empty_strided_cuda((4, 4, 400), (1600, 400, 1), torch.float32)
        triton_red_fused_add_div_mean_mul_std_sub_1[grid(16)](buf17, buf21,
            primals_2, buf15, primals_12, primals_13, buf22, 16, 400,
            XBLOCK=1, RBLOCK=512, num_warps=4, num_stages=1)
        del primals_13
        buf23 = empty_strided_cuda((16, 2048), (2048, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf22, (16, 400), (400, 1), 0),
            reinterpret_tensor(primals_14, (400, 2048), (1, 400), 0), out=buf23
            )
        buf24 = reinterpret_tensor(buf23, (4, 4, 2048), (8192, 2048, 1), 0)
        del buf23
        buf27 = empty_strided_cuda((4, 4, 2048), (8192, 2048, 1), torch.bool)
        triton_poi_fused_relu_threshold_backward_2[grid(32768)](buf24,
            primals_15, buf27, 32768, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_15
        buf25 = empty_strided_cuda((16, 400), (400, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf24, (16, 2048), (2048, 1), 
            0), reinterpret_tensor(primals_16, (2048, 400), (1, 2048), 0),
            out=buf25)
        buf26 = reinterpret_tensor(buf25, (4, 4, 400), (1600, 400, 1), 0)
        del buf25
        triton_poi_fused_add_3[grid(6400)](buf26, primals_2, buf15,
            primals_17, 6400, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_17
    return (buf26, primals_2, primals_12, buf1, buf5, buf6,
        reinterpret_tensor(buf7, (4, 4, 1, 100), (400, 100, 400, 1), 0),
        reinterpret_tensor(buf8, (4, 4, 1, 100), (400, 100, 400, 1), 0),
        reinterpret_tensor(buf9, (4, 4, 1, 100), (400, 100, 400, 1), 0),
        buf11, buf12, buf13, buf14, buf15, buf17, buf21, reinterpret_tensor
        (buf22, (16, 400), (400, 1), 0), reinterpret_tensor(buf24, (16, 
        2048), (2048, 1), 0), primals_16, buf27, primals_14, primals_10,
        primals_8, primals_6, primals_4)


def attention(q, k, v, d_k, mask=None, dropout=None):
    scores = torch.matmul(q, k.transpose(-2, -1)) / math.sqrt(d_k)
    if mask is not None:
        mask = mask.unsqueeze(1)
        scores = scores.masked_fill(mask == 0, -1000000000.0)
    scores = F.softmax(scores, dim=-1)
    if dropout is not None:
        scores = dropout(scores)
    output = torch.matmul(scores, v)
    return output


class FeedForward(nn.Module):

    def __init__(self, d_model, d_ff=2048, dropout=0.1):
        super().__init__()
        self.linear_1 = nn.Linear(d_model, d_ff)
        self.dropout = nn.Dropout(dropout)
        self.linear_2 = nn.Linear(d_ff, d_model)

    def forward(self, x):
        x = self.dropout(F.relu(self.linear_1(x)))
        x = self.linear_2(x)
        return x


class MultiHeadAttention(nn.Module):

    def __init__(self, heads, d_model, dropout=0.1):
        super().__init__()
        self.d_model = d_model
        self.d_k = d_model // heads
        self.h = heads
        self.q_linear = nn.Linear(d_model, d_model)
        self.v_linear = nn.Linear(d_model, d_model)
        self.k_linear = nn.Linear(d_model, d_model)
        self.dropout = nn.Dropout(dropout)
        self.out = nn.Linear(d_model, d_model)

    def forward(self, q, k, v, mask=None):
        bs = q.size(0)
        k = self.k_linear(k).view(bs, -1, self.h, self.d_k)
        q = self.q_linear(q).view(bs, -1, self.h, self.d_k)
        v = self.v_linear(v).view(bs, -1, self.h, self.d_k)
        k = k.transpose(1, 2)
        q = q.transpose(1, 2)
        v = v.transpose(1, 2)
        scores = attention(q, k, v, self.d_k, mask, self.dropout)
        concat = scores.transpose(1, 2).contiguous().view(bs, -1, self.d_model)
        output = self.out(concat)
        return output


class Norm(nn.Module):

    def __init__(self, d_model, eps=1e-06):
        super().__init__()
        self.size = d_model
        self.alpha = nn.Parameter(torch.ones(self.size))
        self.bias = nn.Parameter(torch.zeros(self.size))
        self.eps = eps

    def forward(self, x):
        norm = self.alpha * (x - x.mean(dim=-1, keepdim=True)) / (x.std(dim
            =-1, keepdim=True) + self.eps) + self.bias
        return norm


class Building_BlockNew(nn.Module):

    def __init__(self, input_features, hidden_features, num_heads, dropout):
        super(Building_BlockNew, self).__init__()
        self.input_features = input_features
        self.hidden_features = hidden_features
        self.embed_dim = 100 * self.hidden_features
        self.attn = MultiHeadAttention(num_heads, self.embed_dim, dropout)
        self.pos_ffn = FeedForward(self.embed_dim, dropout=dropout)
        self.norm_1 = Norm(self.embed_dim)
        self.norm_2 = Norm(self.embed_dim)
        self.dropout_1 = nn.Dropout(dropout)
        self.dropout_2 = nn.Dropout(dropout)

    def forward(self, input_0):
        primals_4 = self.attn.q_linear.weight
        primals_1 = self.attn.q_linear.bias
        primals_6 = self.attn.v_linear.weight
        primals_3 = self.attn.v_linear.bias
        primals_8 = self.attn.k_linear.weight
        primals_5 = self.attn.k_linear.bias
        primals_10 = self.attn.out.weight
        primals_7 = self.attn.out.bias
        primals_14 = self.pos_ffn.linear_1.weight
        primals_15 = self.pos_ffn.linear_1.bias
        primals_16 = self.pos_ffn.linear_2.weight
        primals_9 = self.pos_ffn.linear_2.bias
        primals_11 = self.norm_1.alpha
        primals_12 = self.norm_1.bias
        primals_13 = self.norm_2.alpha
        primals_17 = self.norm_2.bias
        primals_2 = 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, primals_14,
            primals_15, primals_16, primals_17])
        return output[0]
