code: def convert_to_weak_tensor_or_tensor(t, to_weak):
      if to_weak:
          return WeakTensor.from_tensor(t)
      # We should return a normal Tensor because is_weak = False.
      if isinstance(t, WeakTensor):
          return t.tensor
      return t
  
imports: from typing import Optional
  import numpy
  from tensorflow.python.eager import context
  from tensorflow.python.framework import composite_tensor_gradient
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import extension_type
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor
  from tensorflow.python.framework import tensor_conversion_registry
  from tensorflow.python.types import core
label_desc: Use image node_id 1 for calling a global function with example usage: convert_to_weak_tensor_or_tensor(t, to_weak) and returns: t, WeakTensor, t