class_docstr: The IterativeSFTTrainer can be used to finetune models with methods that requires some steps between optimization.
  
  Attributes:
      **model** (`PreTrainedModel`) -- Model to be optimized, either an 'AutoModelForCausalLM' or an 'AutoModelForSeq2SeqLM'.
          Check the documentation of `PreTrainedModel` for more details.
      **args** (`transformers.TrainingArguments`): -- The arguments to use for training.
      **tokenizer** (`PreTrainedTokenizerBase`) -- Tokenizer to be used for encoding the
          data. Check the documentation of `transformers.PreTrainedTokenizer` and
          `transformers.PreTrainedTokenizerFast` for more details.
      **optimizers** (`Tuple[torch.optim.Optimizer, torch.optim.lr_scheduler.LambdaLR]`): -- The optimizer and scheduler to use for training.
      **data_collator** (Union[DataCollatorForLanguageModeling, DataCollatorForSeq2Seq], *optional*) -- Data collator to be used for training and
          passed along the dataloader.
      **eval_dataset** (`datasets.Dataset`): The dataset to use for evaluation.
      **max_length** (`int`, defaults to `None`): -- The maximum length of the input.
      **truncation_mode** (`str`, defaults to `keep_end`): -- The truncation mode to use, either `keep_end` or `keep_start`.
      **preprocess_logits_for_metrics** (`Callable[[torch.Tensor, torch.Tensor], torch.Tensor]`): -- The function to use to preprocess the logits before computing the metrics.
      **compute_metrics** (`Callable[[EvalPrediction], Dict]`, *optional*): -- The function to use to compute the metrics. Must take a `EvalPrediction` and return a dictionary string to metric values.
      **optimize_device_cache ** (`bool`, *optional*, defaults to `False`) -- Optimize CUDA cache for slightly more memory-efficient training.
class_docstr_tok: ["The","IterativeSFTTrainer","can","be","used","to","finetune","models","with","methods","that","requires","some","steps","between","optimization",".","Attributes",":","*","*","model","*","*","(","`","PreTrainedModel","`",")","--","Model","to","be","optimized",",","either","an","'AutoModelForCausalLM","'","or","an","'AutoModelForSeq2SeqLM","'",".","Check","the","documentation","of","`","PreTrainedModel","`","for","more","details",".","*","*","args","*","*","(","`","transformers.TrainingArguments","`",")",":","--","The","arguments","to","use","for","training",".","*","*","tokenizer","*","*","(","`","PreTrainedTokenizerBase","`",")","--","Tokenizer","to","be","used","for","encoding","the","data",".","Check","the","documentation","of","`","transformers.PreTrainedTokenizer","`","and","`","transformers.PreTrainedTokenizerFast","`","for","more","details",".","*","*","optimizers","*","*","(","`","Tuple","[","torch.optim.Optimizer",",","torch.optim.lr_scheduler.LambdaLR","]","`",")",":","--","The","optimizer","and","scheduler","to","use","for","training",".","*","*","data_collator","*","*","(","Union","[","DataCollatorForLanguageModeling",",","DataCollatorForSeq2Seq","]",",","*","optional","*",")","--","Data","collator","to","be","used","for","training","and","passed","along","the","dataloader",".","*","*","eval_dataset","*","*","(","`","datasets.Dataset","`",")",":","The","dataset","to","use","for","evaluation",".","*","*","max_length","*","*","(","`","int","`",",","defaults","to","`","None","`",")",":","--","The","maximum","length","of","the","input",".","*","*","truncation_mode","*","*","(","`","str","`",",","defaults","to","`","keep_end","`",")",":","--","The","truncation","mode","to","use",",","either","`","keep_end","`","or","`","keep_start","`",".","*","*","preprocess_logits_for_metrics","*","*","(","`","Callable","[","[","torch.Tensor",",","torch.Tensor","]",",","torch.Tensor","]","`",")",":","--","The","function","to","use","to","preprocess","the","logits","before","computing","the","metrics",".","*","*","compute_metrics","*","*","(","`","Callable","[","[","EvalPrediction","]",",","Dict","]","`",",","*","optional","*",")",":","--","The","function","to","use","to","compute","the","metrics",".","Must","take","a","`","EvalPrediction","`","and","return","a","dictionary","string","to","metric","values",".","*","*","optimize_device_cache","*","*","(","`","bool","`",",","*","optional","*",",","defaults","to","`","False","`",")","--","Optimize","CUDA","cache","for","slightly","more","memory-efficient","training","."]
docstr: Check if the input data is valid for training.
  
  Args:
      input_ids (List[`torch.LongTensor`]):
          List of tensors containing the input_ids
      attention_mask (List[`torch.LongTensor`]):
          List of tensors containing the attention_mask
      labels (List[`torch.FloatTensor`]):
          List of tensors containing the labels
      texts (List[`str`]):
          List of string containing the text input.
      texts_labels (List[`str`]):
          List of string containing the text labels.
  Returns:
      `tuple`: The input data.
