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 math as tl_math
import torch._C
import torch.serialization
from torch import nn
from torch.nn import init
from torch.nn import Parameter
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__softmax_0(in_ptr0, 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
    x0 = xindex % 16
    x2 = xindex // 64
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp3 = triton_helpers.maximum(tmp1, tmp2)
    tmp5 = triton_helpers.maximum(tmp3, tmp4)
    tmp7 = triton_helpers.maximum(tmp5, tmp6)
    tmp8 = tmp0 - tmp7
    tmp9 = tl_math.exp(tmp8)
    tl.store(out_ptr0 + x3, tmp9, xmask)


@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, 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
    x0 = xindex % 16
    x2 = xindex // 64
    tmp0 = tl.load(in_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
        'evict_last')
    tmp3 = tmp1 + tmp2
    tmp5 = tmp3 + tmp4
    tmp7 = tmp5 + tmp6
    tmp8 = tmp0 / tmp7
    tl.store(out_ptr0 + x3, tmp8, xmask)


@triton.jit
def triton_poi_fused_div_exp_neg_pow_sub_2(in_out_ptr0, in_out_ptr1,
    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
    x0 = xindex % 16
    x2 = xindex // 128
    tmp0 = tl.load(in_out_ptr0 + x3, None)
    tmp1 = tl.load(in_ptr0 + (x0 + 16 * x2), None, eviction_policy='evict_last'
        )
    tmp8 = tl.load(in_out_ptr1 + x3, None)
    tmp2 = tmp0 - tmp1
    tmp3 = tmp2 * tmp2
    tmp4 = 0.2222222222222222
    tmp5 = tmp3 * tmp4
    tmp6 = -tmp5
    tmp7 = tl_math.exp(tmp6)
    tmp9 = tmp8 - tmp1
    tmp10 = tmp9 * tmp9
    tmp11 = 0.08
    tmp12 = tmp10 * tmp11
    tmp13 = -tmp12
    tmp14 = tl_math.exp(tmp13)
    tl.store(in_out_ptr0 + x3, tmp7, None)
    tl.store(in_out_ptr1 + x3, tmp14, None)


@triton.jit
def triton_per_fused_mul_sum_3(in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel,
    XBLOCK: tl.constexpr):
    xnumel = 256
    RBLOCK: tl.constexpr = 8
    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
    x0 = xindex % 16
    x1 = xindex // 16
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 16 * r2 + 128 * x1), xmask, other=0.0)
    tmp1 = tl.load(in_ptr1 + r2, None, eviction_policy='evict_last')
    tmp2 = tmp0 * tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.where(xmask, tmp3, 0)
    tmp6 = tl.sum(tmp5, 1)[:, None]
    tl.store(out_ptr0 + x3, tmp6, xmask)


@triton.jit
def triton_per_fused_div_mul_sum_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
    out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 1024
    RBLOCK: tl.constexpr = 8
    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)
    r4 = rindex
    x0 = xindex % 16
    x5 = xindex // 64
    x1 = xindex // 16 % 4
    x3 = xindex // 256
    x2 = xindex // 64 % 4
    x7 = xindex % 64
    tmp0 = tl.load(in_ptr0 + (x0 + 16 * r4 + 128 * x5), xmask,
        eviction_policy='evict_last', other=0.0)
    tmp1 = tl.load(in_ptr1 + (x0 + 16 * r4 + 128 * x1 + 512 * x3), xmask,
        eviction_policy='evict_last', other=0.0)
    tmp3 = tl.load(in_ptr2 + r4, None, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr3 + (x0 + 16 * x5), xmask, eviction_policy=
        'evict_last')
    tmp2 = tmp0 * tmp1
    tmp4 = tmp2 * tmp3
    tmp5 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK])
    tmp7 = tl.where(xmask, tmp5, 0)
    tmp8 = tl.sum(tmp7, 1)[:, None]
    tmp10 = tmp8 / tmp9
    tl.store(out_ptr1 + (x2 + 9 * x7 + 576 * x3), tmp10, xmask)


@triton.jit
def triton_per_fused_div_mul_sum_5(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
    out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr):
    xnumel = 1024
    RBLOCK: tl.constexpr = 8
    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)
    r4 = rindex
    x0 = xindex % 16
    x5 = xindex // 64
    x1 = xindex // 16 % 4
    x3 = xindex // 256
    x2 = xindex // 64 % 4
    x7 = xindex % 64
    tmp0 = tl.load(in_ptr0 + (x0 + 16 * r4 + 128 * x5), xmask,
        eviction_policy='evict_last', other=0.0)
    tmp1 = tl.load(in_ptr1 + (x0 + 16 * r4 + 128 * x1 + 512 * x3), xmask,
        eviction_policy='evict_last', other=0.0)
    tmp3 = tl.load(in_ptr2 + r4, None, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr3 + (x0 + 16 * x5), xmask, eviction_policy=
        'evict_last')
    tmp2 = tmp0 * tmp1
    tmp4 = tmp2 * tmp3
    tmp5 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK])
    tmp7 = tl.where(xmask, tmp5, 0)
    tmp8 = tl.sum(tmp7, 1)[:, None]
    tmp10 = tmp8 / tmp9
    tl.store(out_ptr1 + (x2 + 9 * x7 + 576 * x3), tmp10, xmask)


