# 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/il/cil5hpoi7ygpsypgim2u7imeqozhugxjb3qehifbgnc6wf4rjrsp.py
# Topologically Sorted Source Nodes: [uw, softplus, muw, sub, mul, pow_1, sum_1, truediv, uhat, mv, zwb, psi, psi_u, add_4, abs_1, add_5, logdet_jacobian], Original ATen: [aten.dot, aten.softplus, aten.add, aten.sub, aten.mul, aten.pow, aten.sum, aten.div, aten.mv, aten.abs, aten.log]
# Source node to ATen node mapping:
#   abs_1 => abs_1
#   add_4 => add_4
#   add_5 => add_5
#   logdet_jacobian => log
#   mul => mul_1
#   muw => add
#   mv => mul_2, sum_3
#   pow_1 => pow_1
#   psi => mul_4
#   psi_u => mul_5, sum_4
#   softplus => exp, gt, log1p, where
#   sub => sub
#   sum_1 => sum_2
#   truediv => div
#   uhat => add_1
#   uw => mul, sum_1
#   zwb => add_2
# Graph fragment:
#   %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%primals_1, %primals_2), kwargs = {})
#   %sum_1 : [num_users=4] = call_function[target=torch.ops.aten.sum.default](args = (%mul,), kwargs = {})
#   %exp : [num_users=1] = call_function[target=torch.ops.aten.exp.default](args = (%sum_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 = (%sum_1, 20), kwargs = {})
#   %where : [num_users=1] = call_function[target=torch.ops.aten.where.self](args = (%gt, %sum_1, %log1p), kwargs = {})
#   %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%where, -1), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%add, %sum_1), kwargs = {})
#   %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%sub, %primals_2), kwargs = {})
#   %pow_1 : [num_users=1] = call_function[target=torch.ops.aten.pow.Tensor_Scalar](args = (%primals_2, 2), kwargs = {})
#   %sum_2 : [num_users=1] = call_function[target=torch.ops.aten.sum.default](args = (%pow_1,), kwargs = {})
#   %div : [num_users=1] = call_function[target=torch.ops.aten.div.Tensor](args = (%mul_1, %sum_2), kwargs = {})
#   %add_1 : [num_users=2] = call_function[target=torch.ops.aten.add.Tensor](args = (%primals_1, %div), kwargs = {})
#   %mul_2 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%primals_3, %primals_2), kwargs = {})
#   %sum_3 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_2, [1]), kwargs = {})
#   %add_2 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_3, %primals_4), kwargs = {})
#   %mul_4 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%view_2, %view_3), kwargs = {})
#   %mul_5 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%mul_4, %add_1), kwargs = {})
#   %sum_4 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%mul_5, [1]), kwargs = {})
#   %add_4 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%sum_4, 1), kwargs = {})
#   %abs_1 : [num_users=1] = call_function[target=torch.ops.aten.abs.default](args = (%add_4,), kwargs = {})
#   %add_5 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%abs_1, 1e-08), kwargs = {})
#   %log : [num_users=1] = call_function[target=torch.ops.aten.log.default](args = (%add_5,), kwargs = {})
triton_per_fused_abs_add_div_dot_log_mul_mv_pow_softplus_sub_sum_0 = async_compile.triton('triton_per_fused_abs_add_div_dot_log_mul_mv_pow_softplus_sub_sum_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=[1, 4],
    reduction_hint=ReductionHint.DEFAULT,
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: '*fp32', 6: '*fp32', 7: '*fp32', 8: 'i32', 9: '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': {8: 1}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5, 6, 7), equal_to_1=(8,))]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_per_fused_abs_add_div_dot_log_mul_mv_pow_softplus_sub_sum_0', 'mutated_arg_names': ['in_out_ptr0'], 'no_x_dim': False, 'num_load': 15, 'num_reduction': 2, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False}
)
@triton.jit
def triton_per_fused_abs_add_div_dot_log_mul_mv_pow_softplus_sub_sum_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK : tl.constexpr):
    xnumel = 1
    rnumel = 4
    RBLOCK: tl.constexpr = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    roffset = 0
    rmask = tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + (r0), None)
    tmp1 = tl.load(in_ptr1 + (r0), None)
    tmp10 = tl.load(in_ptr2 + (4*r0), None, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr1 + (0))
    tmp12 = tl.broadcast_to(tmp11, [XBLOCK, RBLOCK])
    tmp14 = tl.load(in_ptr2 + (1 + (4*r0)), None, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr1 + (1))
    tmp16 = tl.broadcast_to(tmp15, [XBLOCK, RBLOCK])
    tmp19 = tl.load(in_ptr2 + (2 + (4*r0)), None, eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr1 + (2))
    tmp21 = tl.broadcast_to(tmp20, [XBLOCK, RBLOCK])
    tmp24 = tl.load(in_ptr2 + (3 + (4*r0)), None, eviction_policy='evict_last')
    tmp25 = tl.load(in_ptr1 + (3))
    tmp26 = tl.broadcast_to(tmp25, [XBLOCK, RBLOCK])
    tmp29 = tl.load(in_ptr3 + (0))
    tmp30 = tl.broadcast_to(tmp29, [XBLOCK, RBLOCK])
    tmp37 = tl.load(in_ptr0 + (0))
    tmp38 = tl.broadcast_to(tmp37, [XBLOCK, RBLOCK])
    tmp52 = tl.load(in_ptr0 + (1))
    tmp53 = tl.broadcast_to(tmp52, [XBLOCK, RBLOCK])
    tmp60 = tl.load(in_ptr0 + (2))
    tmp61 = tl.broadcast_to(tmp60, [XBLOCK, RBLOCK])
    tmp68 = tl.load(in_ptr0 + (3))
    tmp69 = tl.broadcast_to(tmp68, [XBLOCK, RBLOCK])
    tmp2 = tmp0 * tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.sum(tmp3, 1)[:, None]
    tmp6 = tmp1 * tmp1
    tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
    tmp9 = tl.sum(tmp7, 1)[:, None]
    tmp13 = tmp10 * tmp12
    tmp17 = tmp14 * tmp16
    tmp18 = tmp13 + tmp17
    tmp22 = tmp19 * tmp21
    tmp23 = tmp18 + tmp22
    tmp27 = tmp24 * tmp26
    tmp28 = tmp23 + tmp27
    tmp31 = tmp28 + tmp30
    tmp32 = libdevice.tanh(tmp31)
    tmp33 = tmp32 * tmp32
    tmp34 = 1.0
    tmp35 = tmp34 - tmp33
    tmp36 = tmp35 * tmp12
    tmp39 = 20.0
    tmp40 = tmp5 > tmp39
    tmp41 = tl_math.exp(tmp5)
    tmp42 = libdevice.log1p(tmp41)
    tmp43 = tl.where(tmp40, tmp5, tmp42)
    tmp44 = -1.0
    tmp45 = tmp43 + tmp44
    tmp46 = tmp45 - tmp5
    tmp47 = tmp46 * tmp12
    tmp48 = tmp47 / tmp9
    tmp49 = tmp38 + tmp48
    tmp50 = tmp36 * tmp49
    tmp51 = tmp35 * tmp16
    tmp54 = tmp46 * tmp16
    tmp55 = tmp54 / tmp9
    tmp56 = tmp53 + tmp55
    tmp57 = tmp51 * tmp56
    tmp58 = tmp50 + tmp57
    tmp59 = tmp35 * tmp21
    tmp62 = tmp46 * tmp21
    tmp63 = tmp62 / tmp9
    tmp64 = tmp61 + tmp63
    tmp65 = tmp59 * tmp64
    tmp66 = tmp58 + tmp65
    tmp67 = tmp35 * tmp26
    tmp70 = tmp46 * tmp26
    tmp71 = tmp70 / tmp9
    tmp72 = tmp69 + tmp71
    tmp73 = tmp67 * tmp72
    tmp74 = tmp66 + tmp73
    tmp75 = tmp74 + tmp34
    tmp76 = tl_math.abs(tmp75)
    tmp77 = 1e-08
    tmp78 = tmp76 + tmp77
    tmp79 = tl_math.log(tmp78)
    tl.store(out_ptr2 + (tl.broadcast_to(r0, [XBLOCK, RBLOCK])), tmp31, None)
    tl.store(in_out_ptr0 + (tl.broadcast_to(r0, [XBLOCK, RBLOCK])), tmp79, None)
    tl.store(out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp5, None)
    tl.store(out_ptr1 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp9, None)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/kk/ckkz4nmmavawr3cwhzxvsdtcrjydick2txrs43laojgo3e6wua2r.py