docstr_tok: ["Check","if","the","input","data","is","valid","for","training",".","Args",":","input_ids","(","List","[","`","torch.LongTensor","`","]",")",":","List","of","tensors","containing","the","input_ids","attention_mask","(","List","[","`","torch.LongTensor","`","]",")",":","List","of","tensors","containing","the","attention_mask","labels","(","List","[","`","torch.FloatTensor","`","]",")",":","List","of","tensors","containing","the","labels","texts","(","List","[","`","str","`","]",")",":","List","of","string","containing","the","text","input",".","texts_labels","(","List","[","`","str","`","]",")",":","List","of","string","containing","the","text","labels",".","Returns",":","`","tuple","`",":","The","input","data","."]
code: def _step_safety_checker(
      input_ids: List[torch.LongTensor],
      attention_mask: List[torch.LongTensor],
      labels: List[torch.LongTensor],
      texts: List[str],
      texts_labels: List[str],
  ):
      """
      Check if the input data is valid for training.
  
      Args:
          input_ids (List[`torch.LongTensor`]):
              List of tensors containing the input_ids
          attention_mask (List[`torch.LongTensor`]):
              List of tensors containing the attention_mask
          labels (List[`torch.FloatTensor`]):
              List of tensors containing the labels
          texts (List[`str`]):
              List of string containing the text input.
          texts_labels (List[`str`]):
              List of string containing the text labels.
      Returns:
          `tuple`: The input data.
      """
      if texts is None:
          if attention_mask is None:
              for name, tensor_list in zip(
                  ["input_ids", "labels"], [input_ids, labels]
              ):
                  if not isinstance(tensor_list, list):
                      raise ValueError(
                          f"{name} must be a list of tensors - got {type(tensor_list)}"
                      )
                  if not isinstance(tensor_list[0], torch.Tensor):
                      raise ValueError(
                          f"Elements in {name} must be tensors - got {type(tensor_list[0])}"
                      )
          else:
              for name, tensor_list in zip(
                  ["input_ids", "attention_mask", "labels"],
                  [input_ids, attention_mask, labels],
              ):
                  if not isinstance(tensor_list, list):
                      raise ValueError(
                          f"{name} must be a list of tensors - got {type(tensor_list)}"
                      )
                  if not isinstance(tensor_list[0], torch.Tensor):
                      raise ValueError(
                          f"Elements in {name} must be tensors - got {type(tensor_list[0])}"
                      )
      else:
          if not isinstance(texts, list):
              raise ValueError(
                  f"'text' must be a list of strings - got {type(texts)}"
              )
          if not isinstance(texts[0], str):
              raise ValueError(
                  f"Elements in 'text' must be strings - got {type(texts[0])}"
              )
          if texts_labels is not None:
              if not isinstance(texts_labels, list):
                  raise ValueError(
                      f"'text_labels' must be a list of strings - got {type(texts_labels)}"
                  )
              if not isinstance(texts_labels[0], str):
                  raise ValueError(
                      f"Elements in 'text_labels' must be strings - got {type(texts_labels[0])}"
                  )
  
      return input_ids, attention_mask, labels, texts, texts_labels
  
file_path: trl/trl/trainer/iterative_sft_trainer.py
imports: import warnings
  from typing import Callable, Dict, List, Optional, Tuple, Union
  import torch
  from datasets import Dataset
  from torch.utils.data import DataLoader
  from transformers import DataCollator, DataCollatorForLanguageModeling, DataCollatorForSeq2Seq, PreTrainedModel, PreTrainedTokenizerBase, Trainer, TrainingArguments
  from transformers.trainer_utils import EvalLoopOutput
  from ..core import PPODecorators
  from ..import_utils import is_peft_available
label_desc: Use image node_id 3 for calling the IterativeSFTTrainer obj's underlying member method code with example usage: obj._step_safety_checker(input_ids, attention_mask, labels, texts, texts_labels) and returns: input_ids,  attention_mask,  labels,  texts,  texts_labels