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


class AttentionPool2d(nn.Module):

    def __init__(self, spacial_dim: 'int', embed_dim: 'int', num_heads:
        'int', output_dim: 'int'=None):
        super().__init__()
        self.positional_embedding = nn.Parameter(torch.randn(spacial_dim **
            2 + 1, embed_dim) / embed_dim ** 0.5)
        self.k_proj = nn.Linear(embed_dim, embed_dim)
        self.q_proj = nn.Linear(embed_dim, embed_dim)
        self.v_proj = nn.Linear(embed_dim, embed_dim)
        self.c_proj = nn.Linear(embed_dim, output_dim or embed_dim)
        self.num_heads = num_heads

    def forward(self, x):
        x = x.reshape(x.shape[0], x.shape[1], x.shape[2] * x.shape[3]).permute(
            2, 0, 1)
        x = torch.cat([x.mean(dim=0, keepdim=True), x], dim=0)
        temp = self.positional_embedding[:, None, :]
        temp = temp.permute(2, 1, 0)
        temp = F.interpolate(temp, size=x.shape[0], mode='linear').permute(
            2, 1, 0)
        x = x + temp
        x, _ = F.multi_head_attention_forward(query=x, key=x, value=x,
            embed_dim_to_check=x.shape[-1], num_heads=self.num_heads,
            q_proj_weight=self.q_proj.weight, k_proj_weight=self.k_proj.
            weight, v_proj_weight=self.v_proj.weight, in_proj_weight=None,
            in_proj_bias=torch.cat([self.q_proj.bias, self.k_proj.bias,
            self.v_proj.bias]), bias_k=None, bias_v=None, add_zero_attn=
            False, dropout_p=0, out_proj_weight=self.c_proj.weight,
            out_proj_bias=self.c_proj.bias, use_separate_proj_weight=True,
            training=self.training, need_weights=False)
        return x


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


