class_docstr: Communication spec is used to record the communication action. It has two main functions:
  1. Compute the communication cost which will be used in auto parallel solver.
  2. Convert the communication spec to real action which will be used in runtime.
  It contains comm_pattern to determine the
  communication method, sharding_spec to determine the communication size, gather_dim and shard_dim
  to determine the buffer shape, and logical_process_axis
  
  Argument:
      comm_pattern(CollectiveCommPattern): describe the communication method used in this spec.
      sharding_spec(ShardingSpec): This is sharding spec of the tensor which will join the communication action.
      gather_dim(int, Optional): The gather_dim of the tensor will be gathered.
      shard_dim(int, Optional): The shard_dim of the tensor will be sharded.
      logical_process_axis(Union(int, List[int]), Optional): The mesh_dim to implement the communication action.
class_docstr_tok: ["Communication","spec","is","used","to","record","the","communication","action",".","It","has","two","main","functions",":","1",".","Compute","the","communication","cost","which","will","be","used","in","auto","parallel","solver",".","2",".","Convert","the","communication","spec","to","real","action","which","will","be","used","in","runtime",".","It","contains","comm_pattern","to","determine","the","communication","method",",","sharding_spec","to","determine","the","communication","size",",","gather_dim","and","shard_dim","to","determine","the","buffer","shape",",","and","logical_process_axis","Argument",":","comm_pattern","(","CollectiveCommPattern",")",":","describe","the","communication","method","used","in","this","spec",".","sharding_spec","(","ShardingSpec",")",":","This","is","sharding","spec","of","the","tensor","which","will","join","the","communication","action",".","gather_dim","(","int",",","Optional",")",":","The","gather_dim","of","the","tensor","will","be","gathered",".","shard_dim","(","int",",","Optional",")",":","The","shard_dim","of","the","tensor","will","be","sharded",".","logical_process_axis","(","Union","(","int",",","List","[","int","]",")",",","Optional",")",":","The","mesh_dim","to","implement","the","communication","action","."]
docstr: Convert CommSpec into runtime action, implement real collection communication to target tensor.
  The collection communication action is directed by the CommSpec.
  
  Argument:
      tensor(torch.Tensor): Tensor stored in each device, which could be different in different ranks.
code: def covert_spec_to_action(self, tensor):
      """
      Convert CommSpec into runtime action, implement real collection communication to target tensor.
      The collection communication action is directed by the CommSpec.
  
      Argument:
          tensor(torch.Tensor): Tensor stored in each device, which could be different in different ranks.
      """
      if self.comm_pattern in pattern_to_func_dict:
          tensor = pattern_to_func_dict[self.comm_pattern](tensor, self)
      else:
          tensor = tensor
      return tensor
  
imports: import operator
  from enum import Enum
  from functools import reduce
  import torch
  import torch.distributed
  from torch.distributed import ReduceOp
label_desc: Use image node_id 4 for calling the CommSpec obj's underlying member method code with example usage: obj.covert_spec_to_action(tensor) and returns: tensor