code: def _multi_instance_helper(model, recv_queue, send_queue, next_idx):
      from bigdl.nano.pytorch import InferenceOptimizer
  
      with InferenceOptimizer.get_context(model):
          while True:
              try:
                  args = recv_queue.get()
                  if isinstance(args, DataLoader):
                      dataset = args.dataset
                      batch_size = args.batch_size
                      length = len(args)
                      idx = get_next_idx(next_idx)
                      while idx < length:
                          batch = [
                              dataset[i]
                              for i in range(
                                  idx * batch_size,
                                  (idx + 1) * batch_size,
                              )
                          ]
                          inputs = args.collate_fn(batch)
                          # get next index before sending output to main process
                          # to ensure we get next index before main process reset `next_idx`
                          new_idx = get_next_idx(next_idx)
                          inference(idx, inputs, model, send_queue)
                          idx = new_idx
                  else:
                      idx, inputs = args
                      inference(idx, inputs, model, send_queue)
              except Exception as e:
                  send_queue.put((idx, e))
  
file_path: BigDL/python/nano/src/bigdl/nano/pytorch/inference/multi_instance.py
imports: from typing import Union, List
  import torch
  from torch.utils.data.dataset import TensorDataset
  from torch.utils.data.dataloader import DataLoader
  from bigdl.nano.utils.common import invalidInputError, invalidOperationError
  from bigdl.nano.pytorch.model import AcceleratedLightningModule
label_desc: Use image node_id 1 for calling a global function with example usage: _multi_instance_helper(model, recv_queue, send_queue, next_idx) without return types