code: def cast_tensor_to_fp16(tensor: torch.Tensor) -> torch.Tensor:
      if isinstance(tensor, StatefulTensor):
          tensor = tensor.payload
      if (
          torch.is_floating_point(tensor)
          and tensor.dtype is torch.float32
      ):
          return tensor.half()
      return tensor
  
file_path: ColossalAI/colossalai/legacy/zero/sharded_model/_utils.py
imports: from typing import Any, Callable, List, Tuple, Union
  import torch
  import torch.nn.functional
  from colossalai.legacy.zero.gemini.stateful_tensor import StatefulTensor
label_desc: Use image node_id 4 for calling a global function with example usage: cast_tensor_to_fp16(tensor) and returns: tensor, tensor