code: def attention_pool(
      tensor, pool, thw_shape, has_cls_embed=True, norm=None
  ):
      if pool is None:
          return tensor, thw_shape
      tensor_dim = tensor.ndim
      if tensor_dim == 4:
          pass
      elif tensor_dim == 3:
          tensor = tensor.unsqueeze(1)
      else:
          raise NotImplementedError(
              f"Unsupported input dimension {tensor.shape}"
          )
  
      if has_cls_embed:
          cls_tok, tensor = tensor[:, :, :1, :], tensor[:, :, 1:, :]
  
      B, N, L, C = tensor.shape
      T, H, W = thw_shape
      tensor = (
          tensor.reshape(B * N, T, H, W, C)
          .permute(0, 4, 1, 2, 3)
          .contiguous()
      )
  
      tensor = pool(tensor)
  
      thw_shape = [tensor.shape[2], tensor.shape[3], tensor.shape[4]]
      L_pooled = tensor.shape[2] * tensor.shape[3] * tensor.shape[4]
      tensor = tensor.reshape(B, N, C, L_pooled).transpose(2, 3)
      if has_cls_embed:
          tensor = torch.cat((cls_tok, tensor), dim=2)
      if norm is not None:
          tensor = norm(tensor)
      # Assert tensor_dim in [3, 4]
      if tensor_dim == 4:
          pass
      else:  #  tensor_dim == 3:
          tensor = tensor.squeeze(1)
      return tensor, thw_shape
  
file_path: SlowFast/slowfast/models/attention.py
imports: import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.nn.init import trunc_normal_
  from slowfast.models.common import DropPath, Mlp
label_desc: Use image node_id 1 for calling a global function with example usage: attention_pool(tensor, pool, thw_shape, has_cls_embed, norm) and returns: tensor,  thw_shape, tensor,  thw_shape