code: def sliding_window_inference(
      model, inputs, labels, roi_shape=(128, 128, 128), overlap=0.5
  ):
      from tinygrad.jit import TinyJit
  
      mdl_run = TinyJit(lambda x: model(x).realize())
      image_shape, dim = list(inputs.shape[2:]), len(inputs.shape[2:])
      strides = [int(roi_shape[i] * (1 - overlap)) for i in range(dim)]
      bounds = [image_shape[i] % strides[i] for i in range(dim)]
      bounds = [
          bounds[i] if bounds[i] < strides[i] // 2 else 0
          for i in range(dim)
      ]
      inputs = inputs[
          ...,
          bounds[0] // 2 : image_shape[0]
          - (bounds[0] - bounds[0] // 2),
          bounds[1] // 2 : image_shape[1]
          - (bounds[1] - bounds[1] // 2),
          bounds[2] // 2 : image_shape[2]
          - (bounds[2] - bounds[2] // 2),
      ]
      labels = labels[
          ...,
          bounds[0] // 2 : image_shape[0]
          - (bounds[0] - bounds[0] // 2),
          bounds[1] // 2 : image_shape[1]
          - (bounds[1] - bounds[1] // 2),
          bounds[2] // 2 : image_shape[2]
          - (bounds[2] - bounds[2] // 2),
      ]
      inputs, paddings = pad_input(inputs, roi_shape, strides)
      padded_shape = inputs.shape[2:]
      size = [
          (inputs.shape[2:][i] - roi_shape[i]) // strides[i] + 1
          for i in range(dim)
      ]
      result = np.zeros((1, 3, *padded_shape), dtype=np.float32)
      norm_map = np.zeros((1, 3, *padded_shape), dtype=np.float32)
      norm_patch = gaussian_kernel(roi_shape[0], 0.125 * roi_shape[0])
      norm_patch = np.expand_dims(norm_patch, axis=0)
      for i in range(0, strides[0] * size[0], strides[0]):
          for j in range(0, strides[1] * size[1], strides[1]):
              for k in range(0, strides[2] * size[2], strides[2]):
                  out = mdl_run(
                      Tensor(
                          inputs[
                              ...,
                              i : roi_shape[0] + i,
                              j : roi_shape[1] + j,
                              k : roi_shape[2] + k,
                          ]
                      )
                  ).numpy()
                  result[
                      ...,
                      i : roi_shape[0] + i,
                      j : roi_shape[1] + j,
                      k : roi_shape[2] + k,
                  ] += (
                      out * norm_patch
                  )
                  norm_map[
                      ...,
                      i : roi_shape[0] + i,
                      j : roi_shape[1] + j,
                      k : roi_shape[2] + k,
                  ] += norm_patch
      result /= norm_map
      result = result[
          ...,
          paddings[4] : image_shape[0] + paddings[4],
          paddings[2] : image_shape[1] + paddings[2],
          paddings[0] : image_shape[2] + paddings[0],
      ]
      return result, labels
  
file_path: tinygrad/extra/datasets/kits19.py
imports: import random
  import functools
  from pathlib import Path
  import numpy
  import nibabel
  from scipy import signal
  import torch
  import torch.nn.functional
  from tinygrad.tensor import Tensor
  from tinygrad.helpers import fetch
label_desc: Use image node_id 10 for calling a global function with example usage: sliding_window_inference(model, inputs, labels, roi_shape, overlap) and returns: result,  labels