# 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/yl/cylmztthhqsuazxqdnn3s5mwrv4ht4vltlbbcl2pu45p6l64wrd3.py
# Topologically Sorted Source Nodes: [sub, inputs], Original ATen: [aten.sub, aten.div]
# Source node to ATen node mapping:
#   inputs => div
#   sub => sub
# Graph fragment:
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%primals_2, %primals_1), kwargs = {})
#   %div : [num_users=2] = call_function[target=torch.ops.aten.div.Tensor](args = (%sub, %primals_3), kwargs = {})
triton_poi_fused_div_sub_0 = async_compile.triton('triton_poi_fused_div_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.pointwise(
    size_hints=[16], 
    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_div_sub_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 3, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_div_sub_0(in_ptr0, in_ptr1, in_ptr2, 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
    x0 = xindex % 4
    tmp0 = tl.load(in_ptr0 + (x2), xmask)
    tmp1 = tl.load(in_ptr1 + (x0), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + (x0), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 - tmp1
    tmp4 = tmp2 / tmp3
    tl.store(out_ptr0 + (x2), tmp4, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/su/csuizz2ownuafectvusuawmeivm2ftgfnsijcxph6sw2bq3rztvj.py
# Topologically Sorted Source Nodes: [inputs_1, inputs_2], Original ATen: [aten.add, aten.silu]
# Source node to ATen node mapping:
#   inputs_1 => add
#   inputs_2 => mul, sigmoid
# Graph fragment:
#   %add : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%bmm, %primals_5), kwargs = {})
#   %sigmoid : [num_users=1] = call_function[target=torch.ops.aten.sigmoid.default](args = (%add,), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%add, %sigmoid), kwargs = {})
triton_poi_fused_add_silu_1 = async_compile.triton('triton_poi_fused_add_silu_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=[4096], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_silu_1', 'mutated_arg_names': [], '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_add_silu_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 3200
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 200
    x2 = (xindex // 800)
    tmp0 = tl.load(in_ptr0 + (x3), xmask)
    tmp1 = tl.load(in_ptr1 + (x0 + (200*x2)), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.sigmoid(tmp2)
    tmp4 = tmp2 * tmp3
    tl.store(out_ptr0 + (x3), tmp4, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/zb/czbdw5y33wdeoyorbmsurpyiyxyzndcnzhlq75se72y2xog2pq6h.py
# Topologically Sorted Source Nodes: [inputs_13], Original ATen: [aten.add]
# Source node to ATen node mapping:
#   inputs_13 => add_6
# Graph fragment:
#   %add_6 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%bmm_6, %primals_17), kwargs = {})
triton_poi_fused_add_2 = async_compile.triton('triton_poi_fused_add_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=[128], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_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_add_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK : tl.constexpr):
    xnumel = 128
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 8
    x2 = (xindex // 32)
    tmp0 = tl.load(in_out_ptr0 + (x3), xmask)
    tmp1 = tl.load(in_ptr0 + (x0 + (8*x2)), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + (x3), tmp2, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/gv/cgvoihs2me7l4uwmhcvmzqpxv3oby3zgl3mihluiy7ns4ykscrtg.py
# Topologically Sorted Source Nodes: [sub_1, softplus, logvar_1, sub_3, softplus_1, logvar_2], Original ATen: [aten.sub, aten.softplus, aten.add]
# Source node to ATen node mapping:
#   logvar_1 => sub_2
#   logvar_2 => add_7
#   softplus => exp, gt, log1p, where
#   softplus_1 => exp_1, gt_1, log1p_1, where_1
#   sub_1 => sub_1
#   sub_3 => sub_3
# Graph fragment:
#   %sub_1 : [num_users=4] = call_function[target=torch.ops.aten.sub.Tensor](args = (%primals_18, %slice_6), kwargs = {})
#   %exp : [num_users=1] = call_function[target=torch.ops.aten.exp.default](args = (%sub_1,), kwargs = {})
#   %log1p : [num_users=1] = call_function[target=torch.ops.aten.log1p.default](args = (%exp,), kwargs = {})
#   %gt : [num_users=1] = call_function[target=torch.ops.aten.gt.Scalar](args = (%sub_1, 20), kwargs = {})
#   %where : [num_users=1] = call_function[target=torch.ops.aten.where.self](args = (%gt, %sub_1, %log1p), kwargs = {})
#   %sub_2 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%primals_18, %where), kwargs = {})
#   %sub_3 : [num_users=3] = call_function[target=torch.ops.aten.sub.Tensor](args = (%sub_2, %primals_19), kwargs = {})
#   %exp_1 : [num_users=1] = call_function[target=torch.ops.aten.exp.default](args = (%sub_3,), kwargs = {})
#   %log1p_1 : [num_users=1] = call_function[target=torch.ops.aten.log1p.default](args = (%exp_1,), kwargs = {})
#   %gt_1 : [num_users=1] = call_function[target=torch.ops.aten.gt.Scalar](args = (%sub_3, 20), kwargs = {})
#   %where_1 : [num_users=1] = call_function[target=torch.ops.aten.where.self](args = (%gt_1, %sub_3, %log1p_1), kwargs = {})
#   %add_7 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%primals_19, %where_1), kwargs = {})
triton_poi_fused_add_softplus_sub_3 = async_compile.triton('triton_poi_fused_add_softplus_sub_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=[64], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_softplus_sub_3', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 3, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused_add_softplus_sub_3(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK : tl.constexpr):
    xnumel = 64
    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), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (4 + x0 + (8*x1)), xmask)
    tmp3 = tl.load(in_ptr2 + (x0), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 - tmp1
    tmp4 = 20.0
    tmp5 = tmp2 > tmp4
    tmp6 = tl_math.exp(tmp2)
    tmp7 = libdevice.log1p(tmp6)
    tmp8 = tl.where(tmp5, tmp2, tmp7)
    tmp9 = tmp0 - tmp8
    tmp10 = tmp9 - tmp3
    tmp11 = tmp10 > tmp4
    tmp12 = tl_math.exp(tmp10)
    tmp13 = libdevice.log1p(tmp12)
    tmp14 = tl.where(tmp11, tmp10, tmp13)
    tmp15 = tmp3 + tmp14
    tl.store(out_ptr0 + (x2), tmp2, xmask)
    tl.store(out_ptr1 + (x2), tmp15, 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, primals_18, primals_19 = args
    args.clear()
    assert_size_stride(primals_1, (4, ), (1, ))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    assert_size_stride(primals_3, (4, ), (1, ))
    assert_size_stride(primals_4, (4, 4, 200), (800, 200, 1))
    assert_size_stride(primals_5, (4, 1, 200), (200, 200, 1))
    assert_size_stride(primals_6, (4, 200, 200), (40000, 200, 1))
    assert_size_stride(primals_7, (4, 1, 200), (200, 200, 1))
    assert_size_stride(primals_8, (4, 200, 200), (40000, 200, 1))
    assert_size_stride(primals_9, (4, 1, 200), (200, 200, 1))
    assert_size_stride(primals_10, (4, 200, 200), (40000, 200, 1))
    assert_size_stride(primals_11, (4, 1, 200), (200, 200, 1))
    assert_size_stride(primals_12, (4, 200, 200), (40000, 200, 1))
    assert_size_stride(primals_13, (4, 1, 200), (200, 200, 1))
    assert_size_stride(primals_14, (4, 200, 200), (40000, 200, 1))
    assert_size_stride(primals_15, (4, 1, 200), (200, 200, 1))
    assert_size_stride(primals_16, (4, 200, 8), (1600, 8, 1))
    assert_size_stride(primals_17, (4, 1, 8), (8, 8, 1))
    assert_size_stride(primals_18, (1, 4), (4, 1))
    assert_size_stride(primals_19, (1, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [sub, inputs], Original ATen: [aten.sub, aten.div]
        stream0 = get_raw_stream(0)
        triton_poi_fused_div_sub_0.run(primals_2, primals_1, primals_3, buf0, 16, grid=grid(16), stream=stream0)
        del primals_1
        del primals_2
        del primals_3
        buf1 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        # Topologically Sorted Source Nodes: [matmul], Original ATen: [aten.bmm]
        extern_kernels.bmm(reinterpret_tensor(buf0, (4, 4, 4), (0, 4, 1), 0), primals_4, out=buf1)
        del primals_4
        buf2 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        # Topologically Sorted Source Nodes: [inputs_1, inputs_2], Original ATen: [aten.add, aten.silu]
        triton_poi_fused_add_silu_1.run(buf1, primals_5, buf2, 3200, grid=grid(3200), stream=stream0)
        buf3 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        # Topologically Sorted Source Nodes: [matmul_1], Original ATen: [aten.bmm]
        extern_kernels.bmm(buf2, primals_6, out=buf3)
        buf4 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        # Topologically Sorted Source Nodes: [inputs_3, inputs_4], Original ATen: [aten.add, aten.silu]
        triton_poi_fused_add_silu_1.run(buf3, primals_7, buf4, 3200, grid=grid(3200), stream=stream0)
        buf5 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        # Topologically Sorted Source Nodes: [matmul_2], Original ATen: [aten.bmm]
        extern_kernels.bmm(buf4, primals_8, out=buf5)
        buf6 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        # Topologically Sorted Source Nodes: [inputs_5, inputs_6], Original ATen: [aten.add, aten.silu]
        triton_poi_fused_add_silu_1.run(buf5, primals_9, buf6, 3200, grid=grid(3200), stream=stream0)
        buf7 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        # Topologically Sorted Source Nodes: [matmul_3], Original ATen: [aten.bmm]
        extern_kernels.bmm(buf6, primals_10, out=buf7)
        buf8 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        # Topologically Sorted Source Nodes: [inputs_7, inputs_8], Original ATen: [aten.add, aten.silu]
        triton_poi_fused_add_silu_1.run(buf7, primals_11, buf8, 3200, grid=grid(3200), stream=stream0)
        buf9 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        # Topologically Sorted Source Nodes: [matmul_4], Original ATen: [aten.bmm]
        extern_kernels.bmm(buf8, primals_12, out=buf9)
        buf10 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        # Topologically Sorted Source Nodes: [inputs_9, inputs_10], Original ATen: [aten.add, aten.silu]
        triton_poi_fused_add_silu_1.run(buf9, primals_13, buf10, 3200, grid=grid(3200), stream=stream0)
        buf11 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        # Topologically Sorted Source Nodes: [matmul_5], Original ATen: [aten.bmm]
        extern_kernels.bmm(buf10, primals_14, out=buf11)
        buf12 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        # Topologically Sorted Source Nodes: [inputs_11, inputs_12], Original ATen: [aten.add, aten.silu]
        triton_poi_fused_add_silu_1.run(buf11, primals_15, buf12, 3200, grid=grid(3200), stream=stream0)
        buf13 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
        # Topologically Sorted Source Nodes: [matmul_6], Original ATen: [aten.bmm]
        extern_kernels.bmm(buf12, primals_16, out=buf13)
        buf14 = buf13; del buf13  # reuse
        # Topologically Sorted Source Nodes: [inputs_13], Original ATen: [aten.add]
        triton_poi_fused_add_2.run(buf14, primals_17, 128, grid=grid(128), stream=stream0)
        del primals_17
        buf15 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        buf16 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [sub_1, softplus, logvar_1, sub_3, softplus_1, logvar_2], Original ATen: [aten.sub, aten.softplus, aten.add]
        triton_poi_fused_add_softplus_sub_3.run(primals_18, buf14, primals_19, buf15, buf16, 64, grid=grid(64), stream=stream0)
    return (reinterpret_tensor(buf14, (4, 4, 4), (32, 8, 1), 0), buf16, primals_5, primals_7, primals_9, primals_11, primals_13, primals_15, primals_18, primals_19, buf0, buf1, buf3, buf5, buf7, buf9, buf11, buf15, reinterpret_tensor(buf12, (4, 200, 4), (800, 1, 200), 0), reinterpret_tensor(primals_16, (4, 8, 200), (1600, 1, 8), 0), reinterpret_tensor(buf10, (4, 200, 4), (800, 1, 200), 0), reinterpret_tensor(primals_14, (4, 200, 200), (40000, 1, 200), 0), reinterpret_tensor(buf8, (4, 200, 4), (800, 1, 200), 0), reinterpret_tensor(primals_12, (4, 200, 200), (40000, 1, 200), 0), reinterpret_tensor(buf6, (4, 200, 4), (800, 1, 200), 0), reinterpret_tensor(primals_10, (4, 200, 200), (40000, 1, 200), 0), reinterpret_tensor(buf4, (4, 200, 4), (800, 1, 200), 0), reinterpret_tensor(primals_8, (4, 200, 200), (40000, 1, 200), 0), reinterpret_tensor(buf2, (4, 200, 4), (800, 1, 200), 0), reinterpret_tensor(primals_6, (4, 200, 200), (40000, 1, 200), 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, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((4, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    primals_3 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_4 = rand_strided((4, 4, 200), (800, 200, 1), device='cuda:0', dtype=torch.float32)
    primals_5 = rand_strided((4, 1, 200), (200, 200, 1), device='cuda:0', dtype=torch.float32)
    primals_6 = rand_strided((4, 200, 200), (40000, 200, 1), device='cuda:0', dtype=torch.float32)
    primals_7 = rand_strided((4, 1, 200), (200, 200, 1), device='cuda:0', dtype=torch.float32)
    primals_8 = rand_strided((4, 200, 200), (40000, 200, 1), device='cuda:0', dtype=torch.float32)
    primals_9 = rand_strided((4, 1, 200), (200, 200, 1), device='cuda:0', dtype=torch.float32)
    primals_10 = rand_strided((4, 200, 200), (40000, 200, 1), device='cuda:0', dtype=torch.float32)
    primals_11 = rand_strided((4, 1, 200), (200, 200, 1), device='cuda:0', dtype=torch.float32)
    primals_12 = rand_strided((4, 200, 200), (40000, 200, 1), device='cuda:0', dtype=torch.float32)
    primals_13 = rand_strided((4, 1, 200), (200, 200, 1), device='cuda:0', dtype=torch.float32)
    primals_14 = rand_strided((4, 200, 200), (40000, 200, 1), device='cuda:0', dtype=torch.float32)
    primals_15 = rand_strided((4, 1, 200), (200, 200, 1), device='cuda:0', dtype=torch.float32)
    primals_16 = rand_strided((4, 200, 8), (1600, 8, 1), device='cuda:0', dtype=torch.float32)
    primals_17 = rand_strided((4, 1, 8), (8, 8, 1), device='cuda:0', dtype=torch.float32)
    primals_18 = rand_strided((1, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    primals_19 = 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, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19])
    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 numpy as np
import torch.nn.functional as F


def truncated_standardized_normal(shape, a=-2.0, b=2.0):
    a = torch.Tensor([a])
    b = torch.Tensor([b])
    U = torch.distributions.uniform.Uniform(0, 1)
    u = U.sample(shape)
    Fa = 0.5 * (1 + torch.erf(a / math.sqrt(2)))
    Fb = 0.5 * (1 + torch.erf(b / math.sqrt(2)))
    return math.sqrt(2) * torch.erfinv(2 * ((Fb - Fa) * u + Fa) - 1)


def get_affine_params(ensemble_size, in_features, out_features):
    w = truncated_standardized_normal(shape=(ensemble_size, in_features,
        out_features)) / (2.0 * math.sqrt(in_features))
    w = torch.nn.Parameter(w)
    b = torch.nn.Parameter(torch.zeros(ensemble_size, 1, out_features,
        dtype=torch.float32))
    return w, b


class EnsembleModel(torch.nn.Module):

    def __init__(self, ensemble_size, input_num, output_num, hidden_num=200):
        super().__init__()
        self.num_nets = ensemble_size
        self.input_num = input_num
        self.output_num = output_num
        self.lin0_w, self.lin0_b = get_affine_params(ensemble_size,
            input_num, hidden_num)
        self.lin1_w, self.lin1_b = get_affine_params(ensemble_size,
            hidden_num, hidden_num)
        self.lin2_w, self.lin2_b = get_affine_params(ensemble_size,
            hidden_num, hidden_num)
        self.lin3_w, self.lin3_b = get_affine_params(ensemble_size,
            hidden_num, hidden_num)
        self.lin4_w, self.lin4_b = get_affine_params(ensemble_size,
            hidden_num, hidden_num)
        self.lin5_w, self.lin5_b = get_affine_params(ensemble_size,
            hidden_num, hidden_num)
        self.lin6_w, self.lin6_b = get_affine_params(ensemble_size,
            hidden_num, 2 * output_num)
        self.inputs_mu = torch.nn.Parameter(torch.zeros(input_num),
            requires_grad=False)
        self.inputs_sigma = torch.nn.Parameter(torch.zeros(input_num),
            requires_grad=False)
        self.max_logvar = torch.nn.Parameter(torch.ones(1, output_num,
            dtype=torch.float32) / 2.0)
        self.min_logvar = torch.nn.Parameter(-torch.ones(1, output_num,
            dtype=torch.float32) * 10.0)

    def compute_decays(self):
        loss = 0.0
        loss += 1.0 * (self.lin0_w ** 2).sum()
        loss += 1.0 * (self.lin1_w ** 2).sum()
        loss += 1.0 * (self.lin2_w ** 2).sum()
        loss += 1.0 * (self.lin3_w ** 2).sum()
        loss += 1.0 * (self.lin4_w ** 2).sum()
        loss += 1.0 * (self.lin5_w ** 2).sum()
        loss += 1.0 * (self.lin6_w ** 2).sum()
        return 1e-05 * loss / 2.0

    def fit_input_stats(self, data):
        mu = np.mean(data, axis=0, keepdims=True)
        sigma = np.std(data, axis=0, keepdims=True)
        sigma[sigma < 1e-12] = 1.0
        self.inputs_mu.data = torch.from_numpy(mu).float()
        self.inputs_sigma.data = torch.from_numpy(sigma).float()

    def forward(self, inputs):
        inputs = (inputs - self.inputs_mu) / self.inputs_sigma
        inputs = inputs.matmul(self.lin0_w) + self.lin0_b
        inputs = F.silu(inputs)
        inputs = inputs.matmul(self.lin1_w) + self.lin1_b
        inputs = F.silu(inputs)
        inputs = inputs.matmul(self.lin2_w) + self.lin2_b
        inputs = F.silu(inputs)
        inputs = inputs.matmul(self.lin3_w) + self.lin3_b
        inputs = F.silu(inputs)
        inputs = inputs.matmul(self.lin4_w) + self.lin4_b
        inputs = F.silu(inputs)
        inputs = inputs.matmul(self.lin5_w) + self.lin5_b
        inputs = F.silu(inputs)
        inputs = inputs.matmul(self.lin6_w) + self.lin6_b
        mean = inputs[:, :, :self.output_num]
        logvar = inputs[:, :, self.output_num:]
        logvar = self.max_logvar - F.softplus(self.max_logvar - logvar)
        logvar = self.min_logvar + F.softplus(logvar - self.min_logvar)
        return mean, logvar


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


def get_init_inputs():
    return [[], {'ensemble_size': 4, 'input_num': 4, 'output_num': 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.triton_helpers import libdevice, math as tl_math
import math
import numpy as np
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_div_sub_0(in_ptr0, in_ptr1, in_ptr2, 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
    x0 = xindex % 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 - tmp1
    tmp4 = tmp2 / tmp3
    tl.store(out_ptr0 + x2, tmp4, xmask)


@triton.jit
def triton_poi_fused_add_silu_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 3200
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 200
    x2 = xindex // 800
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr1 + (x0 + 200 * x2), xmask, eviction_policy=
        'evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.sigmoid(tmp2)
    tmp4 = tmp2 * tmp3
    tl.store(out_ptr0 + x3, tmp4, xmask)


@triton.jit
def triton_poi_fused_add_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 128
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x0 = xindex % 8
    x2 = xindex // 32
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + (x0 + 8 * x2), xmask, eviction_policy='evict_last'
        )
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x3, tmp2, xmask)


@triton.jit
def triton_poi_fused_add_softplus_sub_3(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
    out_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    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, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + (4 + x0 + 8 * x1), xmask)
    tmp3 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 - tmp1
    tmp4 = 20.0
    tmp5 = tmp2 > tmp4
    tmp6 = tl_math.exp(tmp2)
    tmp7 = libdevice.log1p(tmp6)
    tmp8 = tl.where(tmp5, tmp2, tmp7)
    tmp9 = tmp0 - tmp8
    tmp10 = tmp9 - tmp3
    tmp11 = tmp10 > tmp4
    tmp12 = tl_math.exp(tmp10)
    tmp13 = libdevice.log1p(tmp12)
    tmp14 = tl.where(tmp11, tmp10, tmp13)
    tmp15 = tmp3 + tmp14
    tl.store(out_ptr0 + x2, tmp2, xmask)
    tl.store(out_ptr1 + x2, tmp15, 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,
        primals_18, primals_19) = args
    args.clear()
    assert_size_stride(primals_1, (4,), (1,))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    assert_size_stride(primals_3, (4,), (1,))
    assert_size_stride(primals_4, (4, 4, 200), (800, 200, 1))
    assert_size_stride(primals_5, (4, 1, 200), (200, 200, 1))
    assert_size_stride(primals_6, (4, 200, 200), (40000, 200, 1))
    assert_size_stride(primals_7, (4, 1, 200), (200, 200, 1))
    assert_size_stride(primals_8, (4, 200, 200), (40000, 200, 1))
    assert_size_stride(primals_9, (4, 1, 200), (200, 200, 1))
    assert_size_stride(primals_10, (4, 200, 200), (40000, 200, 1))
    assert_size_stride(primals_11, (4, 1, 200), (200, 200, 1))
    assert_size_stride(primals_12, (4, 200, 200), (40000, 200, 1))
    assert_size_stride(primals_13, (4, 1, 200), (200, 200, 1))
    assert_size_stride(primals_14, (4, 200, 200), (40000, 200, 1))
    assert_size_stride(primals_15, (4, 1, 200), (200, 200, 1))
    assert_size_stride(primals_16, (4, 200, 8), (1600, 8, 1))
    assert_size_stride(primals_17, (4, 1, 8), (8, 8, 1))
    assert_size_stride(primals_18, (1, 4), (4, 1))
    assert_size_stride(primals_19, (1, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_div_sub_0[grid(16)](primals_2, primals_1,
            primals_3, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1)
        del primals_1
        del primals_2
        del primals_3
        buf1 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf0, (4, 4, 4), (0, 4, 1), 0
            ), primals_4, out=buf1)
        del primals_4
        buf2 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        triton_poi_fused_add_silu_1[grid(3200)](buf1, primals_5, buf2, 3200,
            XBLOCK=128, num_warps=4, num_stages=1)
        buf3 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        extern_kernels.bmm(buf2, primals_6, out=buf3)
        buf4 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        triton_poi_fused_add_silu_1[grid(3200)](buf3, primals_7, buf4, 3200,
            XBLOCK=128, num_warps=4, num_stages=1)
        buf5 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        extern_kernels.bmm(buf4, primals_8, out=buf5)
        buf6 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        triton_poi_fused_add_silu_1[grid(3200)](buf5, primals_9, buf6, 3200,
            XBLOCK=128, num_warps=4, num_stages=1)
        buf7 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        extern_kernels.bmm(buf6, primals_10, out=buf7)
        buf8 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        triton_poi_fused_add_silu_1[grid(3200)](buf7, primals_11, buf8, 
            3200, XBLOCK=128, num_warps=4, num_stages=1)
        buf9 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        extern_kernels.bmm(buf8, primals_12, out=buf9)
        buf10 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        triton_poi_fused_add_silu_1[grid(3200)](buf9, primals_13, buf10, 
            3200, XBLOCK=128, num_warps=4, num_stages=1)
        buf11 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        extern_kernels.bmm(buf10, primals_14, out=buf11)
        buf12 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32)
        triton_poi_fused_add_silu_1[grid(3200)](buf11, primals_15, buf12, 
            3200, XBLOCK=128, num_warps=4, num_stages=1)
        buf13 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
        extern_kernels.bmm(buf12, primals_16, out=buf13)
        buf14 = buf13
        del buf13
        triton_poi_fused_add_2[grid(128)](buf14, primals_17, 128, XBLOCK=
            128, num_warps=4, num_stages=1)
        del primals_17
        buf15 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        buf16 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_add_softplus_sub_3[grid(64)](primals_18, buf14,
            primals_19, buf15, buf16, 64, XBLOCK=64, num_warps=1, num_stages=1)
    return (reinterpret_tensor(buf14, (4, 4, 4), (32, 8, 1), 0), buf16,
        primals_5, primals_7, primals_9, primals_11, primals_13, primals_15,
        primals_18, primals_19, buf0, buf1, buf3, buf5, buf7, buf9, buf11,
        buf15, reinterpret_tensor(buf12, (4, 200, 4), (800, 1, 200), 0),
        reinterpret_tensor(primals_16, (4, 8, 200), (1600, 1, 8), 0),
        reinterpret_tensor(buf10, (4, 200, 4), (800, 1, 200), 0),
        reinterpret_tensor(primals_14, (4, 200, 200), (40000, 1, 200), 0),
        reinterpret_tensor(buf8, (4, 200, 4), (800, 1, 200), 0),
        reinterpret_tensor(primals_12, (4, 200, 200), (40000, 1, 200), 0),
        reinterpret_tensor(buf6, (4, 200, 4), (800, 1, 200), 0),
        reinterpret_tensor(primals_10, (4, 200, 200), (40000, 1, 200), 0),
        reinterpret_tensor(buf4, (4, 200, 4), (800, 1, 200), 0),
        reinterpret_tensor(primals_8, (4, 200, 200), (40000, 1, 200), 0),
        reinterpret_tensor(buf2, (4, 200, 4), (800, 1, 200), 0),
        reinterpret_tensor(primals_6, (4, 200, 200), (40000, 1, 200), 0))


def truncated_standardized_normal(shape, a=-2.0, b=2.0):
    a = torch.Tensor([a])
    b = torch.Tensor([b])
    U = torch.distributions.uniform.Uniform(0, 1)
    u = U.sample(shape)
    Fa = 0.5 * (1 + torch.erf(a / math.sqrt(2)))
    Fb = 0.5 * (1 + torch.erf(b / math.sqrt(2)))
    return math.sqrt(2) * torch.erfinv(2 * ((Fb - Fa) * u + Fa) - 1)


def get_affine_params(ensemble_size, in_features, out_features):
    w = truncated_standardized_normal(shape=(ensemble_size, in_features,
        out_features)) / (2.0 * math.sqrt(in_features))
    w = torch.nn.Parameter(w)
    b = torch.nn.Parameter(torch.zeros(ensemble_size, 1, out_features,
        dtype=torch.float32))
    return w, b


class EnsembleModelNew(torch.nn.Module):

    def __init__(self, ensemble_size, input_num, output_num, hidden_num=200):
        super().__init__()
        self.num_nets = ensemble_size
        self.input_num = input_num
        self.output_num = output_num
        self.lin0_w, self.lin0_b = get_affine_params(ensemble_size,
            input_num, hidden_num)
        self.lin1_w, self.lin1_b = get_affine_params(ensemble_size,
            hidden_num, hidden_num)
        self.lin2_w, self.lin2_b = get_affine_params(ensemble_size,
            hidden_num, hidden_num)
        self.lin3_w, self.lin3_b = get_affine_params(ensemble_size,
            hidden_num, hidden_num)
        self.lin4_w, self.lin4_b = get_affine_params(ensemble_size,
            hidden_num, hidden_num)
        self.lin5_w, self.lin5_b = get_affine_params(ensemble_size,
            hidden_num, hidden_num)
        self.lin6_w, self.lin6_b = get_affine_params(ensemble_size,
            hidden_num, 2 * output_num)
        self.inputs_mu = torch.nn.Parameter(torch.zeros(input_num),
            requires_grad=False)
        self.inputs_sigma = torch.nn.Parameter(torch.zeros(input_num),
            requires_grad=False)
        self.max_logvar = torch.nn.Parameter(torch.ones(1, output_num,
            dtype=torch.float32) / 2.0)
        self.min_logvar = torch.nn.Parameter(-torch.ones(1, output_num,
            dtype=torch.float32) * 10.0)

    def compute_decays(self):
        loss = 0.0
        loss += 1.0 * (self.lin0_w ** 2).sum()
        loss += 1.0 * (self.lin1_w ** 2).sum()
        loss += 1.0 * (self.lin2_w ** 2).sum()
        loss += 1.0 * (self.lin3_w ** 2).sum()
        loss += 1.0 * (self.lin4_w ** 2).sum()
        loss += 1.0 * (self.lin5_w ** 2).sum()
        loss += 1.0 * (self.lin6_w ** 2).sum()
        return 1e-05 * loss / 2.0

    def fit_input_stats(self, data):
        mu = np.mean(data, axis=0, keepdims=True)
        sigma = np.std(data, axis=0, keepdims=True)
        sigma[sigma < 1e-12] = 1.0
        self.inputs_mu.data = torch.from_numpy(mu).float()
        self.inputs_sigma.data = torch.from_numpy(sigma).float()

    def forward(self, input_0):
        primals_4 = self.lin0_w
        primals_5 = self.lin0_b
        primals_6 = self.lin1_w
        primals_7 = self.lin1_b
        primals_8 = self.lin2_w
        primals_9 = self.lin2_b
        primals_10 = self.lin3_w
        primals_11 = self.lin3_b
        primals_12 = self.lin4_w
        primals_13 = self.lin4_b
        primals_14 = self.lin5_w
        primals_15 = self.lin5_b
        primals_16 = self.lin6_w
        primals_17 = self.lin6_b
        primals_1 = self.inputs_mu
        primals_3 = self.inputs_sigma
        primals_18 = self.max_logvar
        primals_19 = self.min_logvar
        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, primals_18, primals_19])
        return output[0], output[1]
