code: def _gpu_sliced_torch_case(case_name, dtype, g):
      shapes, slices = get_sliced_torch_case(case_name)
      input_batch = get_random_torch_batch(g, shapes, dtype)
      assert len(input_batch) == len(shapes)
  
      # returns sliced view of the input tensors
      def sliced_tensor(batch):
          stream = current_dali_stream()
          torch_stream = torch.cuda.ExternalStream(stream)
          with torch.cuda.stream(torch_stream):
              tensors = [torch_dlpack.from_dlpack(t) for t in batch]
              assert len(tensors) == len(slices)
              tensor_views = [t[sl] for t, sl in zip(tensors, slices)]
              out = [torch_dlpack.to_dlpack(t) for t in tensor_views]
              return out
  
      @pipeline_def(
          batch_size=len(input_batch), num_threads=4, device_id=0
      )
      def pipeline():
          data = fn.external_source(lambda: input_batch)
          data = fn.dl_tensor_python_function(
              data.gpu(),
              batch_processing=True,
              function=sliced_tensor,
              synchronize_stream=False,
          )
          return data
  
      p = pipeline()
      p.build()
      (out,) = p.run()
  
      out = [numpy.array(sample) for sample in out.as_cpu()]
      ref = [
          numpy.array(sample)[sl]
          for sample, sl in zip(input_batch, slices)
      ]
  
      numpy.testing.assert_equal(out, ref)
  
imports: import numpy
  import nvidia.dali.ops
  import nvidia.dali.types
  import os
  import random
  from functools import partial
  from nvidia.dali.pipeline import Pipeline
  from nvidia.dali import fn, pipeline_def
  from nvidia.dali.python_function_plugin import current_dali_stream
label_desc: Use image node_id 35 for calling a global function with example usage: _gpu_sliced_torch_case(case_name, dtype, g) and returns: data, out