# Topologically Sorted Source Nodes: [mul_1, f_z], Original ATen: [aten.mul, aten.add]
# Source node to ATen node mapping:
#   f_z => add_3
#   mul_1 => mul_3
# Graph fragment:
#   %mul_3 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%view, %view_1), kwargs = {})
#   %add_3 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%primals_3, %mul_3), kwargs = {})
triton_poi_fused_add_mul_1 = async_compile.triton('triton_poi_fused_add_mul_1', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

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

@triton_heuristics.pointwise(
    size_hints=[16], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: '*fp32', 4: '*fp32', 5: '*fp32', 6: '*fp32', 7: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2, 3, 4, 5, 6, 7), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused_add_mul_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 6, '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_mul_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, 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
    x1 = (xindex // 4)
    tmp0 = tl.load(in_ptr0 + (x2), xmask)
    tmp1 = tl.load(in_ptr1 + (x0), xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr2 + (0))
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK])
    tmp12 = tl.load(in_ptr3 + (x0), xmask, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr4 + (0))
    tmp15 = tl.broadcast_to(tmp14, [XBLOCK])
    tmp18 = tl.load(in_ptr5 + (x1), xmask, eviction_policy='evict_last')
    tmp4 = 20.0
    tmp5 = tmp3 > tmp4
    tmp6 = tl_math.exp(tmp3)
    tmp7 = libdevice.log1p(tmp6)
    tmp8 = tl.where(tmp5, tmp3, tmp7)
    tmp9 = -1.0
    tmp10 = tmp8 + tmp9
    tmp11 = tmp10 - tmp3
    tmp13 = tmp11 * tmp12
    tmp16 = tmp13 / tmp15
    tmp17 = tmp1 + tmp16
    tmp19 = libdevice.tanh(tmp18)
    tmp20 = tmp17 * tmp19
    tmp21 = tmp0 + tmp20
    tl.store(out_ptr0 + (x2), tmp21, xmask)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

