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


def activation(act_type, inplace=True, neg_slope=0.05, n_prelu=1):
    act_type = act_type.lower()
    if act_type == 'relu':
        layer = nn.ReLU(inplace)
    elif act_type == 'lrelu':
        layer = nn.LeakyReLU(neg_slope, False)
    elif act_type == 'prelu':
        layer = nn.PReLU(num_parameters=n_prelu, init=neg_slope)
    else:
        raise NotImplementedError('activation layer [{:s}] is not found'.
            format(act_type))
    return layer


def conv_layer(in_channels, out_channels, kernel_size, stride=1, dilation=1,
    groups=1):
    padding = int((kernel_size - 1) / 2) * dilation
    return nn.Conv2d(in_channels, out_channels, kernel_size, stride,
        padding=padding, bias=True, dilation=dilation, groups=groups)


class ESA(nn.Module):

    def __init__(self, n_feats, conv):
        super(ESA, self).__init__()
        f = n_feats // 4
        self.conv1 = conv(n_feats, f, kernel_size=1)
        self.conv_f = conv(f, f, kernel_size=1)
        self.conv_max = conv(f, f, kernel_size=3, padding=1)
        self.conv2 = conv(f, f, kernel_size=3, stride=2, padding=0)
        self.conv3 = conv(f, f, kernel_size=3, padding=1)
        self.conv3_ = conv(f, f, kernel_size=3, padding=1)
        self.conv4 = conv(f, n_feats, kernel_size=1)
        self.sigmoid = nn.Sigmoid()
        self.relu = nn.ReLU(inplace=True)
        self.skip_add = torch.nn.quantized.FloatFunctional()

    def forward(self, x):
        c1_ = self.conv1(x)
        c1 = self.conv2(c1_)
        v_max = F.max_pool2d(c1, kernel_size=7, stride=3)
        v_range = self.relu(self.conv_max(v_max))
        c3 = self.relu(self.conv3(v_range))
        c3 = self.conv3_(c3)
        c3 = F.interpolate(c3, (x.size(2), x.size(3)), mode='bilinear',
            align_corners=False)
        cf = self.conv_f(c1_)
        c4 = self.conv4(self.skip_add.add(c3, cf))
        m = self.sigmoid(c4)
        return self.skip_add.mul(x, m)


class RFDBsmall(nn.Module):

    def __init__(self, in_channels, distillation_rate=0.25):
        super(RFDBsmall, self).__init__()
        self.dc = self.distilled_channels = in_channels // 2
        self.rc = self.remaining_channels = in_channels
        self.c1_d = conv_layer(in_channels, self.dc, 1)
        self.c1_r = conv_layer(in_channels, self.rc, 3)
        self.c2_d = conv_layer(self.remaining_channels, self.dc, 1)
        self.c2_r = conv_layer(self.remaining_channels, self.rc, 3)
        self.c3 = conv_layer(self.remaining_channels, self.dc, 3)
        self.act = activation('lrelu', neg_slope=0.05)
        self.c4 = conv_layer(self.dc * 3, in_channels, 1)
        self.esa = ESA(in_channels, nn.Conv2d)
        self.skip_add = torch.nn.quantized.FloatFunctional()

    def forward(self, input):
        distilled_c1 = self.act(self.c1_d(input))
        r_c1 = self.c1_r(input)
        r_c1 = self.act(self.skip_add.add(r_c1, input))
        """
        ----> conv ->
                    + -> act --> r_c<n> -> conv -> act -> distilled_c<n+1>
        ------------>
        """
        distilled_c2 = self.act(self.c2_d(r_c1))
        r_c2 = self.c2_r(r_c1)
        r_c2 = self.act(self.skip_add.add(r_c2, r_c1))
        r_c3 = self.act(self.c3(r_c2))
        out = torch.cat([distilled_c1, distilled_c2, r_c3], dim=1)
        out_fused = self.esa(self.c4(out))
        return out_fused


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


