code: def build_fourier_pos_embed(
      feat_shape: List[int],
      bands: Optional[torch.Tensor] = None,
      num_bands: int = 64,
      max_res: int = 224,
      linear_bands: bool = False,
      include_grid: bool = False,
      concat_out: bool = True,
      in_pixels: bool = True,
      dtype: torch.dtype = torch.float32,
      device: Optional[torch.device] = None,
  ) -> List[torch.Tensor]:
      if bands is None:
          if in_pixels:
              bands = pixel_freq_bands(
                  num_bands,
                  float(max_res),
                  linear_bands=linear_bands,
                  dtype=dtype,
                  device=device,
              )
          else:
              bands = inv_freq_bands(
                  num_bands, step=1, dtype=dtype, device=device
              )
      else:
          if device is None:
              device = bands.device
          if dtype is None:
              dtype = bands.dtype
  
      if in_pixels:
          grid = torch.stack(
              torch.meshgrid(
                  [
                      torch.linspace(
                          -1.0, 1.0, steps=s, device=device, dtype=dtype
                      )
                      for s in feat_shape
                  ]
              ),
              dim=-1,
          )
      else:
          grid = torch.stack(
              torch.meshgrid(
                  [
                      torch.arange(s, device=device, dtype=dtype)
                      for s in feat_shape
                  ]
              ),
              dim=-1,
          )
      grid = grid.unsqueeze(-1)
      pos = grid * bands
  
      pos_sin, pos_cos = pos.sin(), pos.cos()
      out = (
          (grid, pos_sin, pos_cos)
          if include_grid
          else (pos_sin, pos_cos)
      )
      # FIXME torchscript doesn't like multiple return types, probably need to always cat?
      if concat_out:
          out = torch.cat(out, dim=-1)
      return out
  
imports: import math
  import warnings
  from collections import OrderedDict
  from typing import List, Optional, Tuple, Union
  import torch
  import torch.nn
  from torch import nn
  from lavis.models.clip_models.utils import freeze_batch_norm_2d
label_desc: Use image node_id 4 for calling a global function with example usage: build_fourier_pos_embed(feat_shape, bands, num_bands, max_res, linear_bands, include_grid, concat_out, in_pixels, dtype, device) and returns: out