code: def _basic_validation(op, args=(), kwargs=None):
      """
      Common validation across all ops go in here.
      """
      from torch.distributed._shard.sharded_tensor import ShardedTensor
  
      if len(args) == 0 and (kwargs is None or len(kwargs) == 0):
          raise ValueError(f" No input for '{op.__name__}'!")
  
      # Validate types
      has_distributed_tensor = False
  
      def is_distributed_tensor(e):
          nonlocal has_distributed_tensor
          if isinstance(e, ShardedTensor):
              has_distributed_tensor = True
  
      pytree.tree_map_(is_distributed_tensor, args)
      pytree.tree_map_(is_distributed_tensor, kwargs)
  
      if not has_distributed_tensor:
          raise TypeError(
              f"torch function '{op.__name__}', with args: {args} and "
              f"kwargs: {kwargs} are called without any distributed tensor!"
          )
  
      # Validate all distributed tensors use the same PG.
      cur_pg: Optional[torch.distributed.ProcessGroup] = None
  
      def validate_pg(e):
          nonlocal cur_pg
          if isinstance(e, ShardedTensor):
              if cur_pg is not None and e._process_group is not cur_pg:
                  raise RuntimeError(
                      "All distributed tensors should use the "
                      "same ProcessGroup if used together in an op."
                  )
              cur_pg = e._process_group
  
      pytree.tree_map_(validate_pg, args)
      pytree.tree_map_(validate_pg, kwargs)
  
imports: import torch
  from torch.utils import _pytree
  from typing import Optional
label_desc: Use image node_id 1 for calling a global function with example usage: _basic_validation(op, args, kwargs) without return types