def get_init_inputs():
    return [[], {'in_channels': 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 import triton_helpers
import torch.nn as nn
import torch.nn.functional as F
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_poi_fused_convolution_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x1 = xindex // 4096 % 2
    tmp0 = tl.load(in_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = 0.0
    tmp4 = tmp2 > tmp3
    tl.store(out_ptr0 + x3, tmp4, None)


@triton.jit
def triton_poi_fused_add_convolution_leaky_relu_1(in_ptr0, in_ptr1, in_ptr2,
    out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x1 = xindex // 4096 % 4
    tmp0 = tl.load(in_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + x3, None)
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp5 = 0.0
    tmp6 = tmp4 > tmp5
    tmp7 = 0.05
    tmp8 = tmp4 * tmp7
    tmp9 = tl.where(tmp6, tmp4, tmp8)
    tl.store(out_ptr0 + x3, tmp6, None)
    tl.store(out_ptr1 + x3, tmp9, None)


@triton.jit
def triton_poi_fused_cat_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
    in_ptr5, in_ptr6, in_ptr7, in_ptr8, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x1 = xindex // 4096 % 6
    x0 = xindex % 4096
    x2 = xindex // 24576
    x3 = xindex
    tmp0 = x1
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 2, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + (x0 + 4096 * x1 + 8192 * x2), tmp4, other=0.0).to(
        tl.int1)
    tmp6 = tl.load(in_ptr1 + (x0 + 4096 * x1 + 8192 * x2), tmp4, other=0.0)
    tmp7 = tl.load(in_ptr2 + x1, tmp4, eviction_policy='evict_last', other=0.0)
    tmp8 = tmp6 + tmp7
    tmp9 = 0.05
    tmp10 = tmp8 * tmp9
    tmp11 = tl.where(tmp5, tmp8, tmp10)
    tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype)
    tmp13 = tl.where(tmp4, tmp11, tmp12)
    tmp14 = tmp0 >= tmp3
    tmp15 = tl.full([1], 4, tl.int64)
    tmp16 = tmp0 < tmp15
    tmp17 = tmp14 & tmp16
    tmp18 = tl.load(in_ptr3 + (x0 + 4096 * (-2 + x1) + 8192 * x2), tmp17,
        other=0.0).to(tl.int1)
    tmp19 = tl.load(in_ptr4 + (x0 + 4096 * (-2 + x1) + 8192 * x2), tmp17,
        other=0.0)
    tmp20 = tl.load(in_ptr5 + (-2 + x1), tmp17, eviction_policy=
        'evict_last', other=0.0)
    tmp21 = tmp19 + tmp20
    tmp22 = tmp21 * tmp9
    tmp23 = tl.where(tmp18, tmp21, tmp22)
    tmp24 = tl.full(tmp23.shape, 0.0, tmp23.dtype)
    tmp25 = tl.where(tmp17, tmp23, tmp24)
    tmp26 = tmp0 >= tmp15
    tl.full([1], 6, tl.int64)
    tmp29 = tl.load(in_ptr6 + (x0 + 4096 * (-4 + x1) + 8192 * x2), tmp26,
        other=0.0).to(tl.int1)
    tmp30 = tl.load(in_ptr7 + (x0 + 4096 * (-4 + x1) + 8192 * x2), tmp26,
        other=0.0)
    tmp31 = tl.load(in_ptr8 + (-4 + x1), tmp26, eviction_policy=
        'evict_last', other=0.0)
    tmp32 = tmp30 + tmp31
    tmp33 = tmp32 * tmp9
    tmp34 = tl.where(tmp29, tmp32, tmp33)
    tmp35 = tl.full(tmp34.shape, 0.0, tmp34.dtype)
    tmp36 = tl.where(tmp26, tmp34, tmp35)
    tmp37 = tl.where(tmp17, tmp25, tmp36)
    tmp38 = tl.where(tmp4, tmp13, tmp37)
    tl.store(out_ptr0 + x3, tmp38, None)


@triton.jit
def triton_poi_fused_convolution_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x1 = xindex // 4096 % 4
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tl.store(in_out_ptr0 + x3, tmp2, None)


@triton.jit
def triton_poi_fused_convolution_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x0 = xindex
    tmp0 = tl.load(in_out_ptr0 + x0, None)
    tmp1 = tl.load(in_ptr0 + 0)
    tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
    tmp3 = tmp0 + tmp2
    tl.store(in_out_ptr0 + x0, tmp3, None)


@triton.jit
def triton_poi_fused_convolution_5(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 3844
    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_convolution_relu_6(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 324
    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
    tmp4 = tl.full([1], 0, tl.int32)
    tmp5 = triton_helpers.maximum(tmp4, tmp3)
    tl.store(in_out_ptr0 + x0, tmp5, xmask)


@triton.jit
def triton_poi_fused__to_copy_7(out_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 = x0
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 0.5
    tmp3 = tmp1 + tmp2
    tmp4 = 0.140625
    tmp5 = tmp3 * tmp4
    tmp6 = tmp5 - tmp2
    tmp7 = 0.0
    tmp8 = triton_helpers.maximum(tmp6, tmp7)
    tmp9 = tmp8.to(tl.int32)
    tl.store(out_ptr0 + x0, tmp9, xmask)


@triton.jit
def triton_poi_fused_add_clamp_8(out_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 = x0
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 0.5
    tmp3 = tmp1 + tmp2
    tmp4 = 0.140625
    tmp5 = tmp3 * tmp4
    tmp6 = tmp5 - tmp2
    tmp7 = 0.0
    tmp8 = triton_helpers.maximum(tmp6, tmp7)
    tmp9 = tmp8.to(tl.int32)
    tmp10 = tl.full([1], 1, tl.int64)
    tmp11 = tmp9 + tmp10
    tmp12 = tl.full([1], 8, tl.int64)
    tmp13 = triton_helpers.minimum(tmp11, tmp12)
    tl.store(out_ptr0 + x0, tmp13, xmask)


@triton.jit
def triton_poi_fused__to_copy_add_arange_clamp_mul_sub_9(out_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 = x0
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 0.5
    tmp3 = tmp1 + tmp2
    tmp4 = 0.140625
    tmp5 = tmp3 * tmp4
    tmp6 = tmp5 - tmp2
    tmp7 = 0.0
    tmp8 = triton_helpers.maximum(tmp6, tmp7)
    tmp9 = tmp8.to(tl.int32)
    tmp10 = tmp9.to(tl.float32)
    tmp11 = tmp8 - tmp10
    tmp12 = triton_helpers.maximum(tmp11, tmp7)
    tmp13 = 1.0
    tmp14 = triton_helpers.minimum(tmp12, tmp13)
    tl.store(out_ptr0 + x0, tmp14, xmask)


@triton.jit
def triton_poi_fused__unsafe_index_add_convolution_mul_sub_10(in_out_ptr0,
    in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7,
    in_ptr8, in_ptr9, xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x1 = xindex // 64 % 64
    x0 = xindex % 64
    x2 = xindex // 4096
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr3 + 0)
    tmp11 = tl.broadcast_to(tmp10, [XBLOCK])
    tmp13 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
    tmp20 = tl.load(in_ptr5 + x0, None, eviction_policy='evict_last')
    tmp23 = tl.load(in_ptr6 + x1, None, eviction_policy='evict_last')
    tmp35 = tl.load(in_ptr7 + x1, None, eviction_policy='evict_last')
    tmp38 = tl.load(in_ptr8 + x3, None)
    tmp39 = tl.load(in_ptr9 + 0)
    tmp40 = tl.broadcast_to(tmp39, [XBLOCK])
    tmp1 = tl.full([XBLOCK], 9, tl.int32)
    tmp2 = tmp0 + tmp1
    tmp3 = tmp0 < 0
    tmp4 = tl.where(tmp3, tmp2, tmp0)
    tmp6 = tmp5 + tmp1
    tmp7 = tmp5 < 0
    tmp8 = tl.where(tmp7, tmp6, tmp5)
    tmp9 = tl.load(in_ptr2 + (tmp8 + 9 * tmp4 + 81 * x2), None,
        eviction_policy='evict_last')
    tmp12 = tmp9 + tmp11
    tmp14 = tmp13 + tmp1
    tmp15 = tmp13 < 0
    tmp16 = tl.where(tmp15, tmp14, tmp13)
    tmp17 = tl.load(in_ptr2 + (tmp16 + 9 * tmp4 + 81 * x2), None,
        eviction_policy='evict_last')
    tmp18 = tmp17 + tmp11
    tmp19 = tmp18 - tmp12
    tmp21 = tmp19 * tmp20
    tmp22 = tmp12 + tmp21
    tmp24 = tmp23 + tmp1
    tmp25 = tmp23 < 0
    tmp26 = tl.where(tmp25, tmp24, tmp23)
    tmp27 = tl.load(in_ptr2 + (tmp8 + 9 * tmp26 + 81 * x2), None,
        eviction_policy='evict_last')
    tmp28 = tmp27 + tmp11
    tmp29 = tl.load(in_ptr2 + (tmp16 + 9 * tmp26 + 81 * x2), None,
        eviction_policy='evict_last')
    tmp30 = tmp29 + tmp11
    tmp31 = tmp30 - tmp28
    tmp32 = tmp31 * tmp20
    tmp33 = tmp28 + tmp32
    tmp34 = tmp33 - tmp22
    tmp36 = tmp34 * tmp35
    tmp37 = tmp22 + tmp36
    tmp41 = tmp38 + tmp40
    tmp42 = tmp37 + tmp41
    tl.store(in_out_ptr0 + x3, tmp42, None)


@triton.jit
def triton_poi_fused_convolution_mul_sigmoid_11(in_out_ptr0, in_ptr0,
    in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    tl.full([XBLOCK], True, tl.int1)
    x3 = xindex
    x1 = xindex // 4096 % 4
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr1 + x3, None)
    tmp2 = tmp0 + tmp1
    tmp4 = tl.sigmoid(tmp2)
    tmp5 = tmp3 * tmp4
    tl.store(in_out_ptr0 + x3, tmp2, None)
    tl.store(out_ptr0 + x3, tmp5, None)


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, primals_27) = args
    args.clear()
    assert_size_stride(primals_1, (2, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_2, (2,), (1,))
    assert_size_stride(primals_3, (4, 4, 64, 64), (16384, 4096, 64, 1))
    assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_5, (4,), (1,))
    assert_size_stride(primals_6, (2, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_7, (2,), (1,))
    assert_size_stride(primals_8, (4, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_9, (4,), (1,))
    assert_size_stride(primals_10, (2, 4, 3, 3), (36, 9, 3, 1))
    assert_size_stride(primals_11, (2,), (1,))
    assert_size_stride(primals_12, (4, 6, 1, 1), (6, 1, 1, 1))
    assert_size_stride(primals_13, (4,), (1,))
    assert_size_stride(primals_14, (1, 4, 1, 1), (4, 1, 1, 1))
    assert_size_stride(primals_15, (1,), (1,))
    assert_size_stride(primals_16, (1, 1, 3, 3), (9, 9, 3, 1))
    assert_size_stride(primals_17, (1,), (1,))
    assert_size_stride(primals_18, (1, 1, 3, 3), (9, 9, 3, 1))
    assert_size_stride(primals_19, (1,), (1,))
    assert_size_stride(primals_20, (1, 1, 3, 3), (9, 9, 3, 1))
    assert_size_stride(primals_21, (1,), (1,))
    assert_size_stride(primals_22, (1, 1, 3, 3), (9, 9, 3, 1))
    assert_size_stride(primals_23, (1,), (1,))
    assert_size_stride(primals_24, (1, 1, 1, 1), (1, 1, 1, 1))
    assert_size_stride(primals_25, (1,), (1,))
    assert_size_stride(primals_26, (4, 1, 1, 1), (1, 1, 1, 1))
    assert_size_stride(primals_27, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 
            1), padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf0, (4, 2, 64, 64), (8192, 4096, 64, 1))
        buf1 = empty_strided_cuda((4, 2, 64, 64), (8192, 4096, 64, 1),
            torch.bool)
        get_raw_stream(0)
        triton_poi_fused_convolution_leaky_relu_0[grid(32768)](buf0,
            primals_2, buf1, 32768, XBLOCK=128, num_warps=4, num_stages=1)
        buf2 = extern_kernels.convolution(primals_3, primals_4, stride=(1, 
            1), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf2, (4, 4, 64, 64), (16384, 4096, 64, 1))
        buf3 = empty_strided_cuda((4, 4, 64, 64), (16384, 4096, 64, 1),
            torch.bool)
        buf4 = empty_strided_cuda((4, 4, 64, 64), (16384, 4096, 64, 1),
            torch.float32)
        triton_poi_fused_add_convolution_leaky_relu_1[grid(65536)](buf2,
            primals_5, primals_3, buf3, buf4, 65536, XBLOCK=512, num_warps=
            4, num_stages=1)
        del primals_5
        buf5 = extern_kernels.convolution(buf4, primals_6, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf5, (4, 2, 64, 64), (8192, 4096, 64, 1))
        buf6 = empty_strided_cuda((4, 2, 64, 64), (8192, 4096, 64, 1),
            torch.bool)
        triton_poi_fused_convolution_leaky_relu_0[grid(32768)](buf5,
            primals_7, buf6, 32768, XBLOCK=128, num_warps=4, num_stages=1)
        buf7 = extern_kernels.convolution(buf4, primals_8, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf7, (4, 4, 64, 64), (16384, 4096, 64, 1))
        buf8 = empty_strided_cuda((4, 4, 64, 64), (16384, 4096, 64, 1),
            torch.bool)
        buf9 = buf2
        del buf2
        triton_poi_fused_add_convolution_leaky_relu_1[grid(65536)](buf7,
            primals_9, buf4, buf8, buf9, 65536, XBLOCK=512, num_warps=4,
            num_stages=1)
        del primals_9
        buf10 = extern_kernels.convolution(buf9, primals_10, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf10, (4, 2, 64, 64), (8192, 4096, 64, 1))
        buf11 = empty_strided_cuda((4, 2, 64, 64), (8192, 4096, 64, 1),
            torch.bool)
        triton_poi_fused_convolution_leaky_relu_0[grid(32768)](buf10,
            primals_11, buf11, 32768, XBLOCK=128, num_warps=4, num_stages=1)
        buf12 = empty_strided_cuda((4, 6, 64, 64), (24576, 4096, 64, 1),
            torch.float32)
        triton_poi_fused_cat_2[grid(98304)](buf1, buf0, primals_2, buf6,
            buf5, primals_7, buf11, buf10, primals_11, buf12, 98304, XBLOCK
            =512, num_warps=8, num_stages=1)
        del buf0
        del buf10
        del buf5
        del primals_11
        del primals_2
        del primals_7
        buf13 = extern_kernels.convolution(buf12, primals_12, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf13, (4, 4, 64, 64), (16384, 4096, 64, 1))
        buf14 = buf13
        del buf13
        triton_poi_fused_convolution_3[grid(65536)](buf14, primals_13, 
            65536, XBLOCK=512, num_warps=4, num_stages=1)
        del primals_13
        buf15 = extern_kernels.convolution(buf14, primals_14, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf15, (4, 1, 64, 64), (4096, 4096, 64, 1))
        buf16 = buf15
        del buf15
        triton_poi_fused_convolution_4[grid(16384)](buf16, primals_15, 
            16384, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_15
        buf17 = extern_kernels.convolution(buf16, primals_16, stride=(2, 2),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf17, (4, 1, 31, 31), (961, 961, 31, 1))
        buf18 = buf17
        del buf17
        triton_poi_fused_convolution_5[grid(3844)](buf18, primals_17, 3844,
            XBLOCK=256, num_warps=4, num_stages=1)
        del primals_17
        buf19 = torch.ops.aten.max_pool2d_with_indices.default(buf18, [7, 7
            ], [3, 3])
        buf20 = buf19[0]
        buf21 = buf19[1]
        del buf19
        buf22 = extern_kernels.convolution(buf20, primals_18, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf22, (4, 1, 9, 9), (81, 81, 9, 1))
        buf23 = buf22
        del buf22
        triton_poi_fused_convolution_relu_6[grid(324)](buf23, primals_19, 
            324, XBLOCK=128, num_warps=4, num_stages=1)
        del primals_19
        buf24 = extern_kernels.convolution(buf23, primals_20, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf24, (4, 1, 9, 9), (81, 81, 9, 1))
        buf25 = buf24
        del buf24
        triton_poi_fused_convolution_relu_6[grid(324)](buf25, primals_21, 
            324, XBLOCK=128, num_warps=4, num_stages=1)
        del primals_21
        buf26 = extern_kernels.convolution(buf25, primals_22, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf26, (4, 1, 9, 9), (81, 81, 9, 1))
        buf27 = empty_strided_cuda((64, 1), (1, 1), torch.int64)
        triton_poi_fused__to_copy_7[grid(64)](buf27, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf28 = empty_strided_cuda((64, 1), (1, 1), torch.int64)
        triton_poi_fused_add_clamp_8[grid(64)](buf28, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf29 = empty_strided_cuda((64,), (1,), torch.int64)
        triton_poi_fused__to_copy_7[grid(64)](buf29, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf30 = empty_strided_cuda((64,), (1,), torch.int64)
        triton_poi_fused_add_clamp_8[grid(64)](buf30, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf31 = empty_strided_cuda((64,), (1,), torch.float32)
        triton_poi_fused__to_copy_add_arange_clamp_mul_sub_9[grid(64)](buf31,
            64, XBLOCK=64, num_warps=1, num_stages=1)
        buf33 = empty_strided_cuda((64, 1), (1, 1), torch.float32)
        triton_poi_fused__to_copy_add_arange_clamp_mul_sub_9[grid(64)](buf33,
            64, XBLOCK=64, num_warps=1, num_stages=1)
        buf35 = extern_kernels.convolution(buf16, primals_24, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf35, (4, 1, 64, 64), (4096, 4096, 64, 1))
        buf34 = empty_strided_cuda((4, 1, 64, 64), (4096, 16384, 64, 1),
            torch.float32)
        buf36 = reinterpret_tensor(buf34, (4, 1, 64, 64), (4096, 4096, 64, 
            1), 0)
        del buf34
        triton_poi_fused__unsafe_index_add_convolution_mul_sub_10[grid(16384)](
            buf36, buf27, buf29, buf26, primals_23, buf30, buf31, buf28,
            buf33, buf35, primals_25, 16384, XBLOCK=256, num_warps=4,
            num_stages=1)
        del buf26
        del buf35
        del primals_23
        del primals_25
        buf37 = extern_kernels.convolution(buf36, primals_26, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf37, (4, 4, 64, 64), (16384, 4096, 64, 1))
        buf38 = buf37
        del buf37
        buf39 = buf7
        del buf7
        triton_poi_fused_convolution_mul_sigmoid_11[grid(65536)](buf38,
            primals_27, buf14, buf39, 65536, XBLOCK=256, num_warps=4,
            num_stages=1)
        del primals_27
    return (buf39, primals_1, primals_3, primals_4, primals_6, primals_8,
        primals_10, primals_12, primals_14, primals_16, primals_18,
        primals_20, primals_22, primals_24, primals_26, buf1, buf3, buf4,
        buf6, buf8, buf9, buf11, buf12, buf14, buf16, buf18, buf20, buf21,
        buf23, buf25, buf27, buf28, buf29, buf30, buf31, buf33, buf36, buf38)


def activation(act_type, inplace=True, neg_slope=0.05, n_prelu=1):
    act_type = act_type.lower()
    if act_type == 'relu':
        layer = nn.ReLU(inplace)
    elif act_type == 'lrelu':
        layer = nn.LeakyReLU(neg_slope, False)
    elif act_type == 'prelu':
        layer = nn.PReLU(num_parameters=n_prelu, init=neg_slope)
    else:
        raise NotImplementedError('activation layer [{:s}] is not found'.
            format(act_type))
    return layer


def conv_layer(in_channels, out_channels, kernel_size, stride=1, dilation=1,
    groups=1):
    padding = int((kernel_size - 1) / 2) * dilation
    return nn.Conv2d(in_channels, out_channels, kernel_size, stride,
        padding=padding, bias=True, dilation=dilation, groups=groups)


class ESA(nn.Module):

    def __init__(self, n_feats, conv):
        super(ESA, self).__init__()
        f = n_feats // 4
        self.conv1 = conv(n_feats, f, kernel_size=1)
        self.conv_f = conv(f, f, kernel_size=1)
        self.conv_max = conv(f, f, kernel_size=3, padding=1)
        self.conv2 = conv(f, f, kernel_size=3, stride=2, padding=0)
        self.conv3 = conv(f, f, kernel_size=3, padding=1)
        self.conv3_ = conv(f, f, kernel_size=3, padding=1)
        self.conv4 = conv(f, n_feats, kernel_size=1)
        self.sigmoid = nn.Sigmoid()
        self.relu = nn.ReLU(inplace=True)
        self.skip_add = torch.nn.quantized.FloatFunctional()

    def forward(self, x):
        c1_ = self.conv1(x)
        c1 = self.conv2(c1_)
        v_max = F.max_pool2d(c1, kernel_size=7, stride=3)
        v_range = self.relu(self.conv_max(v_max))
        c3 = self.relu(self.conv3(v_range))
        c3 = self.conv3_(c3)
        c3 = F.interpolate(c3, (x.size(2), x.size(3)), mode='bilinear',
            align_corners=False)
        cf = self.conv_f(c1_)
        c4 = self.conv4(self.skip_add.add(c3, cf))
        m = self.sigmoid(c4)
        return self.skip_add.mul(x, m)


class RFDBsmallNew(nn.Module):

    def __init__(self, in_channels, distillation_rate=0.25):
        super(RFDBsmallNew, self).__init__()
        self.dc = self.distilled_channels = in_channels // 2
        self.rc = self.remaining_channels = in_channels
        self.c1_d = conv_layer(in_channels, self.dc, 1)
        self.c1_r = conv_layer(in_channels, self.rc, 3)
        self.c2_d = conv_layer(self.remaining_channels, self.dc, 1)
        self.c2_r = conv_layer(self.remaining_channels, self.rc, 3)
        self.c3 = conv_layer(self.remaining_channels, self.dc, 3)
        self.act = activation('lrelu', neg_slope=0.05)
        self.c4 = conv_layer(self.dc * 3, in_channels, 1)
        self.esa = ESA(in_channels, nn.Conv2d)
        self.skip_add = torch.nn.quantized.FloatFunctional()

    def forward(self, input_0):
        primals_1 = self.c1_d.weight
        primals_2 = self.c1_d.bias
        primals_4 = self.c1_r.weight
        primals_5 = self.c1_r.bias
        primals_6 = self.c2_d.weight
        primals_7 = self.c2_d.bias
        primals_8 = self.c2_r.weight
        primals_9 = self.c2_r.bias
        primals_10 = self.c3.weight
        primals_11 = self.c3.bias
        primals_12 = self.c4.weight
        primals_13 = self.c4.bias
        primals_14 = self.esa.conv1.weight
        primals_15 = self.esa.conv1.bias
        primals_24 = self.esa.conv_f.weight
        primals_17 = self.esa.conv_f.bias
        primals_16 = self.esa.conv_max.weight
        primals_19 = self.esa.conv_max.bias
        primals_18 = self.esa.conv2.weight
        primals_21 = self.esa.conv2.bias
        primals_20 = self.esa.conv3.weight
        primals_23 = self.esa.conv3.bias
        primals_22 = self.esa.conv3_.weight
        primals_25 = self.esa.conv3_.bias
        primals_26 = self.esa.conv4.weight
        primals_27 = self.esa.conv4.bias
        primals_3 = 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,
            primals_20, primals_21, primals_22, primals_23, primals_24,
            primals_25, primals_26, primals_27])
        return output[0]
