import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
import torch.nn as nn
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_reflection_pad2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 576
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 6
    x1 = xindex // 6 % 6
    x2 = xindex // 36
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
        x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2),
        xmask, eviction_policy='evict_last')
    tl.store(out_ptr0 + x3, tmp0, xmask)


@triton.jit
def triton_per_fused_add_convolution_div_hardtanh_hardtanh_backward_mean_sqrt_sub_var_1(
    in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1,
    out_ptr2, out_ptr3, out_ptr6, out_ptr7, xnumel, rnumel, XBLOCK: tl.
    constexpr):
    xnumel = 16
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r2 = rindex
    x3 = xindex
    x0 = xindex % 4
    tmp0 = tl.load(in_ptr0 + (r2 + 16 * x3), xmask, other=0.0)
    tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr2 + (r2 + 16 * x3), xmask, other=0.0)
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp5 = 6.0
    tmp6 = triton_helpers.minimum(tmp4, tmp5)
    tmp7 = tmp2 <= tmp3
    tmp8 = tmp2 >= tmp5
    tmp9 = tmp7 | tmp8
    tmp11 = tmp10 + tmp1
    tmp12 = triton_helpers.maximum(tmp11, tmp3)
    tmp13 = triton_helpers.minimum(tmp12, tmp5)
    tmp14 = tmp11 <= tmp3
    tmp15 = tmp11 >= tmp5
    tmp16 = tmp14 | tmp15
    tmp17 = tl.broadcast_to(tmp13, [XBLOCK, RBLOCK])
    tmp19 = tl.where(xmask, tmp17, 0)
    tmp20 = tl.broadcast_to(tmp17, [XBLOCK, RBLOCK])
    tmp22 = tl.where(xmask, tmp20, 0)
    tmp23 = tl.sum(tmp22, 1)[:, None]
    tmp24 = tl.full([XBLOCK, 1], 16, tl.int32)
    tmp25 = tmp24.to(tl.float32)
    tmp26 = tmp23 / tmp25
    tmp27 = tmp17 - tmp26
    tmp28 = tmp27 * tmp27
    tmp29 = tl.broadcast_to(tmp28, [XBLOCK, RBLOCK])
    tmp31 = tl.where(xmask, tmp29, 0)
    tmp32 = tl.sum(tmp31, 1)[:, None]
    tmp34 = tl.sum(tmp19, 1)[:, None]
    tmp35 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
    tmp37 = tl.where(xmask, tmp35, 0)
    tmp38 = tl.broadcast_to(tmp35, [XBLOCK, RBLOCK])
    tmp40 = tl.where(xmask, tmp38, 0)
    tmp41 = tl.sum(tmp40, 1)[:, None]
    tmp42 = tmp41 / tmp25
    tmp43 = tmp35 - tmp42
    tmp44 = tmp43 * tmp43
    tmp45 = tl.broadcast_to(tmp44, [XBLOCK, RBLOCK])
    tmp47 = tl.where(xmask, tmp45, 0)
    tmp48 = tl.sum(tmp47, 1)[:, None]
    tmp50 = tl.sum(tmp37, 1)[:, None]
    tmp51 = 15.0
    tmp52 = tmp32 / tmp51
    tmp53 = 1e-05
    tmp54 = tmp52 + tmp53
    tmp55 = libdevice.sqrt(tmp54)
    tmp56 = tmp48 / tmp51
    tmp57 = tmp56 + tmp53
    tmp58 = libdevice.sqrt(tmp57)
    tmp59 = 16.0
    tmp60 = tmp50 / tmp59
    tmp61 = tmp6 - tmp60
    tmp62 = tmp61 / tmp58
    tmp63 = tmp34 / tmp59
    tmp64 = tmp13 - tmp63
    tmp65 = tmp64 / tmp55
    tl.store(out_ptr0 + (r2 + 16 * x3), tmp6, xmask)
    tl.store(out_ptr1 + (r2 + 16 * x3), tmp9, xmask)
    tl.store(out_ptr2 + (r2 + 16 * x3), tmp13, xmask)
    tl.store(out_ptr3 + (r2 + 16 * x3), tmp16, xmask)
    tl.debug_barrier()
    tl.store(in_out_ptr0 + x3, tmp55, xmask)
    tl.debug_barrier()
    tl.store(in_out_ptr1 + x3, tmp58, xmask)
    tl.store(out_ptr6 + (r2 + 16 * x3), tmp62, xmask)
    tl.store(out_ptr7 + (r2 + 16 * x3), tmp65, xmask)


