# AOT ID: ['0_inference']
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/u4/cu46rjpw6oa6mworxhmsjuu2sie5fvmufgcgjaooowmjpalwpn2r.py
# Topologically Sorted Source Nodes: [ab, add, stddev, alpha, sub_1, pow_1, neg, sub_2, wrapped_log_1, sub_3, pdf, mul_2, sub_4, mul, wrapped_sqrt_1, truediv_2, erf, add_1, cdf, mul_3, add_2, z_mu, add_4, mul_4, mul_5, pow_2, add_5, mul_6, add_6, pow_3, add_7, sub_5, mul_7, add_8, pow_4, z_var], Original ATen: [aten.sub, aten.add, aten.sqrt, aten.div, aten.pow, aten.neg, aten.log, aten.exp, aten.mul, aten.erf, aten.rsub]
# Source node to ATen node mapping:
#   ab => sub
#   add => add
#   add_1 => add_1
#   add_2 => add_2
#   add_4 => add_4
#   add_5 => add_5
#   add_6 => add_6
#   add_7 => add_7
#   add_8 => add_8
#   alpha => div
#   cdf => mul_1
#   erf => erf
#   mul => mul
#   mul_2 => mul_2
#   mul_3 => mul_3
#   mul_4 => mul_4
#   mul_5 => mul_5
#   mul_6 => mul_6
#   mul_7 => mul_7
#   neg => neg
#   pdf => exp
#   pow_1 => pow_1
#   pow_2 => pow_2
#   pow_3 => pow_3
#   pow_4 => pow_4
#   stddev => sqrt
#   sub_1 => sub_1
#   sub_2 => div_1
#   sub_3 => sub_3
#   sub_4 => sub_4
#   sub_5 => sub_5
#   truediv_2 => div_2
#   wrapped_log_1 => full_default_1
#   wrapped_sqrt_1 => full_default_2
#   z_mu => add_3
#   z_var => sub_6
# Graph fragment:
#   %sub : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%slice_4, %slice_8), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%slice_12, %slice_16), kwargs = {})
#   %sqrt : [num_users=3] = call_function[target=torch.ops.aten.sqrt.default](args = (%add,), kwargs = {})
#   %div : [num_users=2] = call_function[target=torch.ops.aten.div.Tensor](args = (%sub, %sqrt), kwargs = {})
#   %sub_1 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%div, 0.0), kwargs = {})
#   %pow_1 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%sub_1, 2), kwargs = {})
#   %neg : [num_users=1] = call_function[target=torch.ops.aten.neg.default](args = (%pow_1,), kwargs = {})
#   %div_1 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%neg, 2.0), kwargs = {})
#   %full_default_1 : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([], 0.9189385332046727), kwargs = {dtype: torch.float64, layout: torch.strided, device: cpu, pin_memory: False})
#   %sub_3 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%div_1, %full_default_1), kwargs = {})
#   %exp : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub_3,), kwargs = {})
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sqrt, %exp), kwargs = {})
#   %sub_4 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%div, 0.0), kwargs = {})
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_4, 1.0), kwargs = {})
#   %full_default_2 : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([], 1.414213562373095), kwargs = {dtype: torch.float64, layout: torch.strided, device: cpu, pin_memory: False})
#   %div_2 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%mul, %full_default_2), kwargs = {})
#   %erf : [num_users=1] = call_function[target=torch.ops.aten.erf.default](args = (%div_2,), kwargs = {})
#   %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%erf, 1.0), kwargs = {})
#   %mul_1 : [num_users=3] = call_function[target=torch.ops.aten.mul.Tensor](args = (%add_1, 0.5), kwargs = {})
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub, %mul_1), kwargs = {})
#   %add_2 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_2, %mul_3), kwargs = {})
#   %add_3 : [num_users=3] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_2, %slice_8), kwargs = {})
#   %add_4 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%slice_4, %slice_8), kwargs = {})
#   %mul_4 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%add_4, %sqrt), kwargs = {})
#   %mul_5 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul_4, %exp), kwargs = {})
#   %pow_2 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%slice_4, 2), kwargs = {})
#   %add_5 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%pow_2, %slice_12), kwargs = {})
#   %mul_6 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%add_5, %mul_1), kwargs = {})
#   %add_6 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_5, %mul_6), kwargs = {})
#   %pow_3 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%slice_8, 2), kwargs = {})
#   %add_7 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%pow_3, %slice_16), kwargs = {})
#   %sub_5 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %mul_1), kwargs = {})
#   %mul_7 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%add_7, %sub_5), kwargs = {})
#   %add_8 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_6, %mul_7), kwargs = {})
#   %pow_4 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%add_3, 2), kwargs = {})
#   %sub_6 : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_8, %pow_4), kwargs = {})
triton_poi_fused_add_div_erf_exp_log_mul_neg_pow_rsub_sqrt_sub_0 = async_compile.triton('triton_poi_fused_add_div_erf_exp_log_mul_neg_pow_rsub_sqrt_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=[128], 
    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_div_erf_exp_log_mul_neg_pow_rsub_sqrt_sub_0', '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_div_erf_exp_log_mul_neg_pow_rsub_sqrt_sub_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK : tl.constexpr):
    xnumel = 128
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (2*x0), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + (2*x0)), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr1 + (2*x0), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr1 + (1 + (2*x0)), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp5 = tmp3 + tmp4
    tmp6 = libdevice.sqrt(tmp5)
    tmp7 = tmp2 * tmp6
    tmp8 = tmp0 - tmp1
    tmp9 = tmp8 / tmp6
    tmp10 = 0.0
    tmp11 = tmp9 - tmp10
    tmp12 = tmp11 * tmp11
    tmp13 = -tmp12
    tmp14 = 0.5
    tmp15 = tmp13 * tmp14
    tmp16 = 0.9189385332046727
    tmp17 = tmp15 - tmp16
    tmp18 = tl_math.exp(tmp17)
    tmp19 = tmp7 * tmp18
    tmp20 = tmp0 * tmp0
    tmp21 = tmp20 + tmp3
    tmp22 = 1.0
    tmp23 = tmp11 * tmp22
    tmp24 = 1.414213562373095
    tmp25 = tmp23 / tmp24
    tmp26 = libdevice.erf(tmp25)
    tmp27 = tmp26 + tmp22
    tmp28 = tmp27 * tmp14
    tmp29 = tmp21 * tmp28
    tmp30 = tmp19 + tmp29
    tmp31 = tmp6 * tmp18
    tmp32 = tmp8 * tmp28
    tmp33 = tmp31 + tmp32
    tmp34 = tmp33 + tmp1
    tmp35 = tmp34 * tmp34
    tmp36 = tmp1 * tmp1
    tmp37 = tmp36 + tmp4
    tmp38 = tmp22 - tmp28
    tmp39 = tmp37 * tmp38
    tmp40 = tmp30 + tmp39
    tmp41 = tmp40 - tmp35
    tl.store(in_out_ptr0 + (x0), tmp41, xmask)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/vi/cviiumjub3u57kibptax7jl6tgmdovps6rx7eaeb6mrngefnmjyp.py