def call(args):
    primals_1, primals_2, primals_3, primals_4 = args
    args.clear()
    assert_size_stride(primals_1, (4, ), (1, ))
    assert_size_stride(primals_2, (4, ), (1, ))
    assert_size_stride(primals_3, (4, 4), (4, 1))
    assert_size_stride(primals_4, (1, ), (1, ))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((), (), torch.float32)
        buf1 = empty_strided_cuda((), (), torch.float32)
        buf2 = empty_strided_cuda((4, ), (1, ), torch.float32)
        buf4 = empty_strided_cuda((4, ), (1, ), torch.float32)
        buf5 = buf4; del buf4  # reuse
        # Topologically Sorted Source Nodes: [uw, softplus, muw, sub, mul, pow_1, sum_1, truediv, uhat, mv, zwb, psi, psi_u, add_4, abs_1, add_5, logdet_jacobian], Original ATen: [aten.dot, aten.softplus, aten.add, aten.sub, aten.mul, aten.pow, aten.sum, aten.div, aten.mv, aten.abs, aten.log]
        stream0 = get_raw_stream(0)
        triton_per_fused_abs_add_div_dot_log_mul_mv_pow_softplus_sub_sum_0.run(buf5, primals_1, primals_2, primals_3, primals_4, buf0, buf1, buf2, 1, 4, grid=grid(1), stream=stream0)
        buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [mul_1, f_z], Original ATen: [aten.mul, aten.add]
        triton_poi_fused_add_mul_1.run(primals_3, primals_1, buf0, primals_2, buf1, buf2, buf3, 16, grid=grid(16), stream=stream0)
        del buf0
        del buf1
        del buf2
    return (buf3, buf5, primals_1, primals_2, primals_3, 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((4, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_3 = rand_strided((4, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    primals_4 = rand_strided((1, ), (1, ), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([primals_1, primals_2, primals_3, primals_4])
    return print_performance(fn, times=times, repeat=repeat)


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

import torch
import torch.nn.functional as F
from torch import nn


class PlanarNormalizingFlow(nn.Module):
    """
    Planar normalizing flow [Rezende & Mohamed 2015].
    Provides a tighter bound on the ELBO by giving more expressive
    power to the approximate distribution, such as by introducing
    covariance between terms.
    """

    def __init__(self, in_features):
        super(PlanarNormalizingFlow, self).__init__()
        self.u = nn.Parameter(torch.randn(in_features))
        self.w = nn.Parameter(torch.randn(in_features))
        self.b = nn.Parameter(torch.ones(1))

    def forward(self, z):
        uw = torch.dot(self.u, self.w)
        muw = -1 + F.softplus(uw)
        uhat = self.u + (muw - uw) * torch.transpose(self.w, 0, -1
            ) / torch.sum(self.w ** 2)
        zwb = torch.mv(z, self.w) + self.b
        f_z = z + uhat.view(1, -1) * F.tanh(zwb).view(-1, 1)
        psi = (1 - F.tanh(zwb) ** 2).view(-1, 1) * self.w.view(1, -1)
        psi_u = torch.mv(psi, uhat)
        logdet_jacobian = torch.log(torch.abs(1 + psi_u) + 1e-08)
        return f_z, logdet_jacobian


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


def get_init_inputs():
    return [[], {'in_features': 4}]

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


@triton.jit
def triton_per_fused_abs_add_div_dot_log_mul_mv_pow_softplus_sub_sum_0(
    in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, out_ptr1,
    out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 4
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:, None]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp1 = tl.load(in_ptr1 + r0, None)
    tmp10 = tl.load(in_ptr2 + 4 * r0, None, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr1 + 0)
    tmp12 = tl.broadcast_to(tmp11, [XBLOCK, RBLOCK])
    tmp14 = tl.load(in_ptr2 + (1 + 4 * r0), None, eviction_policy='evict_last')
    tmp15 = tl.load(in_ptr1 + 1)
    tmp16 = tl.broadcast_to(tmp15, [XBLOCK, RBLOCK])
    tmp19 = tl.load(in_ptr2 + (2 + 4 * r0), None, eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr1 + 2)
    tmp21 = tl.broadcast_to(tmp20, [XBLOCK, RBLOCK])
    tmp24 = tl.load(in_ptr2 + (3 + 4 * r0), None, eviction_policy='evict_last')
    tmp25 = tl.load(in_ptr1 + 3)
    tmp26 = tl.broadcast_to(tmp25, [XBLOCK, RBLOCK])
    tmp29 = tl.load(in_ptr3 + 0)
    tmp30 = tl.broadcast_to(tmp29, [XBLOCK, RBLOCK])
    tmp37 = tl.load(in_ptr0 + 0)
    tmp38 = tl.broadcast_to(tmp37, [XBLOCK, RBLOCK])
    tmp52 = tl.load(in_ptr0 + 1)
    tmp53 = tl.broadcast_to(tmp52, [XBLOCK, RBLOCK])
    tmp60 = tl.load(in_ptr0 + 2)
    tmp61 = tl.broadcast_to(tmp60, [XBLOCK, RBLOCK])
    tmp68 = tl.load(in_ptr0 + 3)
    tmp69 = tl.broadcast_to(tmp68, [XBLOCK, RBLOCK])
    tmp2 = tmp0 * tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.sum(tmp3, 1)[:, None]
    tmp6 = tmp1 * tmp1
    tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
    tmp9 = tl.sum(tmp7, 1)[:, None]
    tmp13 = tmp10 * tmp12
    tmp17 = tmp14 * tmp16
    tmp18 = tmp13 + tmp17
    tmp22 = tmp19 * tmp21
    tmp23 = tmp18 + tmp22
    tmp27 = tmp24 * tmp26
    tmp28 = tmp23 + tmp27
    tmp31 = tmp28 + tmp30
    tmp32 = libdevice.tanh(tmp31)
    tmp33 = tmp32 * tmp32
    tmp34 = 1.0
    tmp35 = tmp34 - tmp33
    tmp36 = tmp35 * tmp12
    tmp39 = 20.0
    tmp40 = tmp5 > tmp39
    tmp41 = tl_math.exp(tmp5)
    tmp42 = libdevice.log1p(tmp41)
    tmp43 = tl.where(tmp40, tmp5, tmp42)
    tmp44 = -1.0
    tmp45 = tmp43 + tmp44
    tmp46 = tmp45 - tmp5
    tmp47 = tmp46 * tmp12
    tmp48 = tmp47 / tmp9
    tmp49 = tmp38 + tmp48
    tmp50 = tmp36 * tmp49
    tmp51 = tmp35 * tmp16
    tmp54 = tmp46 * tmp16
    tmp55 = tmp54 / tmp9
    tmp56 = tmp53 + tmp55
    tmp57 = tmp51 * tmp56
    tmp58 = tmp50 + tmp57
    tmp59 = tmp35 * tmp21
    tmp62 = tmp46 * tmp21
    tmp63 = tmp62 / tmp9
    tmp64 = tmp61 + tmp63
    tmp65 = tmp59 * tmp64
    tmp66 = tmp58 + tmp65
    tmp67 = tmp35 * tmp26
    tmp70 = tmp46 * tmp26
    tmp71 = tmp70 / tmp9
    tmp72 = tmp69 + tmp71
    tmp73 = tmp67 * tmp72
    tmp74 = tmp66 + tmp73
    tmp75 = tmp74 + tmp34
    tmp76 = tl_math.abs(tmp75)
    tmp77 = 1e-08
    tmp78 = tmp76 + tmp77
    tmp79 = tl_math.log(tmp78)
    tl.store(out_ptr2 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp31, None)
    tl.store(in_out_ptr0 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp79, None)
    tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp5, None)
    tl.store(out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp9, None)


@triton.jit
def triton_poi_fused_add_mul_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
    in_ptr5, 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
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr2 + 0)
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK])
    tmp12 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr4 + 0)
    tmp15 = tl.broadcast_to(tmp14, [XBLOCK])
    tmp18 = tl.load(in_ptr5 + x1, xmask, eviction_policy='evict_last')
    tmp4 = 20.0
    tmp5 = tmp3 > tmp4
    tmp6 = tl_math.exp(tmp3)
    tmp7 = libdevice.log1p(tmp6)
    tmp8 = tl.where(tmp5, tmp3, tmp7)
    tmp9 = -1.0
    tmp10 = tmp8 + tmp9
    tmp11 = tmp10 - tmp3
    tmp13 = tmp11 * tmp12
    tmp16 = tmp13 / tmp15
    tmp17 = tmp1 + tmp16
    tmp19 = libdevice.tanh(tmp18)
    tmp20 = tmp17 * tmp19
    tmp21 = tmp0 + tmp20
    tl.store(out_ptr0 + x2, tmp21, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4 = args
    args.clear()
    assert_size_stride(primals_1, (4,), (1,))
    assert_size_stride(primals_2, (4,), (1,))
    assert_size_stride(primals_3, (4, 4), (4, 1))
    assert_size_stride(primals_4, (1,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((), (), torch.float32)
        buf1 = empty_strided_cuda((), (), torch.float32)
        buf2 = empty_strided_cuda((4,), (1,), torch.float32)
        buf4 = empty_strided_cuda((4,), (1,), torch.float32)
        buf5 = buf4
        del buf4
        get_raw_stream(0)
        triton_per_fused_abs_add_div_dot_log_mul_mv_pow_softplus_sub_sum_0[grid
            (1)](buf5, primals_1, primals_2, primals_3, primals_4, buf0,
            buf1, buf2, 1, 4, XBLOCK=1, num_warps=2, num_stages=1)
        buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        triton_poi_fused_add_mul_1[grid(16)](primals_3, primals_1, buf0,
            primals_2, buf1, buf2, buf3, 16, XBLOCK=16, num_warps=1,
            num_stages=1)
        del buf0
        del buf1
        del buf2
    return buf3, buf5, primals_1, primals_2, primals_3, primals_4


class PlanarNormalizingFlowNew(nn.Module):
    """
    Planar normalizing flow [Rezende & Mohamed 2015].
    Provides a tighter bound on the ELBO by giving more expressive
    power to the approximate distribution, such as by introducing
    covariance between terms.
    """

    def __init__(self, in_features):
        super(PlanarNormalizingFlowNew, self).__init__()
        self.u = nn.Parameter(torch.randn(in_features))
        self.w = nn.Parameter(torch.randn(in_features))
        self.b = nn.Parameter(torch.ones(1))

    def forward(self, input_0):
        primals_1 = self.u
        primals_2 = self.w
        primals_4 = self.b
        primals_3 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4])
        return output[0], output[1]
