code: def external_source(
      source=None,
      num_outputs=None,
      *,
      cycle=None,
      name=None,
      device="cpu",
      layout=None,
      dtype=None,
      ndim=None,
      cuda_stream=None,
      use_copy_kernel=None,
      batch=True,
      repeat_last=False,
      **kwargs,
  ):
      """Creates a data node which is populated with data from a Python source.
      The data can be provided by the ``source`` function or iterable, or it can be provided by
      ``pipeline.feed_input(name, data, layout, cuda_stream)`` inside ``pipeline.iter_setup``.
  
      In the case of the GPU input, it is the user responsibility to modify the
      provided GPU memory content only using provided stream (DALI schedules a copy on it
      and all work is properly queued). If no stream is provided feeding input blocks until the
      provided memory is copied to the internal buffer.
  
      .. note::
          :meth:`nvidia.dali.fn.external_source` operator is partially compatible with TensorFlow
          integration via :meth:`nvidia.dali.plugin.tf.experimental.DALIDatasetWithInputs`.
          Please refer to its documentation for details.
  
      .. note::
          To return a batch of copies of the same tensor, use :func:`nvidia.dali.types.Constant`,
          which is more performant.
      """
  
      from nvidia.dali._debug_mode import _PipelineDebug
      from nvidia.dali import _conditionals
  
      def _external_source(
          source=None,
          num_outputs=None,
          *,
          cycle=None,
          name=None,
          device="cpu",
          layout=None,
          dtype=None,
          ndim=None,
          cuda_stream=None,
          use_copy_kernel=None,
          repeat_last=False,
          batch=True,
          **kwargs,
      ):
          if batch is None:
              batch = True
  
          if num_outputs is not None:
              if source is None:
                  raise ValueError(
                      "The parameter ``num_outputs`` is only valid when using ``source`` to "
                      "provide data. To feed multiple external sources in ``feed_input``, "
                      "use multiple ``external_source`` nodes."
                  )
  
          op = ExternalSource(
              device=device,
              num_outputs=num_outputs,
              source=source,
              cycle=cycle,
              layout=layout,
              dtype=dtype,
              ndim=ndim,
              cuda_stream=cuda_stream,
              use_copy_kernel=use_copy_kernel,
              batch=batch,
              repeat_last=repeat_last,
              **kwargs,
          )
          return op(name=name)
  
      # Wrapper around external_source to switch between standard and debug mode.
      current_pipeline = _PipelineDebug.current()
      if getattr(current_pipeline, "_debug_on", False):
          result = current_pipeline._external_source(
              source=source,
              num_outputs=num_outputs,
              cycle=cycle,
              name=name,
              device=device,
              layout=layout,
              batch=batch,
              repeat_last=repeat_last,
              **kwargs,
          )
      else:
          result = _external_source(
              source,
              num_outputs,
              cycle=cycle,
              name=name,
              device=device,
              layout=layout,
              dtype=dtype,
              ndim=ndim,
              cuda_stream=cuda_stream,
              use_copy_kernel=use_copy_kernel,
              batch=batch,
              repeat_last=repeat_last,
              **kwargs,
          )
      if _conditionals.conditionals_enabled():
          _conditionals.register_data_nodes(result)
      return result
  
imports: from nvidia.dali import backend
  from nvidia.dali import tensors
  from nvidia.dali import types
  from nvidia.dali._multiproc.messages import TaskArgs, SampleRange
  import nvidia.dali.types
  from nvidia.dali._utils.external_source_impl import get_callback_from_source, accepted_arg_count, SourceKind
label_desc: Use image node_id 7 for calling a global function with example usage: external_source(source, num_outputs) and returns: result, op