@triton.jit
def triton_poi_fused_convolution_hardtanh_hardtanh_backward_2(in_ptr0,
    in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 128
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 16 % 2
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp5 = 6.0
    tmp6 = triton_helpers.minimum(tmp4, tmp5)
    tmp7 = tmp2 <= tmp3
    tmp8 = tmp2 >= tmp5
    tmp9 = tmp7 | tmp8
    tl.store(out_ptr0 + x3, tmp6, xmask)
    tl.store(out_ptr1 + x3, tmp9, xmask)


@triton.jit
def triton_per_fused__softmax_3(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK:
    tl.constexpr):
    xnumel = 64
    RBLOCK: tl.constexpr = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r1 = rindex
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp3 = tl.where(xmask, tmp1, float('-inf'))
    tmp4 = triton_helpers.max2(tmp3, 1)[:, None]
    tmp5 = tmp0 - tmp4
    tmp6 = tl_math.exp(tmp5)
    tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
    tmp9 = tl.where(xmask, tmp7, 0)
    tmp10 = tl.sum(tmp9, 1)[:, None]
    tmp11 = tmp6 / tmp10
    tl.store(out_ptr2 + (r1 + 16 * x0), tmp11, xmask)


@triton.jit
def triton_poi_fused_convolution_hardtanh_reflection_pad2d_4(in_ptr0,
    in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 576
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 6
    x1 = xindex // 6 % 6
    x4 = xindex // 36
    x2 = xindex // 36 % 4
    x5 = xindex
    tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
        x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x4),
        xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp5 = 6.0
    tmp6 = triton_helpers.minimum(tmp4, tmp5)
    tl.store(out_ptr0 + x5, tmp6, xmask)


@triton.jit
def triton_poi_fused_convolution_hardtanh_hardtanh_backward_5(in_ptr0,
    in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 16 % 4
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = triton_helpers.maximum(tmp2, tmp3)
    tmp5 = 6.0
    tmp6 = triton_helpers.minimum(tmp4, tmp5)
    tmp7 = tmp2 <= tmp3
    tmp8 = tmp2 >= tmp5
    tmp9 = tmp7 | tmp8
    tl.store(out_ptr0 + x3, tmp6, xmask)
    tl.store(out_ptr1 + x3, tmp9, xmask)


@triton.jit
def triton_poi_fused_cat_6(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 512
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 16 % 8
    x0 = xindex % 16
    x2 = xindex // 128
    x3 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 64 * x2), tmp4 & xmask, other=0.0)
    tmp6 = tmp0 >= tmp3
    tl.full([1], 8, tl.int64)
    tmp9 = tl.load(in_ptr1 + (x0 + 16 * (-4 + x1) + 64 * x2), tmp6 & xmask,
        other=0.0)
    tmp10 = tl.where(tmp4, tmp5, tmp9)
    tl.store(out_ptr0 + x3, tmp10, xmask)


@triton.jit
def triton_poi_fused_convolution_7(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 16 % 4
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x3, tmp2, xmask)


@triton.jit
def triton_poi_fused_convolution_8(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_out_ptr0 + x0, xmask)
    tmp1 = tl.load(in_ptr0 + 0)
    tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
    tmp3 = tmp0 + tmp2
    tl.store(in_out_ptr0 + x0, tmp3, xmask)


@triton.jit
def triton_poi_fused_reflection_pad2d_9(in_ptr0, out_ptr0, xnumel, XBLOCK:
    tl.constexpr):
    xnumel = 1024
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 8
    x1 = xindex // 8 % 8
    x2 = xindex // 64
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-2 +
        x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-2 + x1)) + 16 * x2),
        xmask, eviction_policy='evict_last')
    tl.store(out_ptr0 + x3, tmp0, xmask)


