class_docstr:     Trainer to use while training reward model.
  
  Args:
      model (torch.nn.Module): the model to train
      strategy (Strategy): the strategy to use for training
      optim(Optimizer): the optimizer to use for training
      lr_scheduler(_LRScheduler): the lr scheduler to use for training
      max_epochs (int, defaults to 2): the number of epochs to train
      accumulation_steps (int, defaults to 8): the number of steps to accumulate gradients
class_docstr_tok: ["Trainer","to","use","while","training","reward","model",".","Args",":","model","(","torch.nn.Module",")",":","the","model","to","train","strategy","(","Strategy",")",":","the","strategy","to","use","for","training","optim","(","Optimizer",")",":","the","optimizer","to","use","for","training","lr_scheduler","(","_LRScheduler",")",":","the","lr","scheduler","to","use","for","training","max_epochs","(","int",",","defaults","to","2",")",":","the","number","of","epochs","to","train","accumulation_steps","(","int",",","defaults","to","8",")",":","the","number","of","steps","to","accumulate","gradients"]
code: def _eval(self, epoch: int):
      if self.eval_dataloader is not None:
          self.model.eval()
          with torch.no_grad():
              loss_sum, num_seen = 0, 0
              for batch in self.eval_dataloader:
                  batch = to_device(batch, torch.cuda.current_device())
                  outputs = self.model(
                      batch["input_ids"],
                      attention_mask=batch["attention_mask"],
                      labels=batch["labels"],
                  )
                  loss_sum += outputs.loss.item()
                  num_seen += batch["input_ids"].size(0)
              loss_mean = loss_sum / num_seen
              if dist.get_rank() == 0:
                  self.logger.info(
                      f"Eval Epoch {epoch}/{self.max_epochs} loss {loss_mean}"
                  )
              if self.writer:
                  self.writer.add_scalar(
                      "eval/loss", loss_mean, self.num_eval_step
                  )
                  self.num_eval_step += 1
  
file_path: ColossalAI/applications/Chat/coati/trainer/sft.py
imports: from typing import Optional
  import torch
  import torch.distributed
  import tqdm
  from torch.optim import Optimizer
  from torch.optim.lr_scheduler import _LRScheduler
  from torch.utils.data import DataLoader
  from colossalai.logging import DistributedLogger
  from .base import SLTrainer
  from .strategies import GeminiStrategy, Strategy
  from .utils import is_rank_0, to_device
label_desc: Use image node_id 3 for calling the SFTTrainer obj's underlying member method code with example usage: obj._eval(epoch) without return types