# Topologically Sorted Source Nodes: [add_13, add_9, stddev_1, mul_12, ab_1, alpha_1, sub_8, pow_5, neg_1, sub_9, wrapped_log_3, sub_10, pdf_1, mul_13, pow_6, add_14, sub_11, mul_8, wrapped_sqrt_3, truediv_5, erf_1, add_10, cdf_1, mul_14, add_15, pow_7, add_16, sub_12, mul_15, add_17, mul_10, mul_11, add_11, z_mu_1, pow_8, z_var_1], Original ATen: [aten.add, aten.sqrt, aten.mul, aten.sub, aten.div, aten.pow, aten.neg, aten.log, aten.exp, aten.erf, aten.rsub]
# Source node to ATen node mapping:
#   ab_1 => sub_7
#   add_10 => add_10
#   add_11 => add_11
#   add_13 => add_13
#   add_14 => add_14
#   add_15 => add_15
#   add_16 => add_16
#   add_17 => add_17
#   add_9 => add_9
#   alpha_1 => div_3
#   cdf_1 => mul_9
#   erf_1 => erf_1
#   mul_10 => mul_10
#   mul_11 => mul_11
#   mul_12 => mul_12
#   mul_13 => mul_13
#   mul_14 => mul_14
#   mul_15 => mul_15
#   mul_8 => mul_8
#   neg_1 => neg_1
#   pdf_1 => exp_1
#   pow_5 => pow_5
#   pow_6 => pow_6
#   pow_7 => pow_7
#   pow_8 => pow_8
#   stddev_1 => sqrt_3
#   sub_10 => sub_10
#   sub_11 => sub_11
#   sub_12 => sub_12
#   sub_8 => sub_8
#   sub_9 => div_4
#   truediv_5 => div_5
#   wrapped_log_3 => full_default_4
#   wrapped_sqrt_3 => full_default_5
#   z_mu_1 => add_12
#   z_var_1 => sub_13
# Graph fragment:
#   %add_13 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%slice_19, %slice_23), kwargs = {})
#   %add_9 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%slice_27, %slice_31), kwargs = {})
#   %sqrt_3 : [num_users=3] = call_function[target=torch.ops.aten.sqrt.default](args = (%add_9,), kwargs = {})
#   %mul_12 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%add_13, %sqrt_3), kwargs = {})
#   %sub_7 : [num_users=2] = call_function[target=torch.ops.aten.sub.Tensor](args = (%slice_19, %slice_23), kwargs = {})
#   %div_3 : [num_users=2] = call_function[target=torch.ops.aten.div.Tensor](args = (%sub_7, %sqrt_3), kwargs = {})
#   %sub_8 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%div_3, 0.0), kwargs = {})
#   %pow_5 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%sub_8, 2), kwargs = {})
#   %neg_1 : [num_users=1] = call_function[target=torch.ops.aten.neg.default](args = (%pow_5,), kwargs = {})
#   %div_4 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%neg_1, 2.0), kwargs = {})
#   %full_default_4 : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([], 0.9189385332046727), kwargs = {dtype: torch.float64, layout: torch.strided, device: cpu, pin_memory: False})
#   %sub_10 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%div_4, %full_default_4), kwargs = {})
#   %exp_1 : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub_10,), kwargs = {})
#   %mul_13 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul_12, %exp_1), kwargs = {})
#   %pow_6 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%slice_19, 2), kwargs = {})
#   %add_14 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%pow_6, %slice_27), kwargs = {})
#   %sub_11 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%div_3, 0.0), kwargs = {})
#   %mul_8 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_11, 1.0), kwargs = {})
#   %full_default_5 : [num_users=1] = call_function[target=torch.ops.aten.full.default](args = ([], 1.414213562373095), kwargs = {dtype: torch.float64, layout: torch.strided, device: cpu, pin_memory: False})
#   %div_5 : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%mul_8, %full_default_5), kwargs = {})
#   %erf_1 : [num_users=1] = call_function[target=torch.ops.aten.erf.default](args = (%div_5,), kwargs = {})
#   %add_10 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%erf_1, 1.0), kwargs = {})
#   %mul_9 : [num_users=3] = call_function[target=torch.ops.aten.mul.Tensor](args = (%add_10, 0.5), kwargs = {})
#   %mul_14 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%add_14, %mul_9), kwargs = {})
#   %add_15 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_13, %mul_14), kwargs = {})
#   %pow_7 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%slice_23, 2), kwargs = {})
#   %add_16 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%pow_7, %slice_31), kwargs = {})
#   %sub_12 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (1.0, %mul_9), kwargs = {})
#   %mul_15 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%add_16, %sub_12), kwargs = {})
#   %add_17 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_15, %mul_15), kwargs = {})
#   %mul_10 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sqrt_3, %exp_1), kwargs = {})
#   %mul_11 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub_7, %mul_9), kwargs = {})
#   %add_11 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul_10, %mul_11), kwargs = {})
#   %add_12 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%add_11, %slice_23), kwargs = {})
#   %pow_8 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%add_12, 2), kwargs = {})
#   %sub_13 : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add_17, %pow_8), kwargs = {})
triton_poi_fused_add_div_erf_exp_log_mul_neg_pow_rsub_sqrt_sub_1 = async_compile.triton('triton_poi_fused_add_div_erf_exp_log_mul_neg_pow_rsub_sqrt_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.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_div_erf_exp_log_mul_neg_pow_rsub_sqrt_sub_1', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 10, '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_div_erf_exp_log_mul_neg_pow_rsub_sqrt_sub_1(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr2, xnumel, XBLOCK : tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 2
    x1 = (xindex // 2)
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (4 + (2*x0) + (8*x1)), xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (5 + (2*x0) + (8*x1)), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr1 + (4 + (2*x0) + (8*x1)), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr1 + (5 + (2*x0) + (8*x1)), xmask, eviction_policy='evict_last')
    tmp29 = tl.load(in_ptr0 + ((2*x0) + (8*x1)), xmask, eviction_policy='evict_last')
    tmp30 = tl.load(in_ptr0 + (1 + (2*x0) + (8*x1)), xmask, eviction_policy='evict_last')
    tmp33 = tl.load(in_ptr1 + ((2*x0) + (8*x1)), xmask, eviction_policy='evict_last')
    tmp34 = tl.load(in_ptr1 + (1 + (2*x0) + (8*x1)), xmask, eviction_policy='evict_last')
    tmp54 = tl.load(in_ptr2 + (x0 + (4*x1)), xmask)
    tmp55 = tl.load(in_ptr2 + (2 + x0 + (4*x1)), xmask)
    tmp2 = tmp0 + tmp1
    tmp3 = libdevice.sqrt(tmp2)
    tmp6 = tmp4 - tmp5
    tmp7 = tmp6 / tmp3
    tmp8 = 0.0
    tmp9 = tmp7 - tmp8
    tmp10 = tmp9 * tmp9
    tmp11 = -tmp10
    tmp12 = 0.5
    tmp13 = tmp11 * tmp12
    tmp14 = 0.9189385332046727
    tmp15 = tmp13 - tmp14
    tmp16 = tl_math.exp(tmp15)
    tmp17 = tmp3 * tmp16
    tmp18 = 1.0
    tmp19 = tmp9 * tmp18
    tmp20 = 1.414213562373095
    tmp21 = tmp19 / tmp20
    tmp22 = libdevice.erf(tmp21)
    tmp23 = tmp22 + tmp18
    tmp24 = tmp23 * tmp12
    tmp25 = tmp6 * tmp24
    tmp26 = tmp17 + tmp25
    tmp27 = tmp26 + tmp5
    tmp28 = tmp27 * tmp27
    tmp31 = tmp29 + tmp30
    tmp32 = libdevice.sqrt(tmp31)
    tmp35 = tmp33 - tmp34
    tmp36 = tmp35 / tmp32
    tmp37 = tmp36 - tmp8
    tmp38 = tmp37 * tmp37
    tmp39 = -tmp38
    tmp40 = tmp39 * tmp12
    tmp41 = tmp40 - tmp14
    tmp42 = tl_math.exp(tmp41)
    tmp43 = tmp32 * tmp42
    tmp44 = tmp37 * tmp18
    tmp45 = tmp44 / tmp20
    tmp46 = libdevice.erf(tmp45)
    tmp47 = tmp46 + tmp18
    tmp48 = tmp47 * tmp12
    tmp49 = tmp35 * tmp48
    tmp50 = tmp43 + tmp49
    tmp51 = tmp50 + tmp34
    tmp52 = tmp51 + tmp27
    tmp53 = tmp51 - tmp27
    tmp56 = tmp54 + tmp55
    tmp57 = libdevice.sqrt(tmp56)
    tmp58 = tmp53 / tmp57
    tmp59 = tmp58 - tmp8
    tmp60 = tmp59 * tmp59
    tmp61 = -tmp60
    tmp62 = tmp61 * tmp12
    tmp63 = tmp62 - tmp14
    tmp64 = tl_math.exp(tmp63)
    tmp65 = tmp57 * tmp64
    tmp66 = tmp59 * tmp18
    tmp67 = tmp66 / tmp20
    tmp68 = libdevice.erf(tmp67)
    tmp69 = tmp68 + tmp18
    tmp70 = tmp69 * tmp12
    tmp71 = tmp53 * tmp70
    tmp72 = tmp65 + tmp71
    tmp73 = tmp72 + tmp27
    tmp74 = tmp51 * tmp51
    tmp75 = tmp52 * tmp57
    tmp76 = tmp75 * tmp64
    tmp77 = tmp74 + tmp54
    tmp78 = tmp77 * tmp70
    tmp79 = tmp76 + tmp78
    tmp80 = tmp28 + tmp55
    tmp81 = tmp18 - tmp70
    tmp82 = tmp80 * tmp81
    tmp83 = tmp79 + tmp82
    tmp84 = tmp73 * tmp73
    tmp85 = tmp83 - tmp84
    tl.store(out_ptr2 + (x2), tmp73, xmask)
    tl.store(in_out_ptr0 + (x2), tmp85, xmask)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf1 = empty_strided_cuda((4, 4, 4, 2), (32, 8, 2, 1), torch.float32)
        buf3 = buf1; del buf1  # reuse
        # Topologically Sorted Source Nodes: [ab, add, stddev, alpha, sub_1, pow_1, neg, sub_2, wrapped_log_1, sub_3, pdf, mul_2, sub_4, mul, wrapped_sqrt_1, truediv_2, erf, add_1, cdf, mul_3, add_2, z_mu, add_4, mul_4, mul_5, pow_2, add_5, mul_6, add_6, pow_3, add_7, sub_5, mul_7, add_8, pow_4, z_var], Original ATen: [aten.sub, aten.add, aten.sqrt, aten.div, aten.pow, aten.neg, aten.log, aten.exp, aten.mul, aten.erf, aten.rsub]
        stream0 = get_raw_stream(0)
        triton_poi_fused_add_div_erf_exp_log_mul_neg_pow_rsub_sqrt_sub_0.run(buf3, arg0_1, arg1_1, 128, grid=grid(128), stream=stream0)
        buf0 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32)
        buf8 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32)
        buf6 = buf0; del buf0  # reuse
        buf9 = buf6; del buf6  # reuse
        # Topologically Sorted Source Nodes: [add_13, add_9, stddev_1, mul_12, ab_1, alpha_1, sub_8, pow_5, neg_1, sub_9, wrapped_log_3, sub_10, pdf_1, mul_13, pow_6, add_14, sub_11, mul_8, wrapped_sqrt_3, truediv_5, erf_1, add_10, cdf_1, mul_14, add_15, pow_7, add_16, sub_12, mul_15, add_17, mul_10, mul_11, add_11, z_mu_1, pow_8, z_var_1], Original ATen: [aten.add, aten.sqrt, aten.mul, aten.sub, aten.div, aten.pow, aten.neg, aten.log, aten.exp, aten.erf, aten.rsub]
        triton_poi_fused_add_div_erf_exp_log_mul_neg_pow_rsub_sqrt_sub_1.run(buf9, arg1_1, arg0_1, buf3, buf8, 64, grid=grid(64), stream=stream0)
        del arg0_1
        del arg1_1
        del buf3
    return (buf8, buf9, )


