import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch.nn import Module
from torch import nn
import torch.utils.data
import torch.nn.functional
import torch.autograd
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_clone_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
    constexpr, XBLOCK: tl.constexpr):
    ynumel = 64
    xnumel = 4
    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 % 4
    y1 = yindex // 4
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)


@triton.jit
def triton_poi_fused_clone_1(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 = 0.0
    tmp1 = tl_math.exp(tmp0)
    tmp2 = tmp1 + tmp1
    tmp3 = tmp2 + tmp1
    tmp4 = tmp3 + tmp1
    tmp5 = tmp1 / tmp4
    tl.store(out_ptr0 + x0, tmp5, xmask)


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


@triton.jit
def triton_poi_fused_add_div_mul_pow_sqrt_sum_3(in_ptr0, out_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 4
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tmp0 * tmp0
    tmp3 = tmp2 * tmp2
    tmp4 = tmp1 + tmp3
    tmp6 = tmp5 * tmp5
    tmp7 = tmp4 + tmp6
    tmp9 = tmp8 * tmp8
    tmp10 = tmp7 + tmp9
    tmp11 = 1.0
    tmp12 = tmp10 + tmp11
    tmp13 = tmp10 / tmp12
    tmp15 = 1e-08
    tmp16 = tmp10 + tmp15
    tmp17 = libdevice.sqrt(tmp16)
    tmp18 = tmp14 / tmp17
    tmp19 = tmp13 * tmp18
    tl.store(out_ptr0 + x2, tmp19, xmask)


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


@triton.jit
def triton_poi_fused__softmax_5(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
    ):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), 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 + x2, tmp9, xmask)


