code: def generate_synthetic_efficiency_instances(
      tokens: Dict[str, List[TokenizationToken]],
      text_chunks: Dict[str, List[str]],
      client: Client,
      num_instances: int,
      num_prompt_tokens: int,
      tokenizer: str,
      output_path: str = "synthetic_efficiency_instances",
      base_path: str = "prod_env",
  ):
      """Generates the synthetic efficiency instances given the tokenized book sources."""
      tokenizer_organization: str = tokenizer.split("/")[0]
      ai21_tokenizer: bool = tokenizer_organization == "ai21"
  
      books = list(tokens.keys())
      prompts = []
      for i in range(num_instances // len(books)):
          for j in range(len(books)):
              finished = False
              attempt_num = 0
              orig_i = i
              # Select a new span of text to generate a prompt from
              while not finished:
                  i = orig_i + attempt_num
                  prompt: str = ""
  
                  # Initialize
                  if ai21_tokenizer:
                      per_instance_tokens = text_chunks[books[j]][
                          i
                          * num_prompt_tokens : (i + 1)
                          * num_prompt_tokens
                      ]
                  else:
                      per_instance_tokens = [
                          token.value  # type: ignore
                          for token in tokens[books[j]][
                              i
                              * num_prompt_tokens : (i + 1)
                              * num_prompt_tokens
                          ]
                      ]
  
                  # Iterate on this span of text until we get the right number of tokens
                  num_iters = 0
                  while num_iters < MAX_ITERS:
                      if ai21_tokenizer:
                          prompt = "".join(per_instance_tokens)
                      else:
                          decode_request: DecodeRequest = DecodeRequest(tokens=per_instance_tokens)  # type: ignore
                          decode_result: DecodeRequestResult = (
                              client.decode(decode_request)
                          )
                          prompt = decode_result.text
  
                      if prompt == "":
                          num_generated_tokens = 0
                      else:
                          num_generated_tokens = _count_prompt_tokens(
                              client, prompt, tokenizer
                          )
                      if num_generated_tokens != num_prompt_tokens:
                          temp_num_tokens = num_generated_tokens
                          while temp_num_tokens < num_prompt_tokens:
                              if len(per_instance_tokens) == 0:
                                  if num_prompt_tokens != 1:
                                      print(
                                          f"WARNING: got 0 per_instance_tokens with num_prompt_tokens={num_prompt_tokens}"
                                      )
                                      break
                                  if ai21_tokenizer:
                                      per_instance_tokens = text_chunks[
                                          books[j]
                                      ][:2]
                                  else:
                                      per_instance_tokens = [
                                          token.value for token in tokens[books[j]][:2]  # type: ignore
                                      ]
                              else:
                                  per_instance_tokens.append(
                                      per_instance_tokens[-1]
                                  )
                              temp_num_tokens += 1
                          while temp_num_tokens > num_prompt_tokens:
                              per_instance_tokens = per_instance_tokens[
                                  :-1
                              ]
                              temp_num_tokens -= 1
                      else:
                          finished = True
                          break
                      num_iters += 1
                  if not finished:
                      print(
                          f"Requested {num_prompt_tokens}, got {num_generated_tokens} for "
                          f"book {books[j]}, instance #{orig_i}, tokenizer={tokenizer}, "
                          "trying again with a new span of text..."
                      )
                      attempt_num += 1
                      continue
                  prompts.append(prompt)
  
      for i, prompt in enumerate(prompts):
          for k, v in TOKENIZER_REPLACEMENTS.items():
              tokenizer = tokenizer.replace(k, v)
          name = (
              f"num_prompt_tokens={num_prompt_tokens},"
              f"tokenizer={tokenizer.replace('/', '_')},"
              f"id={i}.txt"
          )
          write(os.path.join(output_path, name), prompt)
  
file_path: H2O/h2o_hf/helm/scripts/efficiency/generate_instances.py
imports: import os
  from typing import Dict, List, Tuple
  from helm.common.general import ensure_directory_exists, ensure_file_downloaded, parse_hocon, write
  from helm.common.tokenization_request import TokenizationRequest, TokenizationRequestResult, DecodeRequest, DecodeRequestResult, TokenizationToken
  from helm.proxy.clients.client import Client
  from helm.proxy.clients.auto_client import AutoClient
  from helm.proxy.services.service import CREDENTIALS_FILE, CACHE_DIR
  from helm.benchmark.scenarios.synthetic_efficiency_scenario import NUM_INPUT_TOKENS
label_desc: Use image node_id 4 for calling a global function with example usage: generate_synthetic_efficiency_instances(tokens, text_chunks, client, num_instances, num_prompt_tokens, tokenizer, output_path, base_path) without return types