code: def _test_fp16_dtypes(
      self,
      to_half_before_fsdp_init: bool,
      use_orig_params: bool,
      mixed_precision: MixedPrecision,
  ):
      model = NestedWrappedModule.init(
          self.process_group,
          FSDPInitMode.NO_FSDP,
          CUDAInitMode.CUDA_NEVER,
          {},
      )
      fsdp_kwargs = {
          "use_orig_params": use_orig_params,
          "device_id": torch.cuda.current_device(),
          "mixed_precision": mixed_precision,
      }
      if to_half_before_fsdp_init:
          model = model.half()
      fsdp_model = FSDP(model, **fsdp_kwargs)
      if not to_half_before_fsdp_init:
          fsdp_model = fsdp_model.half()
      for param in fsdp_model.parameters():
          self.assertEqual(param.dtype, torch.float16)
      inp = tuple(
          t.half() if torch.is_tensor(t) else t
          for t in fsdp_model.module.get_input(torch.device("cuda"))
      )
      out = fsdp_model(*inp)
      out.sum().backward()
  
      # Check handle dtype attributes
      for handle in traversal_utils._get_fsdp_handles(fsdp_model):
          self.assertEqual(handle.flat_param.dtype, torch.float16)
          self.assertEqual(handle.flat_param.grad.dtype, torch.float16)
          self.assertEqual(handle._orig_param_dtype, torch.float16)
          # Specifying `mixed_precision` takes precedence over the model
          # dtype for both `param_dtype` and `reduce_dtype`
          if mixed_precision.param_dtype is not None:
              self.assertEqual(
                  handle._fwd_bwd_param_dtype,
                  mixed_precision.param_dtype,
              )
          else:
              self.assertEqual(
                  handle._fwd_bwd_param_dtype, torch.float16
              )
          if mixed_precision.reduce_dtype is not None:
              self.assertEqual(
                  handle._reduce_dtype, mixed_precision.reduce_dtype
              )
          elif (
              mixed_precision.reduce_dtype is None
              and mixed_precision.param_dtype is not None
          ):
              # Special case: infer reduce dtype from parameter dtype
              self.assertEqual(
                  handle._reduce_dtype, mixed_precision.param_dtype
              )
          else:
              self.assertEqual(handle._reduce_dtype, torch.float16)
  
      # Check parameter/gradient dtypes
      for param in fsdp_model.parameters():
          self.assertEqual(param.dtype, torch.float16)
          if param.grad is not None:
              self.assertEqual(param.grad.dtype, torch.float16)
  
file_path: pytorch/test/distributed/fsdp/test_fsdp_pure_fp16.py
imports: import sys
  import torch
  import torch.distributed.fsdp._traversal_utils
  from torch import distributed
  from torch.distributed.fsdp import CPUOffload, FullyShardedDataParallel, MixedPrecision
  from torch.testing._internal.common_distributed import skip_if_lt_x_gpu
  from torch.testing._internal.common_fsdp import CUDAInitMode, FSDPInitMode, FSDPTest, NestedWrappedModule
  from torch.testing._internal.common_utils import instantiate_parametrized_tests, run_tests, TEST_WITH_DEV_DBG_ASAN
label_desc: Use image node_id 5 for calling the TestPureFP16 obj's underlying member method code with example usage: obj._test_fp16_dtypes(to_half_before_fsdp_init, use_orig_params, mixed_precision) without return types