@triton.jit
def triton_poi_fused_convolution_new_ones_6(out_ptr0, xnumel, XBLOCK: tl.
    constexpr):
    xnumel = 256
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = 1.0
    tl.store(out_ptr0 + x0, tmp0, xmask)


@triton.jit
def triton_poi_fused_cat_7(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
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + x0, xmask)
    tmp1 = tl.load(in_ptr1 + x0, xmask)
    tmp2 = tmp0 / tmp1
    tl.store(out_ptr0 + 9 * x0, tmp2, xmask)


@triton.jit
def triton_poi_fused_cat_8(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    ynumel = 36
    xnumel = 64
    yoffset = tl.program_id(1) * YBLOCK
    yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
    ymask = yindex < ynumel
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
    xmask = xindex < xnumel
    x2 = xindex
    y0 = yindex % 9
    y1 = yindex // 9
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 9 * x2 + 576 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tl.store(out_ptr0 + (x2 + 64 * y3), tmp0, xmask & ymask)


@triton.jit
def triton_per_fused_mul_sum_9(in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel,
    XBLOCK: tl.constexpr):
    xnumel = 256
    rnumel = 9
    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, :]
    rmask = rindex < rnumel
    r3 = rindex
    x2 = xindex // 64
    x4 = xindex % 64
    x1 = xindex // 16 % 4
    x5 = xindex
    tmp0 = tl.load(in_ptr0 + (x4 + 64 * r3 + 576 * x2), rmask & xmask,
        other=0.0)
    tmp1 = tl.load(in_ptr1 + (x1 + 4 * r3), rmask & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp2 = tmp0 * tmp1
    tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
    tmp5 = tl.where(rmask & xmask, tmp3, 0)
    tmp6 = tl.sum(tmp5, 1)[:, None]
    tl.store(out_ptr0 + x5, tmp6, xmask)


@triton.jit
def triton_poi_fused_diagonal_copy_10(in_ptr0, out_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 5 * x0, xmask, eviction_policy='evict_last')
    tl.store(out_ptr0 + x0, tmp0, xmask)


@triton.jit
def triton_poi_fused__softmax_mul_sub_11(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
    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 % 16
    x1 = xindex // 16
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask)
    tmp1 = tl.load(in_ptr1 + (x0 + 64 * x1), xmask)
    tmp2 = tl.load(in_ptr2 + (x0 + 64 * x1), xmask)
    tmp3 = tl.load(in_ptr3 + 0)
    tmp4 = tl.broadcast_to(tmp3, [XBLOCK])
    tmp8 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask)
    tmp9 = tl.load(in_ptr1 + (16 + x0 + 64 * x1), xmask)
    tmp10 = tl.load(in_ptr2 + (16 + x0 + 64 * x1), xmask)
    tmp11 = tl.load(in_ptr3 + 1)
    tmp12 = tl.broadcast_to(tmp11, [XBLOCK])
    tmp17 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask)
    tmp18 = tl.load(in_ptr1 + (32 + x0 + 64 * x1), xmask)
    tmp19 = tl.load(in_ptr2 + (32 + x0 + 64 * x1), xmask)
    tmp20 = tl.load(in_ptr3 + 2)
    tmp21 = tl.broadcast_to(tmp20, [XBLOCK])
    tmp26 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask)
    tmp27 = tl.load(in_ptr1 + (48 + x0 + 64 * x1), xmask)
    tmp28 = tl.load(in_ptr2 + (48 + x0 + 64 * x1), xmask)
    tmp29 = tl.load(in_ptr3 + 3)
    tmp30 = tl.broadcast_to(tmp29, [XBLOCK])
    tmp5 = tmp2 * tmp4
    tmp6 = tmp1 - tmp5
    tmp7 = tmp0 - tmp6
    tmp13 = tmp10 * tmp12
    tmp14 = tmp9 - tmp13
    tmp15 = tmp8 - tmp14
    tmp16 = triton_helpers.maximum(tmp7, tmp15)
    tmp22 = tmp19 * tmp21
    tmp23 = tmp18 - tmp22
    tmp24 = tmp17 - tmp23
    tmp25 = triton_helpers.maximum(tmp16, tmp24)
    tmp31 = tmp28 * tmp30
    tmp32 = tmp27 - tmp31
    tmp33 = tmp26 - tmp32
    tmp34 = triton_helpers.maximum(tmp25, tmp33)
    tl.store(out_ptr0 + x2, tmp34, xmask)


@triton.jit
def triton_poi_fused__softmax_mul_sub_12(in_out_ptr0, in_ptr0, in_ptr1,
    in_ptr2, in_ptr3, 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_ptr0 + x3, xmask)
    tmp1 = tl.load(in_out_ptr0 + x3, xmask)
    tmp2 = tl.load(in_ptr1 + x3, xmask)
    tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr3 + (x0 + 16 * x2), xmask, eviction_policy=
        'evict_last')
    tmp4 = tmp2 * tmp3
    tmp5 = tmp1 - tmp4
    tmp6 = tmp0 - tmp5
    tmp8 = tmp6 - tmp7
    tmp9 = tl_math.exp(tmp8)
    tl.store(in_out_ptr0 + x3, tmp9, xmask)


