docstr: Tests that FSDP errors if the all-gather order differs across ranks
  in the first iteration.
docstr_tok: ["Tests","that","FSDP","errors","if","the","all-gather","order","differs","across","ranks","in","the","first","iteration","."]
code: def test_invalid_first_iter_order(
      self,
      sharding_strategy: ShardingStrategy,
  ):
      """Tests that FSDP errors if the all-gather order differs across ranks
      in the first iteration."""
      # Rank 0 runs the forward pass in one order and all other ranks run in
      # different order
      dist.set_debug_level(dist.DebugLevel.DETAIL)
      fsdp_model = Model.wrap(sharding_strategy, self.device)
      if self.rank != 0:
          fsdp_model.flip_path()
      inp = fsdp_model.module.get_input(self.device)
      # Match the error message with the following prefix
      error_regex = "^(Forward order differs across ranks)"
      with self.assertRaisesRegex(RuntimeError, error_regex):
          fsdp_model(*inp)
  
imports: import sys
  import warnings
  from contextlib import nullcontext
  import torch
  from torch import distributed
  from torch.distributed.fsdp import FullyShardedDataParallel
  from torch.distributed.fsdp.fully_sharded_data_parallel import ShardingStrategy
  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 instantiate_parametrized_tests, parametrize, run_tests, TEST_WITH_DEV_DBG_ASAN
label_desc: Use image node_id 3 for calling the TestFSDPExecOrder obj's underlying member method code with example usage: obj.test_invalid_first_iter_order(sharding_strategy) without return types