code: def _create_buffered_slices(
      slices, batch_size, sw_batch_size, buffer_dim, buffer_steps
  ):
      """rearrange slices for buffering"""
      slices_np = np.asarray(slices)
      slices_np = slices_np[
          np.argsort(slices_np[:, buffer_dim, 0], kind="mergesort")
      ]
      slices = [tuple(slice(c[0], c[1]) for c in i) for i in slices_np]
      slices_np = slices_np[:, buffer_dim]
  
      _, _, _b_lens = np.unique(
          slices_np[:, 0], return_counts=True, return_index=True
      )
      b_ends = np.cumsum(
          _b_lens
      ).tolist()  # possible buffer flush boundaries
      x = [0, *b_ends][:: min(len(b_ends), int(buffer_steps))]
      if x[-1] < b_ends[-1]:
          x.append(b_ends[-1])
      n_per_batch = len(x) - 1
      windows_range = [
          range(b * x[-1] + x[i], b * x[-1] + x[i + 1], sw_batch_size)
          for b in range(batch_size)
          for i in range(n_per_batch)
      ]
      b_slices = []
      for _s, _r in enumerate(windows_range):
          s_s = slices_np[
              windows_range[_s - 1].stop % len(slices) if _s > 0 else 0,
              0,
          ]
          s_e = slices_np[(_r.stop - 1) % len(slices), 1]
          b_slices.append(
              (_r.stop, s_s, s_e)
          )  # buffer index, slice start, slice end
      windows_range = itertools.chain(*windows_range)  # type: ignore
      return slices, n_per_batch, b_slices, windows_range
  
file_path: MONAI/monai/inferers/utils.py
imports: from __future__ import annotations
  import itertools
  from collections.abc import Callable, Mapping, Sequence
  from typing import Any, Iterable
  import numpy
  import torch
  import torch.nn.functional
  from monai.data.meta_tensor import MetaTensor
  from monai.data.utils import compute_importance_map, dense_patch_slices, get_valid_patch_size
  from monai.utils import BlendMode, PytorchPadMode, convert_data_type, convert_to_dst_type, ensure_tuple, ensure_tuple_rep, fall_back_tuple, look_up_option, optional_import, pytorch_after
label_desc: Use image node_id 2 for calling a global function with example usage: _create_buffered_slices(slices, batch_size, sw_batch_size, buffer_dim, buffer_steps) and returns: slices,  n_per_batch,  b_slices,  windows_range