# AOT ID: ['0_forward']
from ctypes import c_void_p, c_long, c_int
import torch
import math
import random
import os
import tempfile
from math import inf, nan
from torch._inductor.hooks import run_intermediate_hooks
from torch._inductor.utils import maybe_profile
from torch._inductor.codegen.memory_planning import _align as align
from torch import device, empty_strided
from torch._inductor.async_compile import AsyncCompile
from torch._inductor.select_algorithm import extern_kernels
from torch._inductor.codegen.multi_kernel import MultiKernelCall
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid, split_scan_grid, grid_combo_kernels, start_graph, end_graph
from torch._C import _cuda_getCurrentRawStream as get_raw_stream

aten = torch.ops.aten
inductor_ops = torch.ops.inductor
_quantized = torch.ops._quantized
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cpu = torch._C._dynamo.guards._empty_strided_cpu
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
empty_strided_xpu = torch._C._dynamo.guards._empty_strided_xpu
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
alloc_from_pool = torch.ops.inductor._alloc_from_pool
async_compile = AsyncCompile()


# kernel path: runs/run_shard_4/inductor_cache/r6/cr6neze6yovkog6kjrk5k2db63h47ozkojywfys6karxe7dlumrz.py
# Topologically Sorted Source Nodes: [attn], Original ATen: [aten._softmax]
# Source node to ATen node mapping:
#   attn => amax, exp, sub
# Graph fragment:
#   %amax : [num_users=1] = call_function[target=torch.ops.aten.amax.default](args = (%bmm, [2], True), kwargs = {})
#   %sub : [num_users=1] = call_function[target=torch.ops.aten.sub.Tensor](args = (%bmm, %amax), kwargs = {})
#   %exp : [num_users=2] = call_function[target=torch.ops.aten.exp.default](args = (%sub,), kwargs = {})
triton_poi_fused__softmax_0 = async_compile.triton('triton_poi_fused__softmax_0', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[64], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__softmax_0', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 5, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused__softmax_0(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)
''', device_str='cuda')


# kernel path: runs/run_shard_4/inductor_cache/kj/ckjtlefzavjukjsytvkak6ek26zmzexpcbnlwelx4k5kascjxlf3.py
# Topologically Sorted Source Nodes: [attn], Original ATen: [aten._softmax]
# Source node to ATen node mapping:
#   attn => div, sum_1
# Graph fragment:
#   %sum_1 : [num_users=1] = call_function[target=torch.ops.aten.sum.dim_IntList](args = (%exp, [2], True), kwargs = {})
#   %div : [num_users=2] = call_function[target=torch.ops.aten.div.Tensor](args = (%exp, %sum_1), kwargs = {})
triton_poi_fused__softmax_1 = async_compile.triton('triton_poi_fused__softmax_1', '''
import triton
import triton.language as tl
from triton.compiler.compiler import AttrsDescriptor

from torch._inductor.runtime import triton_helpers, triton_heuristics
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch._inductor.runtime.hints import AutotuneHint, ReductionHint, TileHint, instance_descriptor, DeviceProperties

@triton_heuristics.pointwise(
    size_hints=[64], 
    filename=__file__,
    triton_meta={'signature': {0: '*fp32', 1: '*fp32', 2: 'i32'}, 'device': DeviceProperties(type='cuda', index=0, cc=80, major=8, regs_per_multiprocessor=65536, max_threads_per_multi_processor=2048, multi_processor_count=108), 'constants': {}, 'configs': [AttrsDescriptor(divisible_by_16=(0, 1, 2), equal_to_1=())]},
    inductor_meta={'autotune_hints': set(), 'kernel_name': 'triton_poi_fused__softmax_1', 'mutated_arg_names': [], 'no_x_dim': False, 'num_load': 5, 'num_reduction': 0, 'backend_hash': 'A9C866B4A14FD3277824029365D703C2427B2E685E54EC9B3EF4ADC8D1EEAC1D', 'are_deterministic_algorithms_enabled': False, 'assert_indirect_indexing': True, 'autotune_local_cache': True, 'autotune_pointwise': True, 'autotune_remote_cache': None, 'force_disable_caches': False, 'dynamic_scale_rblock': True, 'max_autotune': False, 'max_autotune_pointwise': False, 'min_split_scan_rblock': 256, 'spill_threshold': 16, 'store_cubin': False},
    min_elem_per_thread=0
)
@triton.jit
def triton_poi_fused__softmax_1(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 = tmp1 + tmp2
    tmp5 = tmp3 + tmp4
    tmp7 = tmp5 + tmp6
    tmp8 = tmp0 / tmp7
    tl.store(out_ptr0 + (x2), tmp8, xmask)
''', device_str='cuda')


async_compile.wait(globals())
del async_compile

def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    assert_size_stride(primals_3, (4, ), (1, ))
    assert_size_stride(primals_4, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_5, (4, 4, 4), (16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [q], Original ATen: [aten.addmm]
        extern_kernels.addmm(primals_3, reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf0)
        buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [k], Original ATen: [aten.addmm]
        extern_kernels.addmm(primals_3, reinterpret_tensor(primals_4, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf1)
        buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [v], Original ATen: [aten.addmm]
        extern_kernels.addmm(primals_3, reinterpret_tensor(primals_5, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf2)
        del primals_2
        del primals_3
        buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [a], Original ATen: [aten.bmm]
        extern_kernels.bmm(reinterpret_tensor(buf0, (4, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf1, (4, 4, 4), (16, 1, 4), 0), out=buf3)
        buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        # Topologically Sorted Source Nodes: [attn], Original ATen: [aten._softmax]
        stream0 = get_raw_stream(0)
        triton_poi_fused__softmax_0.run(buf3, buf4, 64, grid=grid(64), stream=stream0)
        buf5 = buf3; del buf3  # reuse
        # Topologically Sorted Source Nodes: [attn], Original ATen: [aten._softmax]
        triton_poi_fused__softmax_1.run(buf4, buf5, 64, grid=grid(64), stream=stream0)
        buf6 = buf4; del buf4  # reuse
        # Topologically Sorted Source Nodes: [output], Original ATen: [aten.bmm]
        extern_kernels.bmm(buf5, reinterpret_tensor(buf2, (4, 4, 4), (16, 4, 1), 0), out=buf6)
    return (buf6, buf5, reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_4, (16, 4), (4, 1), 0), reinterpret_tensor(primals_5, (16, 4), (4, 1), 0), buf5, reinterpret_tensor(buf2, (4, 4, 4), (16, 1, 4), 0), reinterpret_tensor(buf0, (4, 4, 4), (16, 1, 4), 0), reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0), )


def benchmark_compiled_module(times=10, repeat=10):
    from torch._dynamo.testing import rand_strided
    from torch._inductor.utils import print_performance
    primals_1 = rand_strided((4, 4, 4), (16, 4, 1), device='cuda:0', dtype=torch.float32)
    primals_2 = rand_strided((4, 4), (4, 1), device='cuda:0', dtype=torch.float32)
    primals_3 = rand_strided((4, ), (1, ), device='cuda:0', dtype=torch.float32)
    primals_4 = rand_strided((4, 4, 4), (16, 4, 1), device='cuda:0', dtype=torch.float32)
    primals_5 = rand_strided((4, 4, 4), (16, 4, 1), device='cuda:0', dtype=torch.float32)
    fn = lambda: call([primals_1, primals_2, primals_3, primals_4, primals_5])
    return print_performance(fn, times=times, repeat=repeat)


if __name__ == "__main__":
    from torch._inductor.wrapper_benchmark import compiled_module_main
    compiled_module_main('None', benchmark_compiled_module)

import math
import torch
import warnings
from typing import Optional
from typing import Tuple
import torch.nn as nn


class DotProductAttention(nn.Module):
    """DotProductAttention.

    .. math::

        \\mathrm{DotProductAttention}(Q, K, V) &=& \\mathrm{softmax}(qk^T) v

        q &=& QW_1 + b_1

        k &=& KW_2 + b_2

        v &=& VW_3 + b_3

    Args:
        qdim: dimension of the model, i.e., dimension of Q
        hidden_dim: dimension of hidden layer, i.e., dimension of q, k, v. Default: 512
        output_dim: dimension of output layer, i.e., dimension of output. Default: None
        dropout: a Dropout layer on attn_output_weights. Default: 0.0.
        transform: q = Q, k = K, v = V if it is False. Default: True
        bias: add bias as module parameter. Default: True.
        same_embd: W1 = W2 = W3, b1 = b2 = b3 if it is True. Default: True
        add_bias_kv: add bias to the key and value sequences at dim=0.
        kdim: total number of features in key. Default: None.
        vdim: total number of features in key. Default: None.
        Note: if kdim and vdim are None, they will be set to embed_dim such that
        query, key, and value have the same number of features.

    Examples::
        >>> attn = DotProductAttention(query_dim)
        >>> attn_output, attn_output_weights = attn(query, key, value)
    """

    def __init__(self, qdim: 'int', output_dim: 'Optional[int]'=None,
        dropout: 'float'=0.0, transform: 'bool'=True, bias: 'bool'=True,
        same_embd: 'bool'=True, add_bias_kv: 'Optional[bool]'=None, kdim:
        'Optional[int]'=None, vdim: 'Optional[int]'=None, batch_first:
        'bool'=True, scaled: 'bool'=False) ->None:
        super(DotProductAttention, self).__init__()
        self.qdim: 'int' = qdim
        self.transform: 'bool' = transform
        self.bias: 'bool' = bias
        self.same_embd: 'bool' = same_embd
        self.kdim: 'int' = kdim if kdim is not None else self.qdim
        self.vdim: 'int' = vdim if vdim is not None else self.qdim
        self.output_dim: 'int' = (output_dim if output_dim is not None else
            self.vdim)
        if self.same_embd and (self.qdim != self.kdim or self.qdim != self.vdim
            ):
            raise AssertionError(
                'qdim, kdim, vdim should be the same dimensions if same_embd is True'
                )
        self.add_bias_kv: 'bool' = (add_bias_kv if add_bias_kv is not None else
            self.bias)
        if self.same_embd and self.bias != self.add_bias_kv:
            raise AssertionError(
                'bias and add_bias_kv should be the same if same_embd is True')
        self.batch_first: 'bool' = batch_first
        self.scaled: 'bool' = scaled
        self.fc_q: 'nn.Module' = nn.Linear(self.qdim, self.output_dim, bias
            =bias)
        self.fc_k: 'nn.Module'
        self.fc_v: 'nn.Module'
        if self.same_embd:
            self.fc_k = self.fc_q
            self.fc_v = self.fc_k
        else:
            self.fc_k = nn.Linear(self.kdim, self.output_dim, bias=self.
                add_bias_kv)
            self.fc_v = nn.Linear(self.vdim, self.output_dim, bias=self.
                add_bias_kv)
        self.dropout: 'nn.Module' = nn.Dropout(p=dropout)
        self.softmax: 'nn.Module' = nn.Softmax(dim=2)

    def forward(self, query: 'torch.Tensor', key: 'torch.Tensor', value:
        'torch.Tensor', key_padding_mask: 'Optional[torch.Tensor]'=None,
        attn_mask: 'Optional[torch.Tensor]'=None) ->Tuple[torch.Tensor,
        torch.Tensor]:
        if key_padding_mask is not None:
            warnings.warn(
                "'key_padding_mask' in 'DotProductAttention' is currently an experimental version.When you use this, please check if this is working correctly or not very carefully."
                )
        if not self.batch_first:
            query = torch.transpose(query, 0, 1)
            key = torch.transpose(key, 0, 1)
            value = torch.transpose(value, 0, 1)
        bsz, _tgt_len, _ = query.size()
        q = self.fc_q(query)
        q = self.dropout(q)
        k = self.fc_k(key)
        k = self.dropout(k)
        v = self.fc_v(value)
        v = self.dropout(v)
        if k.size() != v.size():
            raise AssertionError(
                'The sizes of key and value should be the same.')
        src_len = k.size(1)
        if key_padding_mask is not None:
            if key_padding_mask.size(0) != bsz:
                raise AssertionError(
                    'The first dimension of kay padding mask size must be the same as batch size'
                    )
            if key_padding_mask.size(1) != src_len:
                raise AssertionError(
                    'The second dimension of key padding mask size must be the same as source length'
                    )
        a = torch.bmm(q, torch.transpose(k, 1, 2))
        if self.scaled:
            a /= math.sqrt(self.output_dim)
        if attn_mask is not None:
            a += attn_mask
        if key_padding_mask is not None:
            a = a.masked_fill(key_padding_mask.unsqueeze(1), float('-inf'))
        attn = self.softmax(a)
        output = torch.bmm(attn, v)
        if not self.batch_first:
            output = torch.transpose(output, 0, 1)
        return output, attn

    def generate_square_subsequent_mask(self, sz: 'int') ->torch.Tensor:
        """Generate a square mask for the sequence. The masked positions are filled with float('-inf').
        Unmasked positions are filled with float(0.0).
        """
        mask = (torch.triu(torch.ones(sz, sz)) == 1).transpose(0, 1)
        mask = mask.float().masked_fill(mask == 0, float('-inf')).masked_fill(
            mask == 1, float(0.0))
        return mask


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


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


@triton.jit
def triton_poi_fused__softmax_0(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_1(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 = tmp1 + tmp2
    tmp5 = tmp3 + tmp4
    tmp7 = tmp5 + tmp6
    tmp8 = tmp0 / tmp7
    tl.store(out_ptr0 + x2, tmp8, xmask)


def call(args):
    primals_1, primals_2, primals_3, primals_4, primals_5 = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_2, (4, 4), (4, 1))
    assert_size_stride(primals_3, (4,), (1,))
    assert_size_stride(primals_4, (4, 4, 4), (16, 4, 1))
    assert_size_stride(primals_5, (4, 4, 4), (16, 4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_3, reinterpret_tensor(primals_1, (16, 
            4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0
            ), alpha=1, beta=1, out=buf0)
        buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_3, reinterpret_tensor(primals_4, (16, 
            4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0
            ), alpha=1, beta=1, out=buf1)
        buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
        extern_kernels.addmm(primals_3, reinterpret_tensor(primals_5, (16, 
            4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0
            ), alpha=1, beta=1, out=buf2)
        del primals_2
        del primals_3
        buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        extern_kernels.bmm(reinterpret_tensor(buf0, (4, 4, 4), (16, 4, 1), 
            0), reinterpret_tensor(buf1, (4, 4, 4), (16, 1, 4), 0), out=buf3)
        buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused__softmax_0[grid(64)](buf3, buf4, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf5 = buf3
        del buf3
        triton_poi_fused__softmax_1[grid(64)](buf4, buf5, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf6 = buf4
        del buf4
        extern_kernels.bmm(buf5, reinterpret_tensor(buf2, (4, 4, 4), (16, 4,
            1), 0), out=buf6)
    return buf6, buf5, reinterpret_tensor(primals_1, (16, 4), (4, 1), 0
        ), reinterpret_tensor(primals_4, (16, 4), (4, 1), 0
        ), reinterpret_tensor(primals_5, (16, 4), (4, 1), 0
        ), buf5, reinterpret_tensor(buf2, (4, 4, 4), (16, 1, 4), 0
        ), reinterpret_tensor(buf0, (4, 4, 4), (16, 1, 4), 0
        ), reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0)


class DotProductAttentionNew(nn.Module):
    """DotProductAttention.

    .. math::

        \\mathrm{DotProductAttention}(Q, K, V) &=& \\mathrm{softmax}(qk^T) v

        q &=& QW_1 + b_1

        k &=& KW_2 + b_2

        v &=& VW_3 + b_3

    Args:
        qdim: dimension of the model, i.e., dimension of Q
        hidden_dim: dimension of hidden layer, i.e., dimension of q, k, v. Default: 512
        output_dim: dimension of output layer, i.e., dimension of output. Default: None
        dropout: a Dropout layer on attn_output_weights. Default: 0.0.
        transform: q = Q, k = K, v = V if it is False. Default: True
        bias: add bias as module parameter. Default: True.
        same_embd: W1 = W2 = W3, b1 = b2 = b3 if it is True. Default: True
        add_bias_kv: add bias to the key and value sequences at dim=0.
        kdim: total number of features in key. Default: None.
        vdim: total number of features in key. Default: None.
        Note: if kdim and vdim are None, they will be set to embed_dim such that
        query, key, and value have the same number of features.

    Examples::
        >>> attn = DotProductAttention(query_dim)
        >>> attn_output, attn_output_weights = attn(query, key, value)
    """

    def __init__(self, qdim: 'int', output_dim: 'Optional[int]'=None,
        dropout: 'float'=0.0, transform: 'bool'=True, bias: 'bool'=True,
        same_embd: 'bool'=True, add_bias_kv: 'Optional[bool]'=None, kdim:
        'Optional[int]'=None, vdim: 'Optional[int]'=None, batch_first:
        'bool'=True, scaled: 'bool'=False) ->None:
        super(DotProductAttentionNew, self).__init__()
        self.qdim: 'int' = qdim
        self.transform: 'bool' = transform
        self.bias: 'bool' = bias
        self.same_embd: 'bool' = same_embd
        self.kdim: 'int' = kdim if kdim is not None else self.qdim
        self.vdim: 'int' = vdim if vdim is not None else self.qdim
        self.output_dim: 'int' = (output_dim if output_dim is not None else
            self.vdim)
        if self.same_embd and (self.qdim != self.kdim or self.qdim != self.vdim
            ):
            raise AssertionError(
                'qdim, kdim, vdim should be the same dimensions if same_embd is True'
                )
        self.add_bias_kv: 'bool' = (add_bias_kv if add_bias_kv is not None else
            self.bias)
        if self.same_embd and self.bias != self.add_bias_kv:
            raise AssertionError(
                'bias and add_bias_kv should be the same if same_embd is True')
        self.batch_first: 'bool' = batch_first
        self.scaled: 'bool' = scaled
        self.fc_q: 'nn.Module' = nn.Linear(self.qdim, self.output_dim, bias
            =bias)
        self.fc_k: 'nn.Module'
        self.fc_v: 'nn.Module'
        if self.same_embd:
            self.fc_k = self.fc_q
            self.fc_v = self.fc_k
        else:
            self.fc_k = nn.Linear(self.kdim, self.output_dim, bias=self.
                add_bias_kv)
            self.fc_v = nn.Linear(self.vdim, self.output_dim, bias=self.
                add_bias_kv)
        self.dropout: 'nn.Module' = nn.Dropout(p=dropout)
        self.softmax: 'nn.Module' = nn.Softmax(dim=2)

    def generate_square_subsequent_mask(self, sz: 'int') ->torch.Tensor:
        """Generate a square mask for the sequence. The masked positions are filled with float('-inf').
        Unmasked positions are filled with float(0.0).
        """
        mask = (torch.triu(torch.ones(sz, sz)) == 1).transpose(0, 1)
        mask = mask.float().masked_fill(mask == 0, float('-inf')).masked_fill(
            mask == 1, float(0.0))
        return mask

    def forward(self, input_0, input_1, input_2):
        primals_2 = self.fc_q.weight
        primals_3 = self.fc_q.bias
        primals_1 = input_0
        primals_4 = input_1
        primals_5 = input_2
        output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
        return output[0], output[1]
