code: def linear_attention(q: Tensor, k: Tensor, v: Tensor) -> Tensor:
      r"""Efficient attention mechanism from the
      `"Rethinking Attention with Performers"
      <https://arxiv.org/abs/2009.14794>`_ paper.
  
      .. math::
          \mathbf{\hat{D}}^{-1}(\mathbf{Q}'((\mathbf{K}')^{\top} \mathbf{V}))
  
      """
      D_inv = 1.0 / (q @ k.sum(dim=-2).unsqueeze(-1))
      kv = k.transpose(-2, -1) @ v
      qkv = q @ kv
      out = torch.einsum("...L,...Ld->...Ld", D_inv.squeeze(-1), qkv)
      return out
  
file_path: pytorch_geometric/torch_geometric/nn/attention/performer.py
imports: import math
  from typing import Callable, Optional
  import torch
  from torch import Tensor
label_desc: Use image node_id 3 for calling a global function with example usage: linear_attention(q, k, v) and returns: out