class_docstr: Tests ``fully_shard`` initialization.
class_docstr_tok: ["Tests","``","fully_shard","``","initialization","."]
docstr: Tests passing ``sync_module_states=True``.
docstr_tok: ["Tests","passing","``","sync_module_states=True","``","."]
code: def test_sync_module_states(self):
      """Tests passing ``sync_module_states=True``."""
      local_model = CompositeParamModel(device=torch.device("cuda"))
      composable_module = copy.deepcopy(local_model)
      # Check that the parameters are broadcast from rank 0 by comparing
      # against an equivalent FSDP-wrapped module
      if self.rank != 0:
          for param in composable_module.parameters():
              with torch.no_grad():
                  param.zero_()
      policy = ModuleWrapPolicy({UnitModule})
      fsdp_wrapped_model = FSDP(
          copy.deepcopy(local_model),
          auto_wrap_policy=policy,
          use_orig_params=True,
      )
      fully_shard(
          composable_module,
          policy=policy,
          sync_module_states=True,
      )
      for composable_param, fsdp_wrapped_param in zip(
          composable_module.parameters(),
          fsdp_wrapped_model.parameters(),
      ):
          self.assertEqual(composable_param, fsdp_wrapped_param)
  
imports: import copy
  import sys
  from typing import Optional
  import torch
  import torch.distributed
  import torch.distributed.fsdp._traversal_utils
  import torch.nn
  from torch.distributed._composable import fully_shard
  from torch.distributed.fsdp import BackwardPrefetch, FullyShardedDataParallel
  from torch.distributed.fsdp._common_utils import _is_fsdp_flattened, clean_tensor_name
  from torch.distributed.fsdp.wrap import _Policy, CustomPolicy, ModuleWrapPolicy
  from torch.testing._internal.common_dist_composable import CompositeParamModel, FakeSequential, NestedSequentialModel, UnitModule
  from torch.testing._internal.common_distributed import skip_if_lt_x_gpu
  from torch.testing._internal.common_fsdp import FSDPTest
  from torch.testing._internal.common_utils import run_tests, TEST_WITH_DEV_DBG_ASAN
label_desc: Use image node_id 7 for calling the TestInitialization obj's underlying member method code with example usage: obj.test_sync_module_states() without return types