code: def build_instance(self, config: _MixedDatasetConfig):
      _sample_weight = np.array(
          config["incontext_weight"], dtype=np.float32
      )
      _sample_weight = _sample_weight / _sample_weight.sum()
      num_incontext = np.random.choice(
          _sample_weight.shape[0], p=_sample_weight
      )
      ds = config["dataset"]
      transforms = config["transforms"]
      if isinstance(transforms, str):
          while True:
              try:
                  if not os.path.exists(transforms):
                      raise RuntimeError(
                          "transform script file {} not exists".format(
                              transforms
                          )
                      )
                  # load transform script
                  transform_func = self._ensure_transform_function(
                      _dataset_identity(config), transforms
                  )
                  seed = random.random()
                  break
              except Exception as e:
                  print(e)
                  time.sleep(10)
  
          def _transform(data: CPMBeeInputType):
              r = random.Random(seed)
              return transform_func(data, num_incontext, r)
  
          transform = _transform
      elif len(transforms) == 0:
          transform = None
      else:
          transform = transforms[np.random.choice(len(transforms))]
  
      raw_data = {}
      while True:
          inp = ds.read()
          inp = self.apply_transform(inp, transform)
  
          (
              input_ids,
              input_id_subs,
              context,
              segment_ids,
              segment_rel,
              n_segments,
              table_states,
          ) = self.data_to_id(inp)
          if input_ids.shape[0] > self._max_length:
              # too long
              continue
          input_ids = input_ids[: self._max_length]
          context = context[: self._max_length]
          segment_ids = segment_ids[: self._max_length]
          raw_data["input"] = inp
          raw_data["samples"] = []
          break
  
      sample_ids = np.zeros(input_ids.shape, dtype=np.int32)
      segment_rel_offset = np.zeros(input_ids.shape, dtype=np.int32)
      num_segments = np.full(
          input_ids.shape, n_segments, dtype=np.int32
      )
  
      for i in range(num_incontext):
          if input_ids.shape[0] >= self._max_length:
              # early break
              break
  
          sample = ds.read()
          sample = self.apply_transform(sample, transform)
          (
              sample_input_ids,
              sample_id_subs,
              _,
              sample_segments,
              sample_rel,
              n_segments,
              table_states,
          ) = self.data_to_id(sample, table_states)
  
          if (
              input_ids.shape[0] + sample_input_ids.shape[0]
              > self._max_length
          ):
              # too long, break
              break
          raw_data["samples"].append(sample)
          input_ids = np.concatenate(
              [input_ids, sample_input_ids], axis=0
          )
          input_id_subs = np.concatenate(
              [input_id_subs, sample_id_subs], axis=0
          )
          context = np.concatenate(
              [context, np.ones(sample_input_ids.shape, dtype=np.int8)],
              axis=0,
          )
          segment_ids = np.concatenate(
              [segment_ids, sample_segments], axis=0
          )
          segment_rel_offset = np.concatenate(
              [
                  segment_rel_offset,
                  np.full(
                      sample_input_ids.shape,
                      segment_rel.shape[0],
                      dtype=np.int32,
                  ),
              ],
              axis=0,
          )
          segment_rel = np.concatenate(
              [segment_rel, sample_rel], axis=0
          )
          sample_ids = np.concatenate(
              [
                  sample_ids,
                  np.full(
                      sample_input_ids.shape, i + 1, dtype=np.int32
                  ),
              ],
              axis=0,
          )
          num_segments = np.concatenate(
              [
                  num_segments,
                  np.full(
                      sample_input_ids.shape, n_segments, dtype=np.int32
                  ),
              ],
              axis=0,
          )
      return (
          input_ids,
          input_id_subs,
          context,
          segment_ids,
          segment_rel_offset,
          segment_rel,
          sample_ids,
          num_segments,
          raw_data,
      )
  
imports: from collections import OrderedDict
  import multiprocessing
  import os
  from queue import Empty
  from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union
  from typing_extensions import TypedDict
  from ...dataset import DistributedDataset
  from ...tokenizers import CPMBeeTokenizer
  from ...utils.config import load_dataset_config
  import numpy
  import time
  from numpy.typing import NDArray
  import torch
  import bmtrain
  import importlib.machinery
  import importlib.util
  import types
  import random
label_desc: Use image node_id 6 for calling the _MixedDatasetBatchPacker obj's underlying member method code with example usage: obj.build_instance(config) and returns: input_ids,  input_id_subs,  context,  segment_ids,  segment_rel_offset,  segment_rel,  sample_ids,  num_segments,  raw_data, transform_func