@triton.jit
def triton_poi_fused_mul_sub_13(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2,
    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_out_ptr0 + x3, xmask)
    tmp2 = tl.load(in_ptr1 + x3, xmask)
    tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp4 = tmp2 * tmp3
    tmp5 = tmp1 - tmp4
    tmp6 = tmp0 - tmp5
    tl.store(in_out_ptr0 + x3, tmp6, 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) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_3, (32, 1, 3, 3), (9, 9, 3, 1))
    assert_size_stride(primals_4, (32, 1, 3, 3), (9, 9, 3, 1))
    assert_size_stride(primals_5, (1, 1, 1, 8, 1, 1), (8, 8, 8, 1, 1, 1))
    assert_size_stride(primals_6, (32, 1, 3, 3), (9, 9, 3, 1))
    assert_size_stride(primals_7, (32, 1, 3, 3), (9, 9, 3, 1))
    assert_size_stride(primals_8, (1, 1, 1, 8, 1, 1), (8, 8, 8, 1, 1, 1))
    assert_size_stride(primals_9, (4, 1, 3, 3), (9, 9, 3, 1))
    assert_size_stride(primals_10, (1, 9, 4, 1, 1), (36, 4, 1, 1, 1))
    assert_size_stride(primals_11, (4, 4, 1, 1), (4, 1, 1, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused__softmax_0[grid(256)](primals_1, buf0, 256, XBLOCK
            =128, num_warps=4, num_stages=1)
        buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused__softmax_1[grid(256)](buf0, buf1, 256, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf2 = extern_kernels.convolution(primals_2, primals_3, stride=(1, 
            1), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf2, (4, 32, 4, 4), (512, 16, 4, 1))
        del primals_3
        buf3 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf3, (4, 32, 4, 4), (512, 16, 4, 1))
        buf7 = extern_kernels.convolution(primals_2, primals_6, stride=(1, 
            1), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf7, (4, 32, 4, 4), (512, 16, 4, 1))
        del primals_6
        buf4 = reinterpret_tensor(buf2, (4, 4, 8, 4, 4), (512, 128, 16, 4, 
            1), 0)
        del buf2
        buf9 = reinterpret_tensor(buf7, (4, 4, 8, 4, 4), (512, 128, 16, 4, 
            1), 0)
        del buf7
        triton_poi_fused_div_exp_neg_pow_sub_2[grid(2048)](buf4, buf9,
            primals_2, 2048, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_2
        buf6 = buf0
        del buf0
        triton_per_fused_mul_sum_3[grid(256)](buf4, primals_5, buf6, 256, 8,
            XBLOCK=8, num_warps=2, num_stages=1)
        buf18 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 1, 144, 36, 9),
            torch.float32)
        buf15 = reinterpret_tensor(buf18, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 0)
        triton_per_fused_div_mul_sum_4[grid(1024)](buf4, buf3, primals_5,
            buf6, buf15, 1024, 8, XBLOCK=8, num_warps=2, num_stages=1)
        del buf3
        buf8 = extern_kernels.convolution(buf1, primals_7, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf8, (4, 32, 4, 4), (512, 16, 4, 1))
        buf11 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_per_fused_mul_sum_3[grid(256)](buf9, primals_8, buf11, 256, 
            8, XBLOCK=8, num_warps=2, num_stages=1)
        buf16 = reinterpret_tensor(buf18, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 4)
        triton_per_fused_div_mul_sum_5[grid(1024)](buf9, buf8, primals_8,
            buf11, buf16, 1024, 8, XBLOCK=32, num_warps=2, num_stages=1)
        del buf8
        buf12 = extern_kernels.convolution(buf1, primals_9, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf12, (4, 4, 4, 4), (64, 16, 4, 1))
        buf13 = buf1
        del buf1
        triton_poi_fused_convolution_new_ones_6[grid(256)](buf13, 256,
            XBLOCK=256, num_warps=4, num_stages=1)
        buf14 = extern_kernels.convolution(buf13, primals_9, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf14, (4, 4, 4, 4), (64, 16, 4, 1))
        buf17 = reinterpret_tensor(buf18, (4, 1, 4, 4, 4), (576, 1, 144, 36,
            9), 8)
        triton_poi_fused_cat_7[grid(256)](buf12, buf14, buf17, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf19 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1),
            torch.float32)
        triton_poi_fused_cat_8[grid(36, 64)](buf18, buf19, 36, 64, XBLOCK=
            32, YBLOCK=32, num_warps=4, num_stages=1)
        del buf15
        del buf16
        del buf17
        buf20 = buf12
        del buf12
        triton_per_fused_mul_sum_9[grid(256)](buf19, primals_10, buf20, 256,
            9, XBLOCK=1, num_warps=2, num_stages=1)
        buf21 = extern_kernels.convolution(buf20, primals_11, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf21, (4, 4, 4, 4), (64, 16, 4, 1))
        buf22 = empty_strided_cuda((4,), (1,), torch.float32)
        triton_poi_fused_diagonal_copy_10[grid(4)](primals_11, buf22, 4,
            XBLOCK=4, num_warps=1, num_stages=1)
        buf23 = empty_strided_cuda((4, 1, 4, 4), (16, 64, 4, 1), torch.float32)
        triton_poi_fused__softmax_mul_sub_11[grid(64)](primals_1, buf21,
            buf20, buf22, buf23, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf24 = buf21
        del buf21
        triton_poi_fused__softmax_mul_sub_12[grid(256)](buf24, primals_1,
            buf20, buf22, buf23, 256, XBLOCK=256, num_warps=4, num_stages=1)
        buf25 = buf13
        del buf13
        triton_poi_fused__softmax_1[grid(256)](buf24, buf25, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf26 = extern_kernels.convolution(buf25, primals_4, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf26, (4, 32, 4, 4), (512, 16, 4, 1))
        buf34 = buf18
        del buf18
        buf31 = reinterpret_tensor(buf34, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 0)
        triton_per_fused_div_mul_sum_4[grid(1024)](buf4, buf26, primals_5,
            buf6, buf31, 1024, 8, XBLOCK=8, num_warps=2, num_stages=1)
        del buf26
        buf28 = extern_kernels.convolution(buf25, primals_7, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf28, (4, 32, 4, 4), (512, 16, 4, 1))
        buf32 = reinterpret_tensor(buf34, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 4)
        triton_per_fused_div_mul_sum_5[grid(1024)](buf9, buf28, primals_8,
            buf11, buf32, 1024, 8, XBLOCK=32, num_warps=2, num_stages=1)
        del buf28
        buf30 = extern_kernels.convolution(buf25, primals_9, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf30, (4, 4, 4, 4), (64, 16, 4, 1))
        buf33 = reinterpret_tensor(buf34, (4, 1, 4, 4, 4), (576, 1, 144, 36,
            9), 8)
        triton_poi_fused_cat_7[grid(256)](buf30, buf14, buf33, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf35 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1),
            torch.float32)
        triton_poi_fused_cat_8[grid(36, 64)](buf34, buf35, 36, 64, XBLOCK=
            32, YBLOCK=32, num_warps=4, num_stages=1)
        del buf31
        del buf32
        del buf33
        buf36 = buf30
        del buf30
        triton_per_fused_mul_sum_9[grid(256)](buf35, primals_10, buf36, 256,
            9, XBLOCK=1, num_warps=2, num_stages=1)
        buf37 = extern_kernels.convolution(buf36, primals_11, 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, 4, 4), (64, 16, 4, 1))
        buf38 = buf23
        del buf23
        triton_poi_fused__softmax_mul_sub_11[grid(64)](primals_1, buf37,
            buf36, buf22, buf38, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf39 = buf37
        del buf37
        triton_poi_fused__softmax_mul_sub_12[grid(256)](buf39, primals_1,
            buf36, buf22, buf38, 256, XBLOCK=256, num_warps=4, num_stages=1)
        buf40 = buf24
        del buf24
        triton_poi_fused__softmax_1[grid(256)](buf39, buf40, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf41 = extern_kernels.convolution(buf40, primals_4, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf41, (4, 32, 4, 4), (512, 16, 4, 1))
        buf49 = buf34
        del buf34
        buf46 = reinterpret_tensor(buf49, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 0)
        triton_per_fused_div_mul_sum_4[grid(1024)](buf4, buf41, primals_5,
            buf6, buf46, 1024, 8, XBLOCK=8, num_warps=2, num_stages=1)
        del buf41
        buf43 = extern_kernels.convolution(buf40, primals_7, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf43, (4, 32, 4, 4), (512, 16, 4, 1))
        buf47 = reinterpret_tensor(buf49, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 4)
        triton_per_fused_div_mul_sum_5[grid(1024)](buf9, buf43, primals_8,
            buf11, buf47, 1024, 8, XBLOCK=32, num_warps=2, num_stages=1)
        del buf43
        buf45 = extern_kernels.convolution(buf40, primals_9, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf45, (4, 4, 4, 4), (64, 16, 4, 1))
        buf48 = reinterpret_tensor(buf49, (4, 1, 4, 4, 4), (576, 1, 144, 36,
            9), 8)
        triton_poi_fused_cat_7[grid(256)](buf45, buf14, buf48, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf50 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1),
            torch.float32)
        triton_poi_fused_cat_8[grid(36, 64)](buf49, buf50, 36, 64, XBLOCK=
            32, YBLOCK=32, num_warps=4, num_stages=1)
        del buf46
        del buf47
        del buf48
        buf51 = buf45
        del buf45
        triton_per_fused_mul_sum_9[grid(256)](buf50, primals_10, buf51, 256,
            9, XBLOCK=1, num_warps=2, num_stages=1)
        buf52 = extern_kernels.convolution(buf51, primals_11, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf52, (4, 4, 4, 4), (64, 16, 4, 1))
        buf53 = buf38
        del buf38
        triton_poi_fused__softmax_mul_sub_11[grid(64)](primals_1, buf52,
            buf51, buf22, buf53, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf54 = buf52
        del buf52
        triton_poi_fused__softmax_mul_sub_12[grid(256)](buf54, primals_1,
            buf51, buf22, buf53, 256, XBLOCK=256, num_warps=4, num_stages=1)
        buf55 = buf39
        del buf39
        triton_poi_fused__softmax_1[grid(256)](buf54, buf55, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf56 = extern_kernels.convolution(buf55, primals_4, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf56, (4, 32, 4, 4), (512, 16, 4, 1))
        buf64 = buf49
        del buf49
        buf61 = reinterpret_tensor(buf64, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 0)
        triton_per_fused_div_mul_sum_4[grid(1024)](buf4, buf56, primals_5,
            buf6, buf61, 1024, 8, XBLOCK=8, num_warps=2, num_stages=1)
        del buf56
        buf58 = extern_kernels.convolution(buf55, primals_7, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf58, (4, 32, 4, 4), (512, 16, 4, 1))
        buf62 = reinterpret_tensor(buf64, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 4)
        triton_per_fused_div_mul_sum_5[grid(1024)](buf9, buf58, primals_8,
            buf11, buf62, 1024, 8, XBLOCK=32, num_warps=2, num_stages=1)
        del buf58
        buf60 = extern_kernels.convolution(buf55, primals_9, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf60, (4, 4, 4, 4), (64, 16, 4, 1))
        buf63 = reinterpret_tensor(buf64, (4, 1, 4, 4, 4), (576, 1, 144, 36,
            9), 8)
        triton_poi_fused_cat_7[grid(256)](buf60, buf14, buf63, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf65 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1),
            torch.float32)
        triton_poi_fused_cat_8[grid(36, 64)](buf64, buf65, 36, 64, XBLOCK=
            32, YBLOCK=32, num_warps=4, num_stages=1)
        del buf61
        del buf62
        del buf63
        buf66 = buf60
        del buf60
        triton_per_fused_mul_sum_9[grid(256)](buf65, primals_10, buf66, 256,
            9, XBLOCK=1, num_warps=2, num_stages=1)
        buf67 = extern_kernels.convolution(buf66, primals_11, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf67, (4, 4, 4, 4), (64, 16, 4, 1))
        buf68 = buf53
        del buf53
        triton_poi_fused__softmax_mul_sub_11[grid(64)](primals_1, buf67,
            buf66, buf22, buf68, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf69 = buf67
        del buf67
        triton_poi_fused__softmax_mul_sub_12[grid(256)](buf69, primals_1,
            buf66, buf22, buf68, 256, XBLOCK=256, num_warps=4, num_stages=1)
        buf70 = buf54
        del buf54
        triton_poi_fused__softmax_1[grid(256)](buf69, buf70, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf71 = extern_kernels.convolution(buf70, primals_4, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf71, (4, 32, 4, 4), (512, 16, 4, 1))
        buf79 = buf64
        del buf64
        buf76 = reinterpret_tensor(buf79, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 0)
        triton_per_fused_div_mul_sum_4[grid(1024)](buf4, buf71, primals_5,
            buf6, buf76, 1024, 8, XBLOCK=8, num_warps=2, num_stages=1)
        del buf71
        buf73 = extern_kernels.convolution(buf70, primals_7, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf73, (4, 32, 4, 4), (512, 16, 4, 1))
        buf77 = reinterpret_tensor(buf79, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 4)
        triton_per_fused_div_mul_sum_5[grid(1024)](buf9, buf73, primals_8,
            buf11, buf77, 1024, 8, XBLOCK=32, num_warps=2, num_stages=1)
        del buf73
        buf75 = extern_kernels.convolution(buf70, primals_9, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf75, (4, 4, 4, 4), (64, 16, 4, 1))
        buf78 = reinterpret_tensor(buf79, (4, 1, 4, 4, 4), (576, 1, 144, 36,
            9), 8)
        triton_poi_fused_cat_7[grid(256)](buf75, buf14, buf78, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf80 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1),
            torch.float32)
        triton_poi_fused_cat_8[grid(36, 64)](buf79, buf80, 36, 64, XBLOCK=
            32, YBLOCK=32, num_warps=4, num_stages=1)
        del buf76
        del buf77
        del buf78
        buf81 = buf75
        del buf75
        triton_per_fused_mul_sum_9[grid(256)](buf80, primals_10, buf81, 256,
            9, XBLOCK=1, num_warps=2, num_stages=1)
        buf82 = extern_kernels.convolution(buf81, primals_11, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf82, (4, 4, 4, 4), (64, 16, 4, 1))
        buf83 = buf68
        del buf68
        triton_poi_fused__softmax_mul_sub_11[grid(64)](primals_1, buf82,
            buf81, buf22, buf83, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf84 = buf82
        del buf82
        triton_poi_fused__softmax_mul_sub_12[grid(256)](buf84, primals_1,
            buf81, buf22, buf83, 256, XBLOCK=256, num_warps=4, num_stages=1)
        buf85 = buf69
        del buf69
        triton_poi_fused__softmax_1[grid(256)](buf84, buf85, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf86 = extern_kernels.convolution(buf85, primals_4, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf86, (4, 32, 4, 4), (512, 16, 4, 1))
        buf94 = buf79
        del buf79
        buf91 = reinterpret_tensor(buf94, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 0)
        triton_per_fused_div_mul_sum_4[grid(1024)](buf4, buf86, primals_5,
            buf6, buf91, 1024, 8, XBLOCK=8, num_warps=2, num_stages=1)
        del buf86
        buf88 = extern_kernels.convolution(buf85, primals_7, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf88, (4, 32, 4, 4), (512, 16, 4, 1))
        buf92 = reinterpret_tensor(buf94, (4, 4, 4, 4, 4), (576, 1, 144, 36,
            9), 4)
        triton_per_fused_div_mul_sum_5[grid(1024)](buf9, buf88, primals_8,
            buf11, buf92, 1024, 8, XBLOCK=32, num_warps=2, num_stages=1)
        del buf88
        buf90 = extern_kernels.convolution(buf85, primals_9, stride=(1, 1),
            padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf90, (4, 4, 4, 4), (64, 16, 4, 1))
        buf93 = reinterpret_tensor(buf94, (4, 1, 4, 4, 4), (576, 1, 144, 36,
            9), 8)
        triton_poi_fused_cat_7[grid(256)](buf90, buf14, buf93, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf95 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1),
            torch.float32)
        triton_poi_fused_cat_8[grid(36, 64)](buf94, buf95, 36, 64, XBLOCK=
            32, YBLOCK=32, num_warps=4, num_stages=1)
        del buf91
        del buf92
        del buf93
        buf96 = buf90
        del buf90
        triton_per_fused_mul_sum_9[grid(256)](buf95, primals_10, buf96, 256,
            9, XBLOCK=1, num_warps=2, num_stages=1)
        buf97 = extern_kernels.convolution(buf96, primals_11, stride=(1, 1),
            padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf97, (4, 4, 4, 4), (64, 16, 4, 1))
        buf98 = buf83
        del buf83
        triton_poi_fused__softmax_mul_sub_11[grid(64)](primals_1, buf97,
            buf96, buf22, buf98, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf99 = buf97
        del buf97
        triton_poi_fused__softmax_mul_sub_12[grid(256)](buf99, primals_1,
            buf96, buf22, buf98, 256, XBLOCK=256, num_warps=4, num_stages=1)
        buf100 = buf84
        del buf84
        triton_poi_fused__softmax_1[grid(256)](buf99, buf100, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        buf101 = extern_kernels.convolution(buf100, primals_4, stride=(1, 1
            ), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf101, (4, 32, 4, 4), (512, 16, 4, 1))
        buf109 = buf94
        del buf94
        buf106 = reinterpret_tensor(buf109, (4, 4, 4, 4, 4), (576, 1, 144, 
            36, 9), 0)
        triton_per_fused_div_mul_sum_4[grid(1024)](buf4, buf101, primals_5,
            buf6, buf106, 1024, 8, XBLOCK=8, num_warps=2, num_stages=1)
        del buf101
        buf103 = extern_kernels.convolution(buf100, primals_7, stride=(1, 1
            ), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf103, (4, 32, 4, 4), (512, 16, 4, 1))
        buf107 = reinterpret_tensor(buf109, (4, 4, 4, 4, 4), (576, 1, 144, 
            36, 9), 4)
        triton_per_fused_div_mul_sum_5[grid(1024)](buf9, buf103, primals_8,
            buf11, buf107, 1024, 8, XBLOCK=32, num_warps=2, num_stages=1)
        del buf103
        buf105 = extern_kernels.convolution(buf100, primals_9, stride=(1, 1
            ), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf105, (4, 4, 4, 4), (64, 16, 4, 1))
        buf108 = reinterpret_tensor(buf109, (4, 1, 4, 4, 4), (576, 1, 144, 
            36, 9), 8)
        triton_poi_fused_cat_7[grid(256)](buf105, buf14, buf108, 256,
            XBLOCK=128, num_warps=4, num_stages=1)
        buf110 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1),
            torch.float32)
        triton_poi_fused_cat_8[grid(36, 64)](buf109, buf110, 36, 64, XBLOCK
            =32, YBLOCK=32, num_warps=4, num_stages=1)
        del buf106
        del buf107
        del buf108
        buf111 = buf105
        del buf105
        triton_per_fused_mul_sum_9[grid(256)](buf110, primals_10, buf111, 
            256, 9, XBLOCK=1, num_warps=2, num_stages=1)
        buf112 = extern_kernels.convolution(buf111, primals_11, stride=(1, 
            1), padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf112, (4, 4, 4, 4), (64, 16, 4, 1))
        buf113 = buf98
        del buf98
        triton_poi_fused__softmax_mul_sub_11[grid(64)](primals_1, buf112,
            buf111, buf22, buf113, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf114 = buf112
        del buf112
        triton_poi_fused__softmax_mul_sub_12[grid(256)](buf114, primals_1,
            buf111, buf22, buf113, 256, XBLOCK=256, num_warps=4, num_stages=1)
        del buf113
        buf115 = buf99
        del buf99
        triton_poi_fused__softmax_1[grid(256)](buf114, buf115, 256, XBLOCK=
            128, num_warps=4, num_stages=1)
        del buf114
        buf116 = extern_kernels.convolution(buf115, primals_4, stride=(1, 1
            ), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf116, (4, 32, 4, 4), (512, 16, 4, 1))
        buf124 = buf109
        del buf109
        buf121 = reinterpret_tensor(buf124, (4, 4, 4, 4, 4), (576, 1, 144, 
            36, 9), 0)
        triton_per_fused_div_mul_sum_4[grid(1024)](buf4, buf116, primals_5,
            buf6, buf121, 1024, 8, XBLOCK=8, num_warps=2, num_stages=1)
        del buf116
        buf118 = extern_kernels.convolution(buf115, primals_7, stride=(1, 1
            ), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf118, (4, 32, 4, 4), (512, 16, 4, 1))
        buf122 = reinterpret_tensor(buf124, (4, 4, 4, 4, 4), (576, 1, 144, 
            36, 9), 4)
        triton_per_fused_div_mul_sum_5[grid(1024)](buf9, buf118, primals_8,
            buf11, buf122, 1024, 8, XBLOCK=32, num_warps=2, num_stages=1)
        del buf118
        buf120 = extern_kernels.convolution(buf115, primals_9, stride=(1, 1
            ), padding=(1, 1), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=4, bias=None)
        assert_size_stride(buf120, (4, 4, 4, 4), (64, 16, 4, 1))
        buf123 = reinterpret_tensor(buf124, (4, 1, 4, 4, 4), (576, 1, 144, 
            36, 9), 8)
        triton_poi_fused_cat_7[grid(256)](buf120, buf14, buf123, 256,
            XBLOCK=128, num_warps=4, num_stages=1)
        buf125 = empty_strided_cuda((4, 9, 4, 4, 4), (576, 64, 16, 4, 1),
            torch.float32)
        triton_poi_fused_cat_8[grid(36, 64)](buf124, buf125, 36, 64, XBLOCK
            =32, YBLOCK=32, num_warps=4, num_stages=1)
        del buf121
        del buf122
        del buf123
        del buf124
        buf126 = buf120
        del buf120
        triton_per_fused_mul_sum_9[grid(256)](buf125, primals_10, buf126, 
            256, 9, XBLOCK=1, num_warps=2, num_stages=1)
        buf127 = extern_kernels.convolution(buf126, primals_11, stride=(1, 
            1), padding=(0, 0), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf127, (4, 4, 4, 4), (64, 16, 4, 1))
        buf128 = buf127
        del buf127
        triton_poi_fused_mul_sub_13[grid(256)](buf128, primals_1, buf126,
            buf22, 256, XBLOCK=256, num_warps=4, num_stages=1)
        del primals_1
    return (buf128, primals_4, primals_5, primals_7, primals_8, primals_9,
        primals_10, primals_11, reinterpret_tensor(buf4, (4, 4, 1, 8, 4, 4),
        (512, 128, 128, 16, 4, 1), 0), reinterpret_tensor(buf6, (4, 4, 1, 4,
        4), (64, 16, 16, 4, 1), 0), reinterpret_tensor(buf9, (4, 4, 1, 8, 4,
        4), (512, 128, 128, 16, 4, 1), 0), reinterpret_tensor(buf11, (4, 4,
        1, 4, 4), (64, 16, 16, 4, 1), 0), buf14, buf19, buf20, buf22, buf25,
        buf35, buf36, buf40, buf50, buf51, buf55, buf65, buf66, buf70,
        buf80, buf81, buf85, buf95, buf96, buf100, buf110, buf111, buf115,
        buf125, buf126)


def make_onehot_kernel(kernel_size, index):
    """
    Make 2D one hot square kernel, i.e. h=w
    k[kernel_size, kernel_size] = 0 except k.view(-1)[index] = 1
    """
    kernel = torch.zeros(kernel_size, kernel_size)
    kernel.view(-1)[index] = 1
    return kernel.view(1, 1, kernel_size, kernel_size)


def make_spatial_kernel(kernel_size, bandwidth, isreshape=True):
    """
    Make 2D square smoothness kernel, i.e. h=w
    k = 1/bandwidth * exp(-(pj-pi)**2/(2*bandwidth**2))
    pj, pi = location of pixel
    """
    assert bandwidth > 0, 'bandwidth of kernel must be > 0'
    assert kernel_size % 2 != 0, 'kernel must be odd'
    p_end = (kernel_size - 1) // 2
    X = torch.linspace(-p_end, p_end, steps=kernel_size).expand(kernel_size,
        kernel_size)
    Y = X.clone().t()
    kernel = torch.exp(-(X ** 2 + Y ** 2) / (2 * bandwidth ** 2))
    kernel[p_end, p_end] = 0
    if isreshape:
        return kernel.view(1, 1, kernel_size, kernel_size)
    return kernel


class GaussianMask(nn.Module):
    """
    Break down Gaussian kernel (2nd part of appearance kernel) into CNN
    kj = (I(j) - I(i))**2/2*bandwidth**2, j#i
    but compute all maps instead of 1 kernel
    """

    def __init__(self, in_channels, kernel_size, bandwidth, iskernel=True):
        super(GaussianMask, self).__init__()
        assert bandwidth > 0, 'bandwidth of kernel must be > 0'
        assert kernel_size % 2 != 0, 'kernel must be odd'
        self.bandwidth = bandwidth
        self.iskernel = iskernel
        self.n_kernels = kernel_size ** 2 - 1
        kernel_weight = self._make_kernel_weight(in_channels, kernel_size,
            self.n_kernels)
        padding = kernel_size // 2
        self.conv = nn.Conv2d(in_channels, in_channels * self.n_kernels,
            kernel_size, stride=1, padding=padding, groups=in_channels,
            bias=False)
        self.conv.weight.requires_grad = False
        self.conv.weight.copy_(kernel_weight.view_as(self.conv.weight))

    def _make_kernel_weight(self, in_channels, kernel_size, n_kernels):
        kernel_weight = torch.zeros(in_channels, n_kernels, kernel_size,
            kernel_size)
        for i in range(n_kernels):
            index = i if i < n_kernels // 2 else i + 1
            kernel_i = make_onehot_kernel(kernel_size, index)
            kernel_weight[:, i, :] = kernel_i
        return kernel_weight

    def forward(self, X):
        batch_size, in_channels, H, W = X.shape
        Xj = self.conv(X).view(batch_size, in_channels, self.n_kernels, H, W)
        if not self.iskernel:
            return Xj
        Xi = X.unsqueeze(dim=2)
        K = (Xj - Xi) ** 2 / (2 * self.bandwidth ** 2)
        K = torch.exp(-K)
        return K


class SpatialFilter(nn.Module):
    """
    Break down spatial filter (smoothest kernel) into CNN blocks
    refer: https://arxiv.org/pdf/1210.5644.pdf
    """

    def __init__(self, n_classes, kernel_size, theta_gamma):
        super(SpatialFilter, self).__init__()
        padding = kernel_size // 2
        kernel_weight = make_spatial_kernel(kernel_size, theta_gamma)
        self.conv = nn.Conv2d(n_classes, n_classes, kernel_size, stride=1,
            padding=padding, groups=n_classes, bias=False)
        self.conv.weight.requires_grad = False
        self.conv.weight.copy_(kernel_weight)

    def forward(self, Q):
        Qtilde = self.conv(Q)
        norm_weight = self.conv(Q.new_ones(*Q.shape, requires_grad=False))
        Qtilde = Qtilde / norm_weight
        return Qtilde


class BilateralFilter(nn.Module):
    """
    Break down bilateral filter (appearance kernel) into CNN blocks
    remember that exp(-a-b) =exp(-a)*exp(b)
    """

    def __init__(self, in_channels, n_classes, kernel_size, theta_alpha,
        theta_beta):
        super(BilateralFilter, self).__init__()
        kernel_weight = make_spatial_kernel(kernel_size, theta_alpha,
            isreshape=False)
        self.spatial_weight = Parameter(kernel_weight[kernel_weight > 0].
            view(1, 1, 1, -1, 1, 1), requires_grad=False)
        self.gauss_mask_I = GaussianMask(in_channels, kernel_size, theta_beta)
        self.guass_mask_Q = GaussianMask(n_classes, kernel_size, 1,
            iskernel=False)

    def forward(self, Q, I):
        Ij = self.gauss_mask_I(I)
        Qj = self.guass_mask_Q(Q)
        Qj = Ij.unsqueeze(dim=2) * Qj.unsqueeze(dim=1)
        Qj = Qj * self.spatial_weight
        Qtilde = Qj.sum(dim=3)
        norm_weight = Ij * self.spatial_weight.squeeze(dim=2)
        norm_weight = norm_weight.sum(dim=2)
        Qtilde = Qtilde / norm_weight.unsqueeze(dim=2)
        return Qtilde


class MessagePassing(nn.Module):
    """
    Combine bilateral filter (appearance filter)
    and spatial filter to make message passing
    """

    def __init__(self, in_channels, n_classes, kernel_size=[3], theta_alpha
        =[2.0], theta_beta=[2.0], theta_gamma=[2.0]):
        super(MessagePassing, self).__init__()
        assert len(theta_alpha) == len(theta_beta
            ), 'theta_alpha and theta_beta have different lengths'
        self.n_bilaterals, self.n_spatials = len(theta_alpha), len(theta_gamma)
        for i in range(self.n_bilaterals):
            self.add_module('bilateral{}'.format(i), BilateralFilter(
                in_channels, n_classes, kernel_size[i], theta_alpha[i],
                theta_beta[i]))
        for i in range(self.n_spatials):
            self.add_module('spatial{}'.format(i), SpatialFilter(n_classes,
                kernel_size[i], theta_gamma[i]))

    def _get_child(self, child_name):
        return getattr(self, child_name)

    def forward(self, Q, I):
        filteredQ = []
        for i in range(self.n_bilaterals):
            tmp_bilateral = self._get_child('bilateral{}'.format(i))(Q, I)
            filteredQ.append(tmp_bilateral)
        for i in range(self.n_spatials):
            tmp_spatial = self._get_child('spatial{}'.format(i))(Q)
            filteredQ.append(tmp_spatial.unsqueeze(dim=1))
        Qtilde = torch.cat(filteredQ, dim=1)
        return Qtilde


class CRFRNNNew(nn.Module):
    """ Break meanfields down as CNN and do iteration """

    def __init__(self, n_iter, in_channels, n_classes, kernel_size=[3, 3],
        theta_alpha=[1.5, 2.5], theta_beta=[1.5, 2.5], theta_gamma=[1.5]):
        super(CRFRNNNew, self).__init__()
        self.n_iter = n_iter
        self.n_classes = n_classes
        n_filters = in_channels * len(theta_alpha) + len(theta_gamma)
        self.softmax = nn.Softmax2d()
        self.messagepassing = MessagePassing(in_channels, n_classes,
            kernel_size=kernel_size, theta_alpha=theta_alpha, theta_beta=
            theta_beta, theta_gamma=theta_gamma)
        self.weightfiltering = Parameter(torch.rand(1, n_filters, n_classes,
            1, 1))
        self.compatibilitytransf = nn.Conv2d(n_classes, n_classes,
            kernel_size=1, stride=1, padding=0, bias=False)
        self._weight_initial()
        self.train_step = 0

    def _weight_initial(self):
        init.kaiming_normal_(self.weightfiltering)
        init.kaiming_normal_(self.compatibilitytransf.weight)

    def forward(self, input_0, input_1):
        primals_10 = self.weightfiltering
        primals_5 = self.messagepassing.bilateral0.spatial_weight
        primals_3 = self.messagepassing.bilateral0.gauss_mask_I.conv.weight
        primals_4 = self.messagepassing.bilateral0.guass_mask_Q.conv.weight
        primals_8 = self.messagepassing.bilateral1.spatial_weight
        primals_6 = self.messagepassing.bilateral1.gauss_mask_I.conv.weight
        primals_7 = self.messagepassing.bilateral1.guass_mask_Q.conv.weight
        primals_9 = self.messagepassing.spatial0.conv.weight
        primals_11 = self.compatibilitytransf.weight
        primals_1 = input_0
        primals_2 = 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])
        return output[0]


Measured latency_ms: 0.039427