code: def iter_chunk_and_save(
      task,
      phase,
      examples,
      feat_spec,
      tokenizer,
      args: RunConfiguration,
  ):
      """Convert Examples to DataRows, optionally truncate sequences if possible, stream to disk.
  
      Args:
          task: Task object
          phase (str): string identifying the data subset (e.g., train, val or test).
          examples (list[Example]): list of task Examples.
          feat_spec: (FeaturizationSpec): Tokenization-related metadata.
          tokenizer: TODO  (issue #1188)
          args (RunConfiguration): run configuration object.
  
      """
      dataset_generator = (
          preprocessing.iter_chunk_convert_examples_to_dataset(
              task=task,
              examples=examples,
              feat_spec=feat_spec,
              tokenizer=tokenizer,
              phase=phase,
              verbose=True,
          )
      )
      max_valid_length_recorder = preprocessing.MaxValidLengthRecorder(
          args.max_seq_length
      )
      shared_caching.iter_chunk_and_save(
          data=dataset_generator,
          chunk_size=args.chunk_size,
          data_args=args.to_dict(),
          output_dir=os.path.join(args.output_dir, phase),
          recorder_callback=max_valid_length_recorder,
      )
      if args.smart_truncate:
          preprocessing.smart_truncate_cache(
              cache=shared_caching.ChunkedFilesDataCache(
                  os.path.join(args.output_dir, phase)
              ),
              max_seq_length=args.max_seq_length,
              max_valid_length=max_valid_length_recorder.max_valid_length,
              verbose=True,
          )
          py_io.write_json(
              data={
                  "truncated_to": int(
                      max_valid_length_recorder.max_valid_length
                  )
              },
              path=os.path.join(
                  args.output_dir, phase, "smart_truncate.json"
              ),
          )
  
file_path: jiant/jiant/proj/main/tokenize_and_cache.py
imports: import os
  from transformers import AutoConfig
  from transformers import AutoTokenizer
  import jiant.proj.main.preprocessing
  import jiant.shared.caching
  import jiant.tasks.evaluate
  import jiant.utils.python.io
  import jiant.utils.zconf
  from jiant.proj.main.modeling.primary import JiantTransformersModelFactory
  from jiant.shared.constants import PHASE
  from jiant.tasks.retrieval import create_task_from_config_path
label_desc: Use image node_id 3 for calling a global function with example usage: iter_chunk_and_save(task, phase, examples, feat_spec, tokenizer, args) without return types