code: def test_sharding_plan_errors(self):
      rowwise_sharding_spec = generate_chunk_sharding_specs_for_test(1)[
          0
      ]
      sharding_plan_wrong_plan = ShardingPlan(
          plan={
              "fc1.weight": torch.randn(3, 4),
          },
          output_plan={"": rowwise_sharding_spec},
      )
  
      megatron_lm = SimpleMegatronLM([[17, 12], [12, 29]]).cuda(
          self.rank
      )
  
      with self.assertRaisesRegex(
          TypeError,
          "Only `ShardingSpec` and `Sharder` are supported to shard",
      ):
          # shard the module with the provided sharding plan
          shard_module(megatron_lm, sharding_plan_wrong_plan)
  
      sharding_plan_wrong_output_plan = ShardingPlan(
          plan={
              "fc1.weight": rowwise_sharding_spec,
          },
          output_plan={"": torch.randn(3, 4)},
      )
  
      with self.assertRaisesRegex(
          TypeError, "Only `ShardingSpec` is supported as output_plan"
      ):
          # shard the module with the provided sharding plan
          shard_module(megatron_lm, sharding_plan_wrong_output_plan)
  
      sharding_plan_wrong_module_path = ShardingPlan(
          plan={
              "fc3.weight": rowwise_sharding_spec,
          },
      )
      with self.assertRaisesRegex(AttributeError, "has no attribute"):
          # shard the module with the provided sharding plan
          shard_module(megatron_lm, sharding_plan_wrong_module_path)
  
      sharding_plan_wrong_param_path = ShardingPlan(
          plan={
              "fc1.biass": rowwise_sharding_spec,
          },
      )
      with self.assertRaisesRegex(AttributeError, "has no attribute"):
          # shard the module with the provided sharding plan
          shard_module(megatron_lm, sharding_plan_wrong_param_path)
  
imports: import sys
  import torch
  import torch.nn
  import torch.distributed
  from torch.testing._internal.common_distributed import requires_nccl, skip_if_lt_x_gpu
  from torch.distributed._shard import shard_module
  from torch.distributed._shard.sharding_plan import ShardingPlan, ShardingPlanner
  from torch.distributed._shard.sharding_spec import ChunkShardingSpec
  from torch.distributed._shard.sharded_tensor import ShardedTensor
  from torch.testing._internal.common_utils import TEST_WITH_DEV_DBG_ASAN, run_tests
  from torch.testing._internal.distributed._shard.sharded_tensor import TEST_GPU_NUM, ShardedTensorTestBase, with_comms
  from torch.testing._internal.distributed._shard.sharded_tensor._test_ops_common import generate_chunk_sharding_specs_for_test
  from torch.testing._internal.distributed._shard.test_common import SimpleMegatronLM
label_desc: Use image node_id 1 for calling the TestShardingPlan obj's underlying member method code with example usage: obj.test_sharding_plan_errors() without return types