docstr: GridNetBlock Forward.
  
  Args:
      x: [B, C, T, Q]
      out: [B, C, T, Q]
docstr_tok: ["GridNetBlock","Forward",".","Args",":","x",":","[","B",",","C",",","T",",","Q","]","out",":","[","B",",","C",",","T",",","Q","]"]
code: def forward(self, x):
      """GridNetBlock Forward.
  
      Args:
          x: [B, C, T, Q]
          out: [B, C, T, Q]
      """
      B, C, old_T, old_Q = x.shape
      T = (
          math.ceil((old_T - self.emb_ks) / self.emb_hs) * self.emb_hs
          + self.emb_ks
      )
      Q = (
          math.ceil((old_Q - self.emb_ks) / self.emb_hs) * self.emb_hs
          + self.emb_ks
      )
      x = F.pad(x, (0, Q - old_Q, 0, T - old_T))
  
      # intra RNN
      input_ = x
      intra_rnn = self.intra_norm(input_)  # [B, C, T, Q]
      intra_rnn = (
          intra_rnn.transpose(1, 2).contiguous().view(B * T, C, Q)
      )  # [BT, C, Q]
      intra_rnn = F.unfold(
          intra_rnn[..., None],
          (self.emb_ks, 1),
          stride=(self.emb_hs, 1),
      )  # [BT, C*emb_ks, -1]
      intra_rnn = intra_rnn.transpose(1, 2)  # [BT, -1, C*emb_ks]
      intra_rnn, _ = self.intra_rnn(intra_rnn)  # [BT, -1, H]
      intra_rnn = intra_rnn.transpose(1, 2)  # [BT, H, -1]
      intra_rnn = self.intra_linear(intra_rnn)  # [BT, C, Q]
      intra_rnn = intra_rnn.view([B, T, C, Q])
      intra_rnn = intra_rnn.transpose(1, 2).contiguous()  # [B, C, T, Q]
      intra_rnn = intra_rnn + input_  # [B, C, T, Q]
  
      # inter RNN
      input_ = intra_rnn
      inter_rnn = self.inter_norm(input_)  # [B, C, T, F]
      inter_rnn = (
          inter_rnn.permute(0, 3, 1, 2).contiguous().view(B * Q, C, T)
      )  # [BF, C, T]
      inter_rnn = F.unfold(
          inter_rnn[..., None],
          (self.emb_ks, 1),
          stride=(self.emb_hs, 1),
      )  # [BF, C*emb_ks, -1]
      inter_rnn = inter_rnn.transpose(1, 2)  # [BF, -1, C*emb_ks]
      inter_rnn, _ = self.inter_rnn(inter_rnn)  # [BF, -1, H]
      inter_rnn = inter_rnn.transpose(1, 2)  # [BF, H, -1]
      inter_rnn = self.inter_linear(inter_rnn)  # [BF, C, T]
      inter_rnn = inter_rnn.view([B, Q, C, T])
      inter_rnn = inter_rnn.permute(
          0, 2, 3, 1
      ).contiguous()  # [B, C, T, Q]
      inter_rnn = inter_rnn + input_  # [B, C, T, Q]
  
      # attention
      inter_rnn = inter_rnn[..., :old_T, :old_Q]
      batch = inter_rnn
  
      all_Q, all_K, all_V = [], [], []
      for ii in range(self.n_head):
          all_Q.append(
              self["attn_conv_Q_%d" % ii](batch)
          )  # [B, C, T, Q]
          all_K.append(
              self["attn_conv_K_%d" % ii](batch)
          )  # [B, C, T, Q]
          all_V.append(
              self["attn_conv_V_%d" % ii](batch)
          )  # [B, C, T, Q]
  
      Q = torch.cat(all_Q, dim=0)  # [B', C, T, Q]
      K = torch.cat(all_K, dim=0)  # [B', C, T, Q]
      V = torch.cat(all_V, dim=0)  # [B', C, T, Q]
  
      Q = Q.transpose(1, 2)
      Q = Q.flatten(start_dim=2)  # [B', T, C*Q]
      K = K.transpose(1, 2)
      K = K.flatten(start_dim=2)  # [B', T, C*Q]
      V = V.transpose(1, 2)  # [B', T, C, Q]
      old_shape = V.shape
      V = V.flatten(start_dim=2)  # [B', T, C*Q]
      emb_dim = Q.shape[-1]
  
      attn_mat = torch.matmul(Q, K.transpose(1, 2)) / (
          emb_dim**0.5
      )  # [B', T, T]
      attn_mat = F.softmax(attn_mat, dim=2)  # [B', T, T]
      V = torch.matmul(attn_mat, V)  # [B', T, C*Q]
  
      V = V.reshape(old_shape)  # [B', T, C, Q]
      V = V.transpose(1, 2)  # [B', C, T, Q]
      emb_dim = V.shape[1]
  
      batch = V.view(
          [self.n_head, B, emb_dim, old_T, -1]
      )  # [n_head, B, C, T, Q])
      batch = batch.transpose(0, 1)  # [B, n_head, C, T, Q])
      batch = batch.contiguous().view(
          [B, self.n_head * emb_dim, old_T, -1]
      )  # [B, C, T, Q])
      batch = self["attn_concat_proj"](batch)  # [B, C, T, Q])
  
      out = batch + inter_rnn
      return out
  
imports: import math
  from collections import OrderedDict
  from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.nn import init
  from torch.nn.parameter import Parameter
  from espnet2.enh.decoder.stft_decoder import STFTDecoder
  from espnet2.enh.encoder.stft_encoder import STFTEncoder
  from espnet2.enh.layers.complex_utils import new_complex_like
  from espnet2.enh.separator.abs_separator import AbsSeparator
  from espnet2.torch_utils.get_layer_from_string import get_layer
label_desc: Use image node_id 3 for calling the GridNetBlock obj's underlying member method code with example usage: obj.forward(x) and returns: out