class_docstr: Base class for distributed computation models and defines interface methods.
  This class is public and should be used for other custom derived distributed models.
class_docstr_tok: ["Base","class","for","distributed","computation","models","and","defines","interface","methods",".","This","class","is","public","and","should","be","used","for","other","custom","derived","distributed","models","."]
code: def _collective_op(
      self,
      tensor: Union[torch.Tensor, Number, str],
      fn: Callable,
      *args: Any,
      **kwargs: Any,
  ) -> Union[torch.Tensor, float, List[float], List[str]]:
      tensor_to_number = tensor_to_str = False
      device = self.device()
      if isinstance(tensor, (Number, float)):
          tensor_to_number = True
          dtype = self._collective_op_dtype
          if dtype is None and isinstance(tensor, float):
              dtype = torch.double
          tensor = torch.tensor(tensor, device=device, dtype=dtype)
      elif isinstance(tensor, str):
          tensor_to_str = True
          max_length = self._get_max_length(tensor, device)
          tensor = self._encode_str(tensor, device, size=max_length)
  
      tensor = self._apply_op(tensor, device, fn, *args, **kwargs)
  
      if tensor_to_number:
          return tensor.tolist()
      elif tensor_to_str:
          return self._decode_str(tensor)
      return tensor
  
imports: from abc import ABCMeta, abstractmethod
  from numbers import Number
  from typing import Any, Callable, cast, List, Optional, Union
  import torch
  from packaging.version import Version
label_desc: Use image node_id 23 for calling the ComputationModel obj's underlying member method code with example usage: obj._collective_op(tensor, fn) and returns: tensor, tensor, self