@triton.jit
def triton_poi_fused__softmax_6(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK:
    tl.constexpr, XBLOCK: tl.constexpr):
    ynumel = 16
    xnumel = 4
    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 % 4
    y1 = yindex // 4
    y3 = yindex
    tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr0 + (4 * x2 + 16 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tmp2 = tl.load(in_ptr0 + (1 + 4 * x2 + 16 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr0 + (2 + 4 * x2 + 16 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr0 + (3 + 4 * x2 + 16 * y1), xmask & ymask,
        eviction_policy='evict_last')
    tmp3 = tmp1 + tmp2
    tmp5 = tmp3 + tmp4
    tmp7 = tmp5 + tmp6
    tmp8 = tmp0 / tmp7
    tl.store(out_ptr0 + (x2 + 4 * y3), tmp8, xmask & ymask)


@triton.jit
def triton_poi_fused_bmm_7(in_ptr0, 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 + (4 * x1 + 16 * (x0 // 4) + x0 % 4), xmask)
    tl.store(out_ptr0 + x2, tmp0, xmask)


@triton.jit
def triton_poi_fused__softmax_add_8(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
    xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp4 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp7 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp12 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp2 = tmp0 + tmp1
    tmp5 = tmp3 + tmp4
    tmp6 = triton_helpers.maximum(tmp2, tmp5)
    tmp9 = tmp7 + tmp8
    tmp10 = triton_helpers.maximum(tmp6, tmp9)
    tmp13 = tmp11 + tmp12
    tmp14 = triton_helpers.maximum(tmp10, tmp13)
    tmp15 = tmp2 - tmp14
    tmp16 = tl_math.exp(tmp15)
    tmp17 = tmp5 - tmp14
    tmp18 = tl_math.exp(tmp17)
    tmp19 = tmp16 + tmp18
    tmp20 = tmp9 - tmp14
    tmp21 = tl_math.exp(tmp20)
    tmp22 = tmp19 + tmp21
    tmp23 = tmp13 - tmp14
    tmp24 = tl_math.exp(tmp23)
    tmp25 = tmp22 + tmp24
    tl.store(out_ptr0 + x0, tmp14, xmask)
    tl.store(out_ptr1 + x0, tmp25, xmask)


@triton.jit
def triton_poi_fused__softmax_add_clone_9(in_ptr0, in_ptr1, in_ptr2,
    in_ptr3, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x1 = xindex // 4
    tmp0 = tl.load(in_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr1 + x2, xmask)
    tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 - tmp3
    tmp5 = tl_math.exp(tmp4)
    tmp7 = tmp5 / tmp6
    tl.store(out_ptr0 + x2, tmp7, xmask)
    tl.store(out_ptr1 + x2, tmp7, xmask)


@triton.jit
def triton_poi_fused__softmax_add_10(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
    out_ptr1, xnumel, XBLOCK: tl.constexpr):
    xnumel = 16
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp3 = tl.load(in_ptr2 + 4 * x0, xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp6 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp8 = tl.load(in_ptr2 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
    tmp11 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp12 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp14 = tl.load(in_ptr2 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp17 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp18 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp20 = tl.load(in_ptr2 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
        )
    tmp2 = tmp0 + tmp1
    tmp4 = tmp2 + tmp3
    tmp7 = tmp5 + tmp6
    tmp9 = tmp7 + tmp8
    tmp10 = triton_helpers.maximum(tmp4, tmp9)
    tmp13 = tmp11 + tmp12
    tmp15 = tmp13 + tmp14
    tmp16 = triton_helpers.maximum(tmp10, tmp15)
    tmp19 = tmp17 + tmp18
    tmp21 = tmp19 + tmp20
    tmp22 = triton_helpers.maximum(tmp16, tmp21)
    tmp23 = tmp4 - tmp22
    tmp24 = tl_math.exp(tmp23)
    tmp25 = tmp9 - tmp22
    tmp26 = tl_math.exp(tmp25)
    tmp27 = tmp24 + tmp26
    tmp28 = tmp15 - tmp22
    tmp29 = tl_math.exp(tmp28)
    tmp30 = tmp27 + tmp29
    tmp31 = tmp21 - tmp22
    tmp32 = tl_math.exp(tmp31)
    tmp33 = tmp30 + tmp32
    tl.store(out_ptr0 + x0, tmp22, xmask)
    tl.store(out_ptr1 + x0, tmp33, xmask)


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


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


def call(args):
    primals_1, primals_2 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 4, 4, 4, 1), (64, 16, 4, 1, 1), torch
            .float32)
        get_raw_stream(0)
        triton_poi_fused_clone_0[grid(64, 4)](primals_1, buf0, 64, 4,
            XBLOCK=4, YBLOCK=32, num_warps=4, num_stages=1)
        del primals_1
        buf1 = empty_strided_cuda((4, 16, 4), (64, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf0, (4, 16, 4), (64, 4, 1),
            0), reinterpret_tensor(primals_2, (4, 4, 4), (4, 1, 16), 0),
            out=buf1)
        buf2 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32)
        triton_poi_fused_clone_1[grid(64)](buf2, 64, XBLOCK=64, num_warps=1,
            num_stages=1)
        buf3 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0)
        del buf0
        triton_poi_fused_clone_2[grid(4, 64)](buf1, buf3, 4, 64, XBLOCK=32,
            YBLOCK=4, num_warps=4, num_stages=1)
        buf4 = empty_strided_cuda((16, 1, 4), (4, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf2, (16, 1, 4), (4, 0, 1), 
            0), reinterpret_tensor(buf3, (16, 4, 4), (16, 4, 1), 0), out=buf4)
        buf5 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_add_div_mul_pow_sqrt_sum_3[grid(64)](buf4, buf5, 
            64, XBLOCK=64, num_warps=1, num_stages=1)
        buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
        triton_poi_fused_clone_4[grid(4, 64)](buf1, buf6, 4, 64, XBLOCK=32,
            YBLOCK=4, num_warps=4, num_stages=1)
        del buf1
        buf7 = empty_strided_cuda((16, 1, 4), (4, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf5, (16, 1, 4), (4, 0, 1), 
            0), reinterpret_tensor(buf6, (16, 4, 4), (16, 4, 1), 0), out=buf7)
        buf8 = empty_strided_cuda((4, 4, 4), (16, 1, 4), torch.float32)
        triton_poi_fused__softmax_5[grid(64)](buf7, buf8, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf9 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused__softmax_6[grid(16, 4)](buf8, buf9, 16, 4, XBLOCK=
            4, YBLOCK=16, num_warps=1, num_stages=1)
        buf10 = reinterpret_tensor(buf8, (16, 1, 4), (1, 64, 16), 0)
        del buf8
        triton_poi_fused_bmm_7[grid(64)](buf9, buf10, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf11 = empty_strided_cuda((16, 1, 4), (4, 4, 1), torch.float32)
        extern_kernels.bmm(buf10, reinterpret_tensor(buf3, (16, 4, 4), (16,
            4, 1), 0), out=buf11)
        buf12 = reinterpret_tensor(buf10, (4, 4, 4), (16, 4, 1), 0)
        del buf10
        triton_poi_fused_add_div_mul_pow_sqrt_sum_3[grid(64)](buf11, buf12,
            64, XBLOCK=64, num_warps=1, num_stages=1)
        buf13 = empty_strided_cuda((16, 1, 4), (4, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf12, (16, 1, 4), (4, 0, 1),
            0), reinterpret_tensor(buf6, (16, 4, 4), (16, 4, 1), 0), out=buf13)
        buf14 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32)
        buf15 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32)
        triton_poi_fused__softmax_add_8[grid(16)](buf7, buf13, buf14, buf15,
            16, XBLOCK=16, num_warps=1, num_stages=1)
        buf16 = empty_strided_cuda((4, 4, 4), (16, 1, 4), torch.float32)
        buf17 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32)
        triton_poi_fused__softmax_add_clone_9[grid(64)](buf7, buf13, buf14,
            buf15, buf16, buf17, 64, XBLOCK=64, num_warps=1, num_stages=1)
        buf18 = empty_strided_cuda((16, 1, 4), (4, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf17, (16, 1, 4), (4, 0, 1),
            0), reinterpret_tensor(buf3, (16, 4, 4), (16, 4, 1), 0), out=buf18)
        buf19 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_add_div_mul_pow_sqrt_sum_3[grid(64)](buf18, buf19,
            64, XBLOCK=64, num_warps=1, num_stages=1)
        buf20 = empty_strided_cuda((16, 1, 4), (4, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf19, (16, 1, 4), (4, 0, 1),
            0), reinterpret_tensor(buf6, (16, 4, 4), (16, 4, 1), 0), out=buf20)
        buf21 = buf15
        del buf15
        buf22 = buf14
        del buf14
        triton_poi_fused__softmax_add_10[grid(16)](buf7, buf13, buf20,
            buf21, buf22, 16, XBLOCK=16, num_warps=1, num_stages=1)
        buf23 = reinterpret_tensor(buf13, (4, 4, 4), (16, 1, 4), 0)
        del buf13
        buf24 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32)
        triton_poi_fused__softmax_add_clone_11[grid(64)](buf23, buf7, buf20,
            buf21, buf22, buf24, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del buf21
        del buf22
        buf25 = buf20
        del buf20
        extern_kernels.bmm(reinterpret_tensor(buf24, (16, 1, 4), (4, 0, 1),
            0), reinterpret_tensor(buf3, (16, 4, 4), (16, 4, 1), 0), out=buf25)
        buf26 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        triton_poi_fused_add_div_mul_pow_sqrt_sum_3[grid(64)](buf25, buf26,
            64, XBLOCK=64, num_warps=1, num_stages=1)
        buf27 = empty_strided_cuda((16, 4, 1), (4, 1, 4), torch.float32)
        triton_poi_fused_transpose_12[grid(16, 4)](buf9, buf27, 16, 4,
            XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1)
        del buf9
    return (buf26, buf4, buf7, buf11, buf16, buf18, buf23, buf25,
        reinterpret_tensor(buf24, (16, 4, 1), (4, 1, 4), 0),
        reinterpret_tensor(buf3, (16, 4, 4), (16, 1, 4), 0),
        reinterpret_tensor(buf19, (16, 4, 1), (4, 1, 4), 0),
        reinterpret_tensor(buf6, (16, 4, 4), (16, 1, 4), 0),
        reinterpret_tensor(buf17, (16, 4, 1), (4, 1, 4), 0),
        reinterpret_tensor(buf12, (16, 4, 1), (4, 1, 4), 0), buf27,
        reinterpret_tensor(buf5, (16, 4, 1), (4, 1, 4), 0),
        reinterpret_tensor(buf2, (16, 4, 1), (4, 1, 4), 0),
        reinterpret_tensor(primals_2, (4, 4, 4), (4, 16, 1), 0))


class Squash(Module):
    '\n    ## Squash\n\n    This is **squashing** function from paper, given by equation $(1)$.\n\n    $$\\mathbf{v}_j = \x0crac{{\\lVert \\mathbf{s}_j \rVert}^2}{1 + {\\lVert \\mathbf{s}_j \rVert}^2}\n     \x0crac{\\mathbf{s}_j}{\\lVert \\mathbf{s}_j \rVert}$$\n\n    $\x0crac{\\mathbf{s}_j}{\\lVert \\mathbf{s}_j \rVert}$\n    normalizes the length of all the capsules, whilst\n    $\x0crac{{\\lVert \\mathbf{s}_j \rVert}^2}{1 + {\\lVert \\mathbf{s}_j \rVert}^2}$\n    shrinks the capsules that have a length smaller than one .\n    '

    def __init__(self, epsilon=1e-08):
        super().__init__()
        self.epsilon = epsilon

    def forward(self, s: 'torch.Tensor'):
        """
        The shape of `s` is `[batch_size, n_capsules, n_features]`
        """
        s2 = (s ** 2).sum(dim=-1, keepdims=True)
        return s2 / (1 + s2) * (s / torch.sqrt(s2 + self.epsilon))


class RouterNew(Module):
    """
    ## Routing Algorithm

    This is the routing mechanism described in the paper.
    You can use multiple routing layers in your models.

    This combines calculating $\\mathbf{s}_j$ for this layer and
    the routing algorithm described in *Procedure 1*.
    """

    def __init__(self, in_caps: 'int', out_caps: 'int', in_d: 'int', out_d:
        'int', iterations: 'int'):
        """
        `in_caps` is the number of capsules, and `in_d` is the number of features per capsule from the layer below.
        `out_caps` and `out_d` are the same for this layer.

        `iterations` is the number of routing iterations, symbolized by $r$ in the paper.
        """
        super().__init__()
        self.in_caps = in_caps
        self.out_caps = out_caps
        self.iterations = iterations
        self.softmax = nn.Softmax(dim=1)
        self.squash = Squash()
        self.weight = nn.Parameter(torch.randn(in_caps, out_caps, in_d,
            out_d), requires_grad=True)

    def forward(self, input_0):
        primals_1 = self.weight
        primals_2 = input_0
        output = call([primals_1, primals_2])
        return output[0]


Measured latency_ms: 0.021308