def get_init_inputs():
    return [[], {'spacial_dim': 4, 'embed_dim': 4, 'num_heads': 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
from torch._inductor.runtime.triton_helpers import math as tl_math
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor


@triton.jit
def triton_per_fused_mean_0(in_ptr0, out_ptr0, 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)
    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, 0)
    tmp4 = tl.sum(tmp3, 1)[:, None]
    tl.store(out_ptr0 + x0, tmp4, xmask)


@triton.jit
def triton_poi_fused__to_copy_add_arange_clamp_mul_sub_1(out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 17
    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 = 1.0
    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_2(out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 17
    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 = 1.0
    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], 16, 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_3(out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 17
    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 = 1.0
    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 = triton_helpers.minimum(tmp12, tmp4)
    tl.store(out_ptr0 + x0, tmp13, xmask)


@triton.jit
def triton_poi_fused_add_cat_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 272
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex // 16
    x3 = xindex % 16
    x0 = xindex % 4
    x5 = xindex
    tmp30 = tl.load(in_ptr3 + x2, xmask, eviction_policy='evict_last')
    tmp0 = x2
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 1, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + x3, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp6 = 16.0
    tmp7 = tmp5 / tmp6
    tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype)
    tmp9 = tl.where(tmp4, tmp7, tmp8)
    tmp10 = tmp0 >= tmp3
    tl.full([1], 17, tl.int64)
    tmp13 = tl.load(in_ptr1 + (16 * x3 + (-1 + x2)), tmp10 & xmask,
        eviction_policy='evict_last', other=0.0)
    tmp14 = tl.where(tmp4, tmp9, tmp13)
    tmp15 = tmp0.to(tl.float32)
    tmp16 = 0.5
    tmp17 = tmp15 + tmp16
    tmp18 = 1.0
    tmp19 = tmp17 * tmp18
    tmp20 = tmp19 - tmp16
    tmp21 = 0.0
    tmp22 = triton_helpers.maximum(tmp20, tmp21)
    tmp23 = tmp22.to(tl.int32)
    tmp24 = tl.load(in_ptr2 + (x0 + 4 * tmp23), xmask)
    tmp25 = tmp23 + tmp3
    tmp26 = tl.full([1], 16, tl.int64)
    tmp27 = triton_helpers.minimum(tmp25, tmp26)
    tmp28 = tl.load(in_ptr2 + (x0 + 4 * tmp27), xmask)
    tmp29 = tmp28 - tmp24
    tmp31 = tmp29 * tmp30
    tmp32 = tmp24 + tmp31
    tmp33 = tmp14 + tmp32
    tl.store(out_ptr0 + x5, tmp33, xmask)


@triton.jit
def triton_poi_fused_cat_5(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 12
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = x0
    tl.full([1], 0, tl.int64)
    tmp3 = tl.full([1], 4, tl.int64)
    tmp4 = tmp0 < tmp3
    tmp5 = tl.load(in_ptr0 + x0, tmp4 & xmask, eviction_policy='evict_last',
        other=0.0)
    tmp6 = tmp0 >= tmp3
    tmp7 = tl.full([1], 8, tl.int64)
    tmp8 = tmp0 < tmp7
    tmp9 = tmp6 & tmp8
    tmp10 = tl.load(in_ptr1 + (-4 + x0), tmp9 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp11 = tmp0 >= tmp7
    tl.full([1], 12, tl.int64)
    tmp14 = tl.load(in_ptr2 + (-8 + x0), tmp11 & xmask, eviction_policy=
        'evict_last', other=0.0)
    tmp15 = tl.where(tmp9, tmp10, tmp14)
    tmp16 = tl.where(tmp4, tmp5, tmp15)
    tl.store(out_ptr0 + x0, tmp16, xmask)


@triton.jit
def triton_poi_fused_mul_transpose_6(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
    out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.
    constexpr):
    ynumel = 16
    xnumel = 17
    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
    y3 = yindex
    y0 = yindex % 4
    tmp0 = tl.load(in_ptr0 + (y3 + 16 * x2), xmask & ymask, eviction_policy
        ='evict_last')
    tmp1 = y0
    tl.full([1, 1], 0, tl.int64)
    tmp4 = tl.full([1, 1], 4, tl.int64)
    tmp5 = tmp1 < tmp4
    tmp6 = tl.load(in_ptr1 + tl.broadcast_to(y0, [XBLOCK, YBLOCK]), tmp5 &
        xmask & ymask, eviction_policy='evict_last', other=0.0)
    tmp7 = tmp1 >= tmp4
    tmp8 = tl.full([1, 1], 8, tl.int64)
    tmp9 = tmp1 < tmp8
    tmp10 = tmp7 & tmp9
    tmp11 = tl.load(in_ptr2 + tl.broadcast_to(-4 + y0, [XBLOCK, YBLOCK]), 
        tmp10 & xmask & ymask, eviction_policy='evict_last', other=0.0)
    tmp12 = tmp1 >= tmp8
    tl.full([1, 1], 12, tl.int64)
    tmp15 = tl.load(in_ptr3 + tl.broadcast_to(-8 + y0, [XBLOCK, YBLOCK]), 
        tmp12 & xmask & ymask, eviction_policy='evict_last', other=0.0)
    tmp16 = tl.where(tmp10, tmp11, tmp15)
    tmp17 = tl.where(tmp5, tmp6, tmp16)
    tmp18 = tmp0 + tmp17
    tmp19 = 1.0
    tmp20 = tmp18 * tmp19
    tl.store(out_ptr0 + (x2 + 17 * y3), tmp20, xmask & ymask)
    tl.store(out_ptr1 + (y3 + 16 * x2), tmp20, xmask & ymask)


@triton.jit
def triton_poi_fused_mul_transpose_7(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
    out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.
    constexpr):
    ynumel = 16
    xnumel = 17
    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
    y3 = yindex
    y0 = yindex % 4
    tmp0 = tl.load(in_ptr0 + (y3 + 16 * x2), xmask & ymask, eviction_policy
        ='evict_last')
    tmp1 = 4 + y0
    tl.full([1, 1], 0, tl.int64)
    tmp4 = tl.full([1, 1], 4, tl.int64)
    tmp5 = tmp1 < tmp4
    tmp6 = tl.load(in_ptr1 + tl.broadcast_to(4 + y0, [XBLOCK, YBLOCK]), 
        tmp5 & xmask & ymask, eviction_policy='evict_last', other=0.0)
    tmp7 = tmp1 >= tmp4
    tmp8 = tl.full([1, 1], 8, tl.int64)
    tmp9 = tmp1 < tmp8
    tmp10 = tmp7 & tmp9
    tmp11 = tl.load(in_ptr2 + tl.broadcast_to(y0, [XBLOCK, YBLOCK]), tmp10 &
        xmask & ymask, eviction_policy='evict_last', other=0.0)
    tmp12 = tmp1 >= tmp8
    tl.full([1, 1], 12, tl.int64)
    tmp15 = tl.load(in_ptr3 + tl.broadcast_to(-4 + y0, [XBLOCK, YBLOCK]), 
        tmp12 & xmask & ymask, eviction_policy='evict_last', other=0.0)
    tmp16 = tl.where(tmp10, tmp11, tmp15)
    tmp17 = tl.where(tmp5, tmp6, tmp16)
    tmp18 = tmp0 + tmp17
    tmp19 = 1.0
    tmp20 = tmp18 * tmp19
    tl.store(out_ptr0 + (x2 + 17 * y3), tmp20, xmask & ymask)
    tl.store(out_ptr1 + (y3 + 16 * x2), tmp20, xmask & ymask)


@triton.jit
def triton_per_fused__safe_softmax_8(in_ptr0, out_ptr3, xnumel, rnumel,
    XBLOCK: tl.constexpr):
    xnumel = 272
    rnumel = 17
    RBLOCK: tl.constexpr = 32
    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
    r1 = rindex
    x0 = xindex
    x2 = xindex % 68
    x3 = xindex // 68
    tmp0 = tl.load(in_ptr0 + (r1 + 17 * x0), rmask & xmask, other=0.0)
    tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
    tmp3 = tl.where(rmask & 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(rmask & xmask, tmp7, 0)
    tmp10 = tl.sum(tmp9, 1)[:, None]
    tmp11 = float('-inf')
    tmp12 = tmp0 == tmp11
    tmp13 = tmp12 == 0
    tmp14 = tmp13.to(tl.int64)
    tmp15 = tmp14 != 0
    tmp16 = tl.broadcast_to(tmp15, [XBLOCK, RBLOCK])
    tmp18 = tl.where(rmask & xmask, tmp16, 0)
    tmp19 = triton_helpers.any(tmp18, 1)[:, None]
    tmp20 = tmp19 == 0
    tmp21 = tmp6 / tmp10
    tmp22 = 0.0
    tmp23 = tl.where(tmp20, tmp22, tmp21)
    tl.store(out_ptr3 + (r1 + 17 * x2 + 1184 * x3), tmp23, rmask & xmask)


@triton.jit
def triton_poi_fused_bmm_9(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 4624
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 289
    x1 = xindex // 289
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 289 * (x1 % 4) + 1184 * (x1 // 4)), xmask)
    tl.store(out_ptr0 + x2, tmp0, xmask)


@triton.jit
def triton_poi_fused_clone_10(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl
    .constexpr, XBLOCK: tl.constexpr):
    ynumel = 17
    xnumel = 16
    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
    x1 = xindex
    y0 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 17 * x1), xmask & ymask, eviction_policy
        ='evict_last')
    tl.store(out_ptr0 + (x1 + 16 * y0), tmp0, xmask & ymask)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9, primals_10) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (17, 4), (4, 1))
    assert_size_stride(primals_3, (4, 4), (4, 1))
    assert_size_stride(primals_4, (4, 4), (4, 1))
    assert_size_stride(primals_5, (4, 4), (4, 1))
    assert_size_stride(primals_6, (4,), (1,))
    assert_size_stride(primals_7, (4,), (1,))
    assert_size_stride(primals_8, (4,), (1,))
    assert_size_stride(primals_9, (4, 4), (4, 1))
    assert_size_stride(primals_10, (4,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((1, 4, 4), (16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_per_fused_mean_0[grid(16)](primals_1, buf0, 16, 16, XBLOCK=8,
            num_warps=2, num_stages=1)
        buf1 = empty_strided_cuda((17,), (1,), torch.int64)
        triton_poi_fused__to_copy_add_arange_clamp_mul_sub_1[grid(17)](buf1,
            17, XBLOCK=32, num_warps=1, num_stages=1)
        buf2 = empty_strided_cuda((17,), (1,), torch.int64)
        triton_poi_fused_add_clamp_2[grid(17)](buf2, 17, XBLOCK=32,
            num_warps=1, num_stages=1)
        buf3 = empty_strided_cuda((17,), (1,), torch.float32)
        triton_poi_fused__to_copy_add_arange_clamp_mul_sub_3[grid(17)](buf3,
            17, XBLOCK=32, num_warps=1, num_stages=1)
        buf4 = empty_strided_cuda((17, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_add_cat_4[grid(272)](buf0, primals_1, primals_2,
            buf3, buf4, 272, XBLOCK=256, num_warps=4, num_stages=1)
        del buf0
        del primals_1
        del primals_2
        buf5 = empty_strided_cuda((68, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf4, (68, 4), (4, 1), 0),
            reinterpret_tensor(primals_3, (4, 4), (1, 4), 0), out=buf5)
        buf6 = empty_strided_cuda((68, 4), (4, 1), torch.float32)
        extern_kernels.mm(reinterpret_tensor(buf4, (68, 4), (4, 1), 0),
            reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf6)
        buf7 = empty_strided_cuda((12,), (1,), torch.float32)
        triton_poi_fused_cat_5[grid(12)](primals_6, primals_7, primals_8,
            buf7, 12, XBLOCK=16, num_warps=1, num_stages=1)
        buf8 = empty_strided_cuda((68, 4), (4, 1), torch.float32)
        extern_kernels.addmm(reinterpret_tensor(buf7, (4,), (1,), 8),
            reinterpret_tensor(buf4, (68, 4), (4, 1), 0),
            reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), alpha=1, beta
            =1, out=buf8)
        del buf7
        buf9 = empty_strided_cuda((4, 4, 17, 1), (68, 17, 1, 1), torch.float32)
        buf20 = empty_strided_cuda((16, 1, 17), (1, 1, 16), torch.float32)
        triton_poi_fused_mul_transpose_6[grid(16, 17)](buf5, primals_6,
            primals_7, primals_8, buf9, buf20, 16, 17, XBLOCK=32, YBLOCK=16,
            num_warps=4, num_stages=1)
        buf10 = reinterpret_tensor(buf5, (4, 4, 1, 17), (68, 17, 17, 1), 0)
        del buf5
        buf21 = empty_strided_cuda((16, 17, 1), (1, 16, 1), torch.float32)
        triton_poi_fused_mul_transpose_7[grid(16, 17)](buf6, primals_6,
            primals_7, primals_8, buf10, buf21, 16, 17, XBLOCK=32, YBLOCK=
            16, num_warps=4, num_stages=1)
        del buf6
        del primals_6
        del primals_7
        del primals_8
        buf11 = empty_strided_cuda((16, 17, 17), (289, 17, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf9, (16, 17, 1), (17, 1, 0),
            0), reinterpret_tensor(buf10, (16, 1, 17), (17, 0, 1), 0), out=
            buf11)
        buf15 = empty_strided_cuda((4, 4, 17, 17), (1184, 289, 17, 1),
            torch.float32)
        triton_per_fused__safe_softmax_8[grid(272)](buf11, buf15, 272, 17,
            XBLOCK=8, num_warps=2, num_stages=1)
        buf16 = buf11
        del buf11
        triton_poi_fused_bmm_9[grid(4624)](buf15, buf16, 4624, XBLOCK=128,
            num_warps=4, num_stages=1)
        buf17 = reinterpret_tensor(buf9, (16, 17, 1), (17, 1, 1), 0)
        del buf9
        extern_kernels.bmm(buf16, reinterpret_tensor(buf8, (16, 17, 1), (1,
            16, 0), 0), out=buf17)
        del buf16
        buf18 = reinterpret_tensor(buf10, (17, 4, 4, 1), (16, 4, 1, 1), 0)
        del buf10
        triton_poi_fused_clone_10[grid(17, 16)](buf17, buf18, 17, 16,
            XBLOCK=16, YBLOCK=32, num_warps=4, num_stages=1)
        buf19 = reinterpret_tensor(buf17, (68, 4), (4, 1), 0)
        del buf17
        extern_kernels.addmm(primals_10, reinterpret_tensor(buf18, (68, 4),
            (4, 1), 0), reinterpret_tensor(primals_9, (4, 4), (1, 4), 0),
            alpha=1, beta=1, out=buf19)
        del primals_10
    return reinterpret_tensor(buf19, (17, 4, 4), (16, 4, 1), 0
        ), buf1, buf2, buf3, reinterpret_tensor(buf4, (68, 4), (4, 1), 0
        ), buf15, reinterpret_tensor(buf18, (68, 4), (4, 1), 0
        ), primals_9, reinterpret_tensor(buf8, (16, 1, 17), (1, 1, 16), 0
        ), buf20, buf21, primals_5, primals_4, primals_3


class AttentionPool2dNew(nn.Module):

    def __init__(self, spacial_dim: 'int', embed_dim: 'int', num_heads:
        'int', output_dim: 'int'=None):
        super().__init__()
        self.positional_embedding = nn.Parameter(torch.randn(spacial_dim **
            2 + 1, embed_dim) / embed_dim ** 0.5)
        self.k_proj = nn.Linear(embed_dim, embed_dim)
        self.q_proj = nn.Linear(embed_dim, embed_dim)
        self.v_proj = nn.Linear(embed_dim, embed_dim)
        self.c_proj = nn.Linear(embed_dim, output_dim or embed_dim)
        self.num_heads = num_heads

    def forward(self, input_0):
        primals_2 = self.positional_embedding
        primals_3 = self.k_proj.weight
        primals_6 = self.k_proj.bias
        primals_4 = self.q_proj.weight
        primals_7 = self.q_proj.bias
        primals_5 = self.v_proj.weight
        primals_8 = self.v_proj.bias
        primals_9 = self.c_proj.weight
        primals_10 = self.c_proj.bias
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9, primals_10])
        return output[0]
