class_docstr: An `Adapter`, guided by the `AdapterSpec`, takes a `Scenario` and produces
  a `ScenarioState`. It has additional logic surrounding in-context examples.
docstr: Takes a list of `Instance`s and builds a list of corresponding `RequestState`s.
  The reason we don't do this per eval instance is that we create a common set of
  training instances which is shared across all eval instances.
docstr_tok: ["Takes","a","list","of","`","Instance","`","s","and","builds","a","list","of","corresponding","`","RequestState","`","s",".","The","reason","we","do","n't","do","this","per","eval","instance","is","that","we","create","a","common","set","of","training","instances","which","is","shared","across","all","eval","instances","."]
code: def adapt(
      self, instances: List[Instance], parallelism: int
  ) -> ScenarioState:
      """
      Takes a list of `Instance`s and builds a list of corresponding `RequestState`s.
      The reason we don't do this per eval instance is that we create a common set of
      training instances which is shared across all eval instances.
      """
      # Pick out training instances
      all_train_instances: List[Instance] = [
          instance
          for instance in instances
          if instance.split == TRAIN_SPLIT
      ]
      if (
          len(all_train_instances)
          < self.adapter_spec.max_train_instances
      ):
          hlog(
              f"WARNING: only {len(all_train_instances)} training instances, "
              f"wanted {self.adapter_spec.max_train_instances}"
          )
  
      # Pick out evaluation instances. This includes both valid and test splits.
      eval_instances: List[Instance] = [
          instance
          for instance in instances
          if instance.split in EVAL_SPLITS
      ]
  
      hlog(
          f"{len(instances)} instances, "
          f"choosing {self.adapter_spec.max_train_instances}/{len(all_train_instances)} train instances, "
          f"{len(eval_instances)} eval instances"
      )
  
      # Accumulate all the request states due to adaptation
      all_request_states: List[RequestState] = []
      prompt: Prompt
  
      for train_trial_index in range(
          self.adapter_spec.num_train_trials
      ):
          with htrack_block(
              f"Adapting with train_trial_index={train_trial_index}"
          ):
              all_request_states.extend(
                  self._adapt_trial_index(
                      all_train_instances,
                      train_trial_index,
                      eval_instances,
                      parallelism,
                  )
              )
  
      hlog(f"{len(all_request_states)} requests")
      return ScenarioState(self.adapter_spec, all_request_states)
  
imports: import random
  from abc import ABC
  from collections import defaultdict
  from dataclasses import replace
  from itertools import cycle
  from typing import List, Dict, Optional
  from helm.benchmark.adaptation.prompt import Prompt
  from helm.benchmark.adaptation.request_state import RequestState
  from helm.benchmark.adaptation.scenario_state import ScenarioState
  from helm.benchmark.scenarios.scenario import Instance, TRAIN_SPLIT, EVAL_SPLITS, Reference
  from helm.common.general import parallel_map
  from helm.common.hierarchical_logger import hlog, htrack, htrack_block
  from .adapter import Adapter
label_desc: Use image node_id 1 for calling the InContextLearningAdapter obj's underlying member method code with example usage: obj.adapt(instances, parallelism) and returns: ScenarioState