code: def forward(
      self,
      tgt: Tensor,
      ref_points_unact: Tensor,
      memory: Tensor,
      memory_spatial_shapes: list[tuple[int, int]],
      memory_level_start_index: list[int],
      bbox_head: nn.ModuleList,
      score_head: nn.ModuleList,
      query_pos_head: nn.Module,
      attn_mask: Optional[Tensor] = None,
      memory_mask: Optional[Tensor] = None,
  ) -> tuple[Tensor, Tensor]:
      output: Tensor = tgt
      dec_out_bboxes: list[Tensor] = []
      dec_out_logits: list[Tensor] = []
      ref_points_detach = torch.sigmoid(ref_points_unact)
  
      for i, layer in enumerate(self.layers):
          ref_points_input = ref_points_detach.unsqueeze(2)
          query_pos_embed: Tensor = query_pos_head(ref_points_detach)
  
          output = layer(
              output,
              ref_points_input,
              memory,
              memory_spatial_shapes,
              memory_level_start_index,
              attn_mask,
              memory_mask,
              query_pos_embed,
          )
  
          inter_ref_bbox = torch.sigmoid(
              bbox_head[i](output) + _inverse_sigmoid(ref_points_detach)
          )
  
          # TODO: will be supported later
          # if self.training:
          #    dec_out_logits.append(score_head[i](output))
          #    if i == 0:
          #        dec_out_bboxes.append(inter_ref_bbox)
          #    else:
          #        dec_out_bboxes.append(torch.sigmoid(bbox_head[i](output) + _inverse_sigmoid(ref_points)))
          # elif i == self.eval_idx:
          #    dec_out_logits.append(score_head[i](output))
          #    dec_out_bboxes.append(inter_ref_bbox)
          #    break
          if i == self.eval_idx:
              dec_out_logits.append(score_head[i](output))
              dec_out_bboxes.append(inter_ref_bbox)
              break
  
          # ref_points_detach = inter_ref_bbox.detach(
          # ) if self.training else inter_ref_bbox
          ref_points_detach = inter_ref_bbox
  
      return torch.stack(dec_out_bboxes), torch.stack(dec_out_logits)
  
imports: from __future__ import annotations
  from typing import Optional
  import torch
  from torch import nn
  from kornia.contrib.models.common import MLP, ConvNormAct
  from kornia.core import Module, Tensor, concatenate
label_desc: Use image node_id 2 for calling the TransformerDecoder obj's underlying member method code with example usage: obj.forward(tgt, ref_points_unact, memory, memory_spatial_shapes, memory_level_start_index, bbox_head, score_head, query_pos_head, attn_mask, memory_mask) and returns: torch,  torch