code: def _test_ignored_modules_transformer(
      self,
      use_orig_params: bool,
      ignore_modules: bool,  # as opposed to `ignored_states`
      use_auto_wrap: bool,
      composable: bool,
  ):
      # Initialize an FSDP-wrapped transformer model that has FSDP ignore
      # the `nn.Transformer` module's parameters
      model: nn.Module = TransformerWithSharedParams.init(
          self.process_group,
          FSDPInitMode.NO_FSDP,
          CUDAInitMode.CUDA_BEFORE,
          deterministic=True,
      )
      fsdp_kwargs = {"process_group": self.process_group}
      if use_auto_wrap:
          # Unshare the output projection weight and embedding weight to be
          # able to auto wrap every linear correctly
          model.output_proj.weight = nn.Parameter(
              model.output_proj.weight.clone()
          )
          fsdp_kwargs[
              "policy" if composable else "auto_wrap_policy"
          ] = ModuleWrapPolicy({nn.Linear})
      if ignore_modules:
          fsdp_kwargs["ignored_modules"] = [model.transformer]
      else:
          fsdp_kwargs["ignored_states"] = list(
              model.transformer.parameters()
          )
      wrapper_cls = fully_shard if composable else FSDP
      wrapped_model = wrapper_cls(model, **fsdp_kwargs)
      # Check that the wrapped model's flattened parameter does not include
      # the ignored transformer module's parameters
      nonwrapped_model: nn.Module = TransformerWithSharedParams.init(
          self.process_group,
          FSDPInitMode.NO_FSDP,
          CUDAInitMode.CUDA_BEFORE,
          deterministic=True,
      )
      if use_auto_wrap:
          nonwrapped_model.output_proj.weight = nn.Parameter(
              nonwrapped_model.output_proj.weight.clone()
          )
      total_numel = sum(
          p.numel() for p in nonwrapped_model.parameters()
      )
      ignored_numel = sum(
          p.numel() for p in nonwrapped_model.transformer.parameters()
      )
      nonignored_numel = total_numel - ignored_numel
      fsdp_managed_numel = 0
      with FSDP.summon_full_params(wrapped_model):
          for handle in traversal_utils._get_fsdp_handles(
              wrapped_model
          ):
              flat_param = handle.flat_param
              flat_param_numel = flat_param.numel()
              if composable or use_orig_params:
                  # Subtract the numel contributed from alignment padding
                  padding_numel = sum(
                      numel
                      for (numel, is_padding) in zip(
                          flat_param._numels_with_padding,
                          flat_param._is_padding_mask,
                      )
                      if is_padding
                  )
                  flat_param_numel -= padding_numel
              fsdp_managed_numel += flat_param_numel
      self.assertEqual(fsdp_managed_numel, nonignored_numel)
      # Check that we can run a few iterations
      optim = torch.optim.Adam(wrapped_model.parameters(), lr=1e-3)
      self._train_model(wrapped_model, optim, 3)
  
imports: import functools
  import math
  import sys
  import torch
  import torch.distributed.fsdp._traversal_utils
  import torch.nn
  from torch import distributed
  from torch.distributed._composable import fully_shard
  from torch.distributed.fsdp import FullyShardedDataParallel
  from torch.distributed.fsdp._common_utils import _get_module_fsdp_state
  from torch.distributed.fsdp.wrap import ModuleWrapPolicy, transformer_auto_wrap_policy
  from torch.testing._internal.common_distributed import skip_if_lt_x_gpu
  from torch.testing._internal.common_fsdp import CUDAInitMode, FSDPInitMode, FSDPTest, TransformerWithSharedParams
  from torch.testing._internal.common_utils import instantiate_parametrized_tests, parametrize, run_tests, TEST_WITH_DEV_DBG_ASAN
label_desc: Use image node_id 5 for calling the TestFSDPIgnoredModules obj's underlying member method code with example usage: obj._test_ignored_modules_transformer(use_orig_params, ignore_modules, use_auto_wrap, composable) without return types