code: def forward(
      self,
      hidden_states: torch.Tensor,
      output_hidden_states: Optional[bool] = None,
      return_dict: Optional[bool] = None,
  ) -> Union[tuple, BaseModelOutputWithNoAttention]:
      output_hidden_states = (
          output_hidden_states
          if output_hidden_states is not None
          else self.config.output_hidden_states
      )
      return_dict = (
          return_dict
          if return_dict is not None
          else self.config.use_return_dict
      )
  
      all_hidden_states = (
          (hidden_states,) if output_hidden_states else None
      )
  
      for block in self.network:
          hidden_states = block(hidden_states)
          if output_hidden_states:
              all_hidden_states = all_hidden_states + (hidden_states,)
  
      if not return_dict:
          return tuple(
              v
              for v in [hidden_states, all_hidden_states]
              if v is not None
          )
  
      return BaseModelOutputWithNoAttention(
          last_hidden_state=hidden_states,
          hidden_states=all_hidden_states,
      )
  
imports: import collections.abc
  from typing import Optional, Tuple, Union
  import torch
  import torch.utils.checkpoint
  from torch import nn
  from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
  from ...activations import ACT2CLS
  from ...modeling_outputs import BaseModelOutputWithNoAttention, ImageClassifierOutputWithNoAttention
  from ...modeling_utils import PreTrainedModel
  from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
  from .configuration_swiftformer import SwiftFormerConfig
label_desc: Use image node_id 2 for calling the SwiftFormerEncoder obj's underlying member method code with example usage: obj.forward(hidden_states, output_hidden_states, return_dict) and returns: BaseModelOutputWithNoAttention, tuple