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","."]
code: def _maybe_log_save_evaluate(self):
      # check if eval is required
      if self.args.eval_steps is not None:
          if (
              self.state.global_step % self.args.eval_steps == 0
              and self.state.global_step != 0
          ):
              self.evaluate(self.eval_dataset)
  
      # check if logging is required
      if self.args.logging_steps is not None:
          if (
              self.state.global_step % self.args.logging_steps == 0
              and self.state.global_step != 0
          ):
              logs: Dict[str, float] = {}
  
              tr_loss_scalar = (
                  self._nested_gather(self.tr_loss).mean().item()
              )
  
              # reset tr_loss to zero
              self.tr_loss -= self.tr_loss
  
              logs["loss"] = round(
                  tr_loss_scalar
                  / (
                      self.state.global_step
                      - self._globalstep_last_logged
                  ),
                  4,
              )
              logs["learning_rate"] = self._get_learning_rate()
  
              self._globalstep_last_logged = self.state.global_step
  
              self.log(logs)
  
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 5 for calling the IterativeSFTTrainer obj's underlying member method code with example usage: obj._maybe_log_save_evaluate() without return types