def benchmark_compiled_module(times=10, repeat=10):
    from torch._dynamo.testing import rand_strided
    from torch._inductor.utils import print_performance
    arg0_1 = rand_strided((4, 4, 4, 4), (64, 16, 4, 1), device='cuda:0', dtype=torch.float32)
    arg1_1 = rand_strided((4, 4, 4, 4), (64, 16, 4, 1), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([arg0_1, arg1_1])
    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 numpy as np
import torch.nn as nn
from numbers import Number


def normcdf(value, mu=0.0, stddev=1.0):
    sinv = 1.0 / stddev if isinstance(stddev, Number) else stddev.reciprocal()
    return 0.5 * (1.0 + torch.erf((value - mu) * sinv / np.sqrt(2.0)))


def _normal_log_pdf(value, mu, stddev):
    var = stddev ** 2
    log_scale = np.log(stddev) if isinstance(stddev, Number) else torch.log(
        stddev)
    return -(value - mu) ** 2 / (2.0 * var) - log_scale - np.log(np.sqrt(
        2.0 * np.pi))


def normpdf(value, mu=0.0, stddev=1.0):
    return torch.exp(_normal_log_pdf(value, mu, stddev))


def keep_variance_fn(x):
    return x + 0.001


class MaxPool2d(nn.Module):

    def __init__(self, keep_variance_fn=None):
        super(MaxPool2d, self).__init__()
        self._keep_variance_fn = keep_variance_fn

    def _max_pool_internal(self, mu_a, mu_b, var_a, var_b):
        stddev = torch.sqrt(var_a + var_b)
        ab = mu_a - mu_b
        alpha = ab / stddev
        pdf = normpdf(alpha)
        cdf = normcdf(alpha)
        z_mu = stddev * pdf + ab * cdf + mu_b
        z_var = (mu_a + mu_b) * stddev * pdf + (mu_a ** 2 + var_a) * cdf + (
            mu_b ** 2 + var_b) * (1.0 - cdf) - z_mu ** 2
        if self._keep_variance_fn is not None:
            z_var = self._keep_variance_fn(z_var)
        return z_mu, z_var

    def _max_pool_1x2(self, inputs_mean, inputs_variance):
        mu_a = inputs_mean[:, :, :, 0::2]
        mu_b = inputs_mean[:, :, :, 1::2]
        var_a = inputs_variance[:, :, :, 0::2]
        var_b = inputs_variance[:, :, :, 1::2]
        outputs_mean, outputs_variance = self._max_pool_internal(mu_a, mu_b,
            var_a, var_b)
        return outputs_mean, outputs_variance

    def _max_pool_2x1(self, inputs_mean, inputs_variance):
        mu_a = inputs_mean[:, :, 0::2, :]
        mu_b = inputs_mean[:, :, 1::2, :]
        var_a = inputs_variance[:, :, 0::2, :]
        var_b = inputs_variance[:, :, 1::2, :]
        outputs_mean, outputs_variance = self._max_pool_internal(mu_a, mu_b,
            var_a, var_b)
        return outputs_mean, outputs_variance

    def forward(self, inputs_mean, inputs_variance):
        z_mean, z_variance = self._max_pool_1x2(inputs_mean, inputs_variance)
        outputs_mean, outputs_variance = self._max_pool_2x1(z_mean, z_variance)
        return outputs_mean, outputs_variance


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


def get_init_inputs():
    return [[], {}]

import torch
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 numpy as np
import torch.nn as nn
from numbers import Number
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda


@triton.jit
def triton_poi_fused_add_div_erf_exp_log_mul_neg_pow_rsub_sqrt_sub_0(
    in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 128
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 2 * x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (1 + 2 * x0), xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr1 + 2 * x0, xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr1 + (1 + 2 * x0), xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp5 = tmp3 + tmp4
    tmp6 = libdevice.sqrt(tmp5)
    tmp7 = tmp2 * tmp6
    tmp8 = tmp0 - tmp1
    tmp9 = tmp8 / tmp6
    tmp10 = 0.0
    tmp11 = tmp9 - tmp10
    tmp12 = tmp11 * tmp11
    tmp13 = -tmp12
    tmp14 = 0.5
    tmp15 = tmp13 * tmp14
    tmp16 = 0.9189385332046727
    tmp17 = tmp15 - tmp16
    tmp18 = tl_math.exp(tmp17)
    tmp19 = tmp7 * tmp18
    tmp20 = tmp0 * tmp0
    tmp21 = tmp20 + tmp3
    tmp22 = 1.0
    tmp23 = tmp11 * tmp22
    tmp24 = 1.414213562373095
    tmp25 = tmp23 / tmp24
    tmp26 = libdevice.erf(tmp25)
    tmp27 = tmp26 + tmp22
    tmp28 = tmp27 * tmp14
    tmp29 = tmp21 * tmp28
    tmp30 = tmp19 + tmp29
    tmp31 = tmp6 * tmp18
    tmp32 = tmp8 * tmp28
    tmp33 = tmp31 + tmp32
    tmp34 = tmp33 + tmp1
    tmp35 = tmp34 * tmp34
    tmp36 = tmp1 * tmp1
    tmp37 = tmp36 + tmp4
    tmp38 = tmp22 - tmp28
    tmp39 = tmp37 * tmp38
    tmp40 = tmp30 + tmp39
    tmp41 = tmp40 - tmp35
    tl.store(in_out_ptr0 + x0, tmp41, xmask)


@triton.jit
def triton_poi_fused_add_div_erf_exp_log_mul_neg_pow_rsub_sqrt_sub_1(
    in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr2, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 2
    x1 = xindex // 2
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (4 + 2 * x0 + 8 * x1), xmask, eviction_policy=
        'evict_last')
    tmp1 = tl.load(in_ptr0 + (5 + 2 * x0 + 8 * x1), xmask, eviction_policy=
        'evict_last')
    tmp4 = tl.load(in_ptr1 + (4 + 2 * x0 + 8 * x1), xmask, eviction_policy=
        'evict_last')
    tmp5 = tl.load(in_ptr1 + (5 + 2 * x0 + 8 * x1), xmask, eviction_policy=
        'evict_last')
    tmp29 = tl.load(in_ptr0 + (2 * x0 + 8 * x1), xmask, eviction_policy=
        'evict_last')
    tmp30 = tl.load(in_ptr0 + (1 + 2 * x0 + 8 * x1), xmask, eviction_policy
        ='evict_last')
    tmp33 = tl.load(in_ptr1 + (2 * x0 + 8 * x1), xmask, eviction_policy=
        'evict_last')
    tmp34 = tl.load(in_ptr1 + (1 + 2 * x0 + 8 * x1), xmask, eviction_policy
        ='evict_last')
    tmp54 = tl.load(in_ptr2 + (x0 + 4 * x1), xmask)
    tmp55 = tl.load(in_ptr2 + (2 + x0 + 4 * x1), xmask)
    tmp2 = tmp0 + tmp1
    tmp3 = libdevice.sqrt(tmp2)
    tmp6 = tmp4 - tmp5
    tmp7 = tmp6 / tmp3
    tmp8 = 0.0
    tmp9 = tmp7 - tmp8
    tmp10 = tmp9 * tmp9
    tmp11 = -tmp10
    tmp12 = 0.5
    tmp13 = tmp11 * tmp12
    tmp14 = 0.9189385332046727
    tmp15 = tmp13 - tmp14
    tmp16 = tl_math.exp(tmp15)
    tmp17 = tmp3 * tmp16
    tmp18 = 1.0
    tmp19 = tmp9 * tmp18
    tmp20 = 1.414213562373095
    tmp21 = tmp19 / tmp20
    tmp22 = libdevice.erf(tmp21)
    tmp23 = tmp22 + tmp18
    tmp24 = tmp23 * tmp12
    tmp25 = tmp6 * tmp24
    tmp26 = tmp17 + tmp25
    tmp27 = tmp26 + tmp5
    tmp28 = tmp27 * tmp27
    tmp31 = tmp29 + tmp30
    tmp32 = libdevice.sqrt(tmp31)
    tmp35 = tmp33 - tmp34
    tmp36 = tmp35 / tmp32
    tmp37 = tmp36 - tmp8
    tmp38 = tmp37 * tmp37
    tmp39 = -tmp38
    tmp40 = tmp39 * tmp12
    tmp41 = tmp40 - tmp14
    tmp42 = tl_math.exp(tmp41)
    tmp43 = tmp32 * tmp42
    tmp44 = tmp37 * tmp18
    tmp45 = tmp44 / tmp20
    tmp46 = libdevice.erf(tmp45)
    tmp47 = tmp46 + tmp18
    tmp48 = tmp47 * tmp12
    tmp49 = tmp35 * tmp48
    tmp50 = tmp43 + tmp49
    tmp51 = tmp50 + tmp34
    tmp52 = tmp51 + tmp27
    tmp53 = tmp51 - tmp27
    tmp56 = tmp54 + tmp55
    tmp57 = libdevice.sqrt(tmp56)
    tmp58 = tmp53 / tmp57
    tmp59 = tmp58 - tmp8
    tmp60 = tmp59 * tmp59
    tmp61 = -tmp60
    tmp62 = tmp61 * tmp12
    tmp63 = tmp62 - tmp14
    tmp64 = tl_math.exp(tmp63)
    tmp65 = tmp57 * tmp64
    tmp66 = tmp59 * tmp18
    tmp67 = tmp66 / tmp20
    tmp68 = libdevice.erf(tmp67)
    tmp69 = tmp68 + tmp18
    tmp70 = tmp69 * tmp12
    tmp71 = tmp53 * tmp70
    tmp72 = tmp65 + tmp71
    tmp73 = tmp72 + tmp27
    tmp74 = tmp51 * tmp51
    tmp75 = tmp52 * tmp57
    tmp76 = tmp75 * tmp64
    tmp77 = tmp74 + tmp54
    tmp78 = tmp77 * tmp70
    tmp79 = tmp76 + tmp78
    tmp80 = tmp28 + tmp55
    tmp81 = tmp18 - tmp70
    tmp82 = tmp80 * tmp81
    tmp83 = tmp79 + tmp82
    tmp84 = tmp73 * tmp73
    tmp85 = tmp83 - tmp84
    tl.store(out_ptr2 + x2, tmp73, xmask)
    tl.store(in_out_ptr0 + x2, tmp85, xmask)


def call(args):
    arg0_1, arg1_1 = args
    args.clear()
    assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf1 = empty_strided_cuda((4, 4, 4, 2), (32, 8, 2, 1), torch.float32)
        buf3 = buf1
        del buf1
        get_raw_stream(0)
        triton_poi_fused_add_div_erf_exp_log_mul_neg_pow_rsub_sqrt_sub_0[grid
            (128)](buf3, arg0_1, arg1_1, 128, XBLOCK=128, num_warps=4,
            num_stages=1)
        buf0 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32)
        buf8 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32)
        buf6 = buf0
        del buf0
        buf9 = buf6
        del buf6
        triton_poi_fused_add_div_erf_exp_log_mul_neg_pow_rsub_sqrt_sub_1[grid
            (64)](buf9, arg1_1, arg0_1, buf3, buf8, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        del arg0_1
        del arg1_1
        del buf3
    return buf8, buf9


def normcdf(value, mu=0.0, stddev=1.0):
    sinv = 1.0 / stddev if isinstance(stddev, Number) else stddev.reciprocal()
    return 0.5 * (1.0 + torch.erf((value - mu) * sinv / np.sqrt(2.0)))


def _normal_log_pdf(value, mu, stddev):
    var = stddev ** 2
    log_scale = np.log(stddev) if isinstance(stddev, Number) else torch.log(
        stddev)
    return -(value - mu) ** 2 / (2.0 * var) - log_scale - np.log(np.sqrt(
        2.0 * np.pi))


def normpdf(value, mu=0.0, stddev=1.0):
    return torch.exp(_normal_log_pdf(value, mu, stddev))


def keep_variance_fn(x):
    return x + 0.001


class MaxPool2dNew(nn.Module):

    def __init__(self, keep_variance_fn=None):
        super(MaxPool2dNew, self).__init__()
        self._keep_variance_fn = keep_variance_fn

    def _max_pool_internal(self, mu_a, mu_b, var_a, var_b):
        stddev = torch.sqrt(var_a + var_b)
        ab = mu_a - mu_b
        alpha = ab / stddev
        pdf = normpdf(alpha)
        cdf = normcdf(alpha)
        z_mu = stddev * pdf + ab * cdf + mu_b
        z_var = (mu_a + mu_b) * stddev * pdf + (mu_a ** 2 + var_a) * cdf + (
            mu_b ** 2 + var_b) * (1.0 - cdf) - z_mu ** 2
        if self._keep_variance_fn is not None:
            z_var = self._keep_variance_fn(z_var)
        return z_mu, z_var

    def _max_pool_1x2(self, inputs_mean, inputs_variance):
        mu_a = inputs_mean[:, :, :, 0::2]
        mu_b = inputs_mean[:, :, :, 1::2]
        var_a = inputs_variance[:, :, :, 0::2]
        var_b = inputs_variance[:, :, :, 1::2]
        outputs_mean, outputs_variance = self._max_pool_internal(mu_a, mu_b,
            var_a, var_b)
        return outputs_mean, outputs_variance

    def _max_pool_2x1(self, inputs_mean, inputs_variance):
        mu_a = inputs_mean[:, :, 0::2, :]
        mu_b = inputs_mean[:, :, 1::2, :]
        var_a = inputs_variance[:, :, 0::2, :]
        var_b = inputs_variance[:, :, 1::2, :]
        outputs_mean, outputs_variance = self._max_pool_internal(mu_a, mu_b,
            var_a, var_b)
        return outputs_mean, outputs_variance

    def forward(self, input_0, input_1):
        arg0_1 = input_0
        arg1_1 = input_1
        output = call([arg0_1, arg1_1])
        return output[0], output[1]
