code: def grad_enabled_forward(self, samples: NestedTensor):
      """
      Adapted from DETR source: https://github.com/facebookresearch/detr
      (detr/models/detr.py)
      """
  
      if isinstance(samples, (list, torch.Tensor)):
          samples = nested_tensor_from_tensor_list(samples)
      features, pos = self.backbone(samples)
      src, mask = features[-1].decompose()
      assert mask is not None
      h_s = self.transformer(
          self.input_proj(src), mask, self.query_embed.weight, pos[-1]
      )[0]
      outputs_class = self.class_embed(h_s)
      outputs_coord = self.bbox_embed(h_s).sigmoid()
      out = {
          "pred_logits": outputs_class[-1],
          "pred_boxes": outputs_coord[-1],
      }
      if self.aux_loss:
          out["aux_outputs"] = self._set_aux_loss(
              outputs_class, outputs_coord
          )  # pylint: disable=W0212
      return out
  
imports: from typing import List, Optional, Tuple, Union
  import torch
label_desc: Use image node_id 8 for calling a global function with example usage: grad_enabled_forward(samples) and returns: out