code: def init_var_from_numpy(input_var, numpy_input, session):
      """Initialize `input_var` to `numpy_input` using `session` in graph mode."""
      with ops.init_scope():
          if context.executing_eagerly():
              input_var.assign(numpy_input)
              return
  
          assert session is not None
          session.run(input_var.initializer)
  
          start_placeholder = array_ops.placeholder(dtypes.int64, ())
          end_placeholder = array_ops.placeholder(dtypes.int64, ())
          slice_placeholder = array_ops.placeholder(input_var.dtype)
          assign_slice_op = input_var[
              start_placeholder:end_placeholder
          ].assign(slice_placeholder)
  
          # If each batch element is > 64 MB, then we copy each batch element
          # individually. Otherwise, the slices will be < 128 MB. There might be
          # padding which might mean that the slices are 128 MB even if the size of
          # the tensor allocated is less than 128 MB.  This formula gives slices with
          # size: ceil(64 MB / byte size per batch element) bytes.  Using ceil()
          # guarantees we get a number >= 1.
  
          # Calculate the size of each batch element.
          byte_size_per_batch_element = (
              np.prod(numpy_input.shape[1:]) * input_var.dtype.size
          )
  
          # Calculate number of elements we want to copy per slice.
          batch_size_per_slice = int(
              np.ceil((64 << 20) / byte_size_per_batch_element)
          )
  
          # Copy slices of the above size starting at 0, except the last slice will be
          # smaller.
          start = 0
          limit = numpy_input.shape[0]
          while start < limit:
              end = min(start + batch_size_per_slice, limit)
              session.run(
                  assign_slice_op,
                  feed_dict={
                      start_placeholder: start,
                      end_placeholder: end,
                      slice_placeholder: numpy_input[start:end],
                  },
              )
              start = end
  
file_path: tensorflow-upstream/tensorflow/python/distribute/numpy_dataset.py
imports: import numpy
  from tensorflow.python.data.ops import dataset_ops
  from tensorflow.python.eager import context
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import variable_scope
  from tensorflow.python.ops import variable_v1
  from tensorflow.python.util import nest
label_desc: Use image node_id 1 for calling a global function with example usage: init_var_from_numpy(input_var, numpy_input, session) without return types