code: def forward(self, x, mask_features):
      # x is a list of multi-scale feature
      assert len(x) == self.num_feature_levels
      src = []
      pos = []
      size_list = []
  
      for i in range(self.num_feature_levels):
          size_list.append(x[i].shape[-2:])
          pos.append(self.pe_layer(x[i], None).flatten(2))
          src.append(
              self.input_proj[i](x[i]).flatten(2)
              + self.level_embed.weight[i][None, :, None]
          )
          pos[-1] = pos[-1].transpose((0, 2, 1))
          src[-1] = src[-1].transpose((0, 2, 1))
  
      bs = src[0].shape[0]
  
      # QxNxC
      query_embed = paddle.tile(
          self.query_embed.weight.unsqueeze(0), (bs, 1, 1)
      )
      output = paddle.tile(
          self.query_feat.weight.unsqueeze(0), (bs, 1, 1)
      )
  
      predictions_class = []
      predictions_mask = []
  
      # Prediction heads on learnable query features
      (
          outputs_class,
          outputs_mask,
          attn_mask,
      ) = self.forward_prediction_heads(
          output, mask_features, attn_mask_target_size=size_list[0]
      )
      predictions_class.append(outputs_class)
      predictions_mask.append(outputs_mask)
  
      for i in range(self.num_layers):
          level_index = i % self.num_feature_levels
          # XXX: Since Paddle boolean tensor does not support masked assign
          attn_mask = attn_mask.astype("int32")
          all_zero_mask = attn_mask.sum(-1, keepdim=True) == 0
          all_zero_mask = paddle.tile(
              all_zero_mask.detach(), (1, 1, attn_mask.shape[-1])
          )
          # If a query associates with a all-zero mask, do not use masked attention
          attn_mask = paddle.where(
              all_zero_mask, paddle.ones_like(attn_mask), attn_mask
          )
          attn_mask = attn_mask.astype("bool")
  
          # NOTE: cross-attention first
          # In paddle.nn.MultiHeadAttention, attn_mask==0 indicates an unwanted position
          output = self.transformer_cross_attention_layers[i](
              output,
              src[level_index],
              memory_mask=attn_mask,
              pos=pos[level_index],
              query_pos=query_embed,
          )
  
          output = self.transformer_self_attention_layers[i](
              output, tgt_mask=None, query_pos=query_embed
          )
  
          # FFN
          output = self.transformer_ffn_layers[i](output)
  
          (
              outputs_class,
              outputs_mask,
              attn_mask,
          ) = self.forward_prediction_heads(
              output,
              mask_features,
              attn_mask_target_size=size_list[
                  (i + 1) % self.num_feature_levels
              ],
          )
          predictions_class.append(outputs_class)
          predictions_mask.append(outputs_mask)
  
      assert len(predictions_class) == self.num_layers + 1
  
      return (
          predictions_class[-1],
          predictions_mask[-1],
          predictions_class[:-1],
          predictions_mask[:-1],
      )
  
imports: import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddleseg.cvlibs import param_init
  from paddlepanseg.models.param_init import c2_xavier_fill, THLinearInitMixin, th_linear_fill, th_multihead_fill
  from .common import Conv2D, PositionEmbeddingSine
label_desc: Use image node_id 3 for calling the MultiScaleMaskedTransformerDecoder obj's underlying member method code with example usage: obj.forward(x, mask_features) and returns: predictions_class,  predictions_mask,  predictions_class,  predictions_mask