@triton.jit
def triton_poi_fused_add_clamp_convolution_div_mul_rsub_sigmoid_10(in_out_ptr0,
    in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 16 % 4
    x0 = xindex % 16
    x2 = xindex // 64
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_out_ptr1 + x3, xmask)
    tmp4 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr2 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp8 = tl.load(in_ptr3 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp11 = tl.load(in_ptr4 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp2 = tmp0 + tmp1
    tmp5 = tmp3 + tmp4
    tmp7 = tl.sigmoid(tmp6)
    tmp9 = tl.sigmoid(tmp8)
    tmp10 = tmp7 + tmp9
    tmp12 = tl.sigmoid(tmp11)
    tmp13 = tmp10 + tmp12
    tmp14 = 0.3333333333333333
    tmp15 = tmp13 * tmp14
    tmp16 = 0.0
    tmp17 = triton_helpers.maximum(tmp15, tmp16)
    tmp18 = 1.0
    tmp19 = triton_helpers.minimum(tmp17, tmp18)
    tmp20 = tmp19 * tmp2
    tmp21 = tmp18 - tmp15
    tmp22 = triton_helpers.maximum(tmp21, tmp16)
    tmp23 = triton_helpers.minimum(tmp22, tmp18)
    tmp24 = tmp23 * tmp5
    tmp25 = tmp20 + tmp24
    tl.store(in_out_ptr0 + x3, tmp2, xmask)
    tl.store(in_out_ptr1 + x3, tmp5, xmask)
    tl.store(out_ptr0 + x3, tmp25, xmask)


@triton.jit
def triton_poi_fused_convolution_hardtanh_backward_11(in_ptr0, in_ptr1,
    out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 16 % 4
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = tmp2 <= tmp3
    tmp5 = 6.0
    tmp6 = tmp2 >= tmp5
    tmp7 = tmp4 | tmp6
    tl.store(out_ptr0 + x3, tmp7, 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, primals_20, primals_21, primals_22,
        primals_23, primals_24, primals_25, primals_26) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_3, (4,), (1,))
    assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_5, (2, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_6, (2,), (1,))
    assert_size_stride(primals_7, (2, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_8, (2,), (1,))
    assert_size_stride(primals_9, (2, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_10, (2,), (1,))
    assert_size_stride(primals_11, (4, 2, 1, 1), (2, 1, 1, 1))
    assert_size_stride(primals_12, (4,), (1,))
    assert_size_stride(primals_13, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_14, (4,), (1,))
    assert_size_stride(primals_15, (4, 8, 1, 1), (8, 1, 1, 1))
    assert_size_stride(primals_16, (4,), (1,))
    assert_size_stride(primals_17, (4, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_18, (4,), (1,))
    assert_size_stride(primals_19, (4, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_20, (4,), (1,))
    assert_size_stride(primals_21, (1, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_22, (1,), (1,))
    assert_size_stride(primals_23, (1, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_24, (1,), (1,))
    assert_size_stride(primals_25, (1, 4, 5, 5), (100, 25, 5, 1))
    assert_size_stride(primals_26, (1,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_reflection_pad2d_0[grid(576)](primals_1, buf0, 576,
            XBLOCK=256, num_warps=4, num_stages=1)
        del primals_1
        buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1))
        buf3 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32)
        triton_poi_fused_reflection_pad2d_0[grid(576)](primals_4, buf3, 576,
            XBLOCK=256, num_warps=4, num_stages=1)
        del primals_4
        buf4 = extern_kernels.convolution(buf3, primals_2, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf4, (4, 4, 4, 4), (64, 16, 4, 1))
        buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf54 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
        buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf55 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
        buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf14 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
        buf9 = buf7
        del buf7
        buf16 = buf14
        del buf14
        buf18 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        buf11 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_per_fused_add_convolution_div_hardtanh_hardtanh_backward_mean_sqrt_sub_var_1[
            grid(16)](buf9, buf16, buf4, primals_3, buf1, buf5, buf54, buf2,
            buf55, buf18, buf11, 16, 16, XBLOCK=8, num_warps=2, num_stages=1)
        del buf1
        del primals_3
        buf12 = extern_kernels.convolution(buf11, primals_5, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf12, (4, 2, 4, 4), (32, 16, 4, 1))
        buf19 = extern_kernels.convolution(buf18, primals_7, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf19, (4, 2, 4, 4), (32, 16, 4, 1))
        buf20 = extern_kernels.convolution(buf5, primals_9, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf20, (4, 2, 4, 4), (32, 16, 4, 1))
        buf21 = empty_strided_cuda((4, 2, 4, 4), (32, 16, 4, 1), torch.float32)
        buf53 = empty_strided_cuda((4, 2, 4, 4), (32, 16, 4, 1), torch.bool)
        triton_poi_fused_convolution_hardtanh_hardtanh_backward_2[grid(128)](
            buf12, primals_6, buf21, buf53, 128, XBLOCK=128, num_warps=4,
            num_stages=1)
        del primals_6
        buf22 = buf12
        del buf12
        buf52 = empty_strided_cuda((4, 2, 4, 4), (32, 16, 4, 1), torch.bool)
        triton_poi_fused_convolution_hardtanh_hardtanh_backward_2[grid(128)](
            buf19, primals_8, buf22, buf52, 128, XBLOCK=128, num_warps=4,
            num_stages=1)
        del primals_8
        buf23 = empty_strided_cuda((4, 16, 16), (256, 16, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf21, (4, 16, 2), (32, 1, 16
            ), 0), reinterpret_tensor(buf22, (4, 2, 16), (32, 16, 1), 0),
            out=buf23)
        buf26 = empty_strided_cuda((4, 16, 16), (256, 16, 1), torch.float32)
        triton_per_fused__softmax_3[grid(64)](buf23, buf26, 64, 16, XBLOCK=
            1, num_warps=2, num_stages=1)
        buf27 = buf19
        del buf19
        buf51 = empty_strided_cuda((4, 2, 4, 4), (32, 16, 4, 1), torch.bool)
        triton_poi_fused_convolution_hardtanh_hardtanh_backward_2[grid(128)](
            buf20, primals_10, buf27, buf51, 128, XBLOCK=128, num_warps=4,
            num_stages=1)
        del primals_10
        buf28 = reinterpret_tensor(buf20, (4, 2, 16), (32, 16, 1), 0)
        del buf20
        extern_kernels.bmm(reinterpret_tensor(buf27, (4, 2, 16), (32, 16, 1
            ), 0), reinterpret_tensor(buf26, (4, 16, 16), (256, 1, 16), 0),
            out=buf28)
        buf29 = extern_kernels.convolution(reinterpret_tensor(buf28, (4, 2,
            4, 4), (32, 16, 4, 1), 0), primals_11, stride=(1, 1), padding=(
            0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0),
            groups=1, bias=None)
        assert_size_stride(buf29, (4, 4, 4, 4), (64, 16, 4, 1))
        buf30 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32
            )
        triton_poi_fused_convolution_hardtanh_reflection_pad2d_4[grid(576)](
            buf29, primals_12, buf30, 576, XBLOCK=128, num_warps=4,
            num_stages=1)
        buf31 = extern_kernels.convolution(buf30, primals_13, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf31, (4, 4, 4, 4), (64, 16, 4, 1))
        buf32 = buf4
        del buf4
        buf49 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
        triton_poi_fused_convolution_hardtanh_hardtanh_backward_5[grid(256)](
            buf31, primals_14, buf32, buf49, 256, XBLOCK=256, num_warps=4,
            num_stages=1)
        del primals_14
        buf33 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32
            )
        triton_poi_fused_cat_6[grid(512)](buf2, buf32, buf33, 512, XBLOCK=
            256, num_warps=4, num_stages=1)
        buf34 = extern_kernels.convolution(buf33, primals_15, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf34, (4, 4, 4, 4), (64, 16, 4, 1))
        buf35 = buf34
        del buf34
        triton_poi_fused_convolution_7[grid(256)](buf35, primals_16, 256,
            XBLOCK=128, num_warps=4, num_stages=1)
        del primals_16
        buf36 = extern_kernels.convolution(buf2, primals_17, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf36, (4, 4, 4, 4), (64, 16, 4, 1))
        buf38 = extern_kernels.convolution(buf32, primals_19, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf38, (4, 4, 4, 4), (64, 16, 4, 1))
        buf40 = extern_kernels.convolution(buf35, primals_21, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf40, (4, 1, 4, 4), (16, 16, 4, 1))
        buf41 = buf40
        del buf40
        triton_poi_fused_convolution_8[grid(64)](buf41, primals_22, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        del primals_22
        buf42 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32
            )
        triton_poi_fused_reflection_pad2d_0[grid(576)](buf35, buf42, 576,
            XBLOCK=256, num_warps=4, num_stages=1)
        buf43 = extern_kernels.convolution(buf42, primals_23, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf43, (4, 1, 4, 4), (16, 16, 4, 1))
        buf44 = buf43
        del buf43
        triton_poi_fused_convolution_8[grid(64)](buf44, primals_24, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        del primals_24
        buf45 = reinterpret_tensor(buf23, (4, 4, 8, 8), (256, 64, 8, 1), 0)
        del buf23
        triton_poi_fused_reflection_pad2d_9[grid(1024)](buf35, buf45, 1024,
            XBLOCK=128, num_warps=4, num_stages=1)
        buf46 = extern_kernels.convolution(buf45, primals_25, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf46, (4, 1, 4, 4), (16, 16, 4, 1))
        buf47 = buf46
        del buf46
        triton_poi_fused_convolution_8[grid(64)](buf47, primals_26, 64,
            XBLOCK=64, num_warps=1, num_stages=1)
        del primals_26
        buf37 = buf36
        del buf36
        buf39 = buf38
        del buf38
        buf48 = buf31
        del buf31
        triton_poi_fused_add_clamp_convolution_div_mul_rsub_sigmoid_10[grid
            (256)](buf37, buf39, primals_18, primals_20, buf41, buf44,
            buf47, buf48, 256, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_18
        del primals_20
        buf50 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
        triton_poi_fused_convolution_hardtanh_backward_11[grid(256)](buf29,
            primals_12, buf50, 256, XBLOCK=256, num_warps=4, num_stages=1)
        del buf29
        del primals_12
    return (buf48, primals_2, primals_5, primals_7, primals_9, primals_11,
        primals_13, primals_15, primals_17, primals_19, primals_21,
        primals_23, primals_25, buf0, buf2, buf3, buf5, buf9, buf11, buf16,
        buf18, buf26, reinterpret_tensor(buf28, (4, 2, 4, 4), (32, 16, 4, 1
        ), 0), buf30, buf32, buf33, buf35, buf37, buf39, buf41, buf42,
        buf44, buf45, buf47, buf49, buf50, reinterpret_tensor(buf27, (4, 16,
        2), (32, 1, 16), 0), reinterpret_tensor(buf21, (4, 2, 16), (32, 16,
        1), 0), reinterpret_tensor(buf22, (4, 16, 2), (32, 1, 16), 0),
        buf51, buf52, buf53, buf54, buf55)


def calc_mean_std(feat, eps=1e-05):
    size = feat.size()
    assert len(size) == 4
    N, C = size[:2]
    feat_var = feat.view(N, C, -1).var(dim=2) + eps
    feat_std = feat_var.sqrt().view(N, C, 1, 1)
    feat_mean = feat.view(N, C, -1).mean(dim=2).view(N, C, 1, 1)
    return feat_mean, feat_std


def mean_variance_norm(feat):
    size = feat.size()
    mean, std = calc_mean_std(feat)
    normalized_feat = (feat - mean.expand(size)) / std.expand(size)
    return normalized_feat


class AttentionUnit(nn.Module):

    def __init__(self, channels):
        super(AttentionUnit, self).__init__()
        self.relu6 = nn.ReLU6()
        self.f = nn.Conv2d(channels, channels // 2, (1, 1))
        self.g = nn.Conv2d(channels, channels // 2, (1, 1))
        self.h = nn.Conv2d(channels, channels // 2, (1, 1))
        self.out_conv = nn.Conv2d(channels // 2, channels, (1, 1))
        self.softmax = nn.Softmax(dim=-1)

    def forward(self, Fc, Fs):
        B, C, H, W = Fc.shape
        f_Fc = self.relu6(self.f(mean_variance_norm(Fc)))
        g_Fs = self.relu6(self.g(mean_variance_norm(Fs)))
        h_Fs = self.relu6(self.h(Fs))
        f_Fc = f_Fc.view(f_Fc.shape[0], f_Fc.shape[1], -1).permute(0, 2, 1)
        g_Fs = g_Fs.view(g_Fs.shape[0], g_Fs.shape[1], -1)
        Attention = self.softmax(torch.bmm(f_Fc, g_Fs))
        h_Fs = h_Fs.view(h_Fs.shape[0], h_Fs.shape[1], -1)
        Fcs = torch.bmm(h_Fs, Attention.permute(0, 2, 1))
        Fcs = Fcs.view(B, C // 2, H, W)
        Fcs = self.relu6(self.out_conv(Fcs))
        return Fcs


class FuseUnit(nn.Module):

    def __init__(self, channels):
        super(FuseUnit, self).__init__()
        self.proj1 = nn.Conv2d(2 * channels, channels, (1, 1))
        self.proj2 = nn.Conv2d(channels, channels, (1, 1))
        self.proj3 = nn.Conv2d(channels, channels, (1, 1))
        self.fuse1x = nn.Conv2d(channels, 1, (1, 1), stride=1)
        self.fuse3x = nn.Conv2d(channels, 1, (3, 3), stride=1)
        self.fuse5x = nn.Conv2d(channels, 1, (5, 5), stride=1)
        self.pad3x = nn.ReflectionPad2d((1, 1, 1, 1))
        self.pad5x = nn.ReflectionPad2d((2, 2, 2, 2))
        self.sigmoid = nn.Sigmoid()

    def forward(self, F1, F2):
        Fcat = self.proj1(torch.cat((F1, F2), dim=1))
        F1 = self.proj2(F1)
        F2 = self.proj3(F2)
        fusion1 = self.sigmoid(self.fuse1x(Fcat))
        fusion3 = self.sigmoid(self.fuse3x(self.pad3x(Fcat)))
        fusion5 = self.sigmoid(self.fuse5x(self.pad5x(Fcat)))
        fusion = (fusion1 + fusion3 + fusion5) / 3
        return torch.clamp(fusion, min=0, max=1.0) * F1 + torch.clamp(1 -
            fusion, min=0, max=1.0) * F2


class PAMANew(nn.Module):

    def __init__(self, channels):
        super(PAMANew, self).__init__()
        self.conv_in = nn.Conv2d(channels, channels, (3, 3), stride=1)
        self.attn = AttentionUnit(channels)
        self.fuse = FuseUnit(channels)
        self.conv_out = nn.Conv2d(channels, channels, (3, 3), stride=1)
        self.pad = nn.ReflectionPad2d((1, 1, 1, 1))
        self.relu6 = nn.ReLU6()

    def forward(self, input_0, input_1):
        primals_2 = self.conv_in.weight
        primals_3 = self.conv_in.bias
        primals_5 = self.attn.f.weight
        primals_6 = self.attn.f.bias
        primals_7 = self.attn.g.weight
        primals_8 = self.attn.g.bias
        primals_9 = self.attn.h.weight
        primals_10 = self.attn.h.bias
        primals_11 = self.attn.out_conv.weight
        primals_12 = self.attn.out_conv.bias
        primals_15 = self.fuse.proj1.weight
        primals_14 = self.fuse.proj1.bias
        primals_17 = self.fuse.proj2.weight
        primals_16 = self.fuse.proj2.bias
        primals_19 = self.fuse.proj3.weight
        primals_18 = self.fuse.proj3.bias
        primals_21 = self.fuse.fuse1x.weight
        primals_22 = self.fuse.fuse1x.bias
        primals_23 = self.fuse.fuse3x.weight
        primals_24 = self.fuse.fuse3x.bias
        primals_25 = self.fuse.fuse5x.weight
        primals_26 = self.fuse.fuse5x.bias
        primals_13 = self.conv_out.weight
        primals_20 = self.conv_out.bias
        primals_1 = input_0
        primals_4 = input_1
        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,
            primals_20, primals_21, primals_22, primals_23, primals_24,
            primals_25, primals_26])
        return output[0]


Measured latency_ms: 0.160145