code: def _create_stack(
      max_stack_depth, value, safety_checks=True, name=None
  ):
      """Creates a new Stack instance.
  
      Args:
        max_stack_depth: A scalar int `Tensor` indicating the depth of stack we
            should pre-allocate.
        value: A batched `Tensor` giving the shape of a batch of values in a
            single stack frame.
        safety_checks: Python `bool` indicating whether we must use runtime
          assertions to detect stack overflow/underflow.
        name: Optional name for this op.
  
      Returns:
        stack: An initialized Stack object.
      """
      with tf.name_scope(name or "Stack.initialize"):
          value = tf.convert_to_tensor(value=value, name="value")
          batch_size = _get_leftmost_dim_size(value)
          # Home the stack index in the same memory space as the value.  The
          # convention on GPU is that int32 are in host memory and int64 are in device
          # memory.
          stack_index_dtype = (
              tf.int64 if value.dtype != tf.int32 else tf.int32
          )
          stack_index = tf.zeros(
              [batch_size], dtype=stack_index_dtype, name="stack_index"
          )
          stack = tf.zeros(
              shape=tf.concat(
                  [
                      [max_stack_depth * batch_size],
                      tf.shape(input=value)[1:],
                  ],
                  axis=0,
              ),
              dtype=value.dtype,
              name="stack",
          )
          stack_class = Stack if safety_checks else UnsafeStack
          return stack_class(stack, stack_index)
  
imports: import collections
  import contextlib
  import six
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.experimental.auto_batching import instructions
  from tensorflow_probability.python.experimental.auto_batching import xla
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow.python.ops import control_flow_util
label_desc: Use image node_id 3 for calling a global function with example usage: _create_stack(max_stack_depth, value, safety_checks, name) and returns: stack_class