class_docstr: ## Retro trainer
class_docstr_tok: ["#","#","Retro","trainer"]
docstr: * `device` is the device of the model
  * `model` is the [Retro mode](retro.html)
  * `dataloader` is the dataloader for the [dataset with pre-retrieved neighbors](dataset.html)
  * `optimizer` is the optimizer
docstr_tok: ["*","`","device","`","is","the","device","of","the","model","*","`","model","`","is","the","[","Retro","mode","]","(","retro.html",")","*","`","dataloader","`","is","the","dataloader","for","the","[","dataset","with","pre-retrieved","neighbors","]","(","dataset.html",")","*","`","optimizer","`","is","the","optimizer"]
code: def __init__(
      self,
      device: torch.device,
      model: retro.RetroModel,
      dataloader: DataLoader,
      optimizer: torch.optim.Optimizer,
  ):
      """
      * `device` is the device of the model
      * `model` is the [Retro mode](retro.html)
      * `dataloader` is the dataloader for the [dataset with pre-retrieved neighbors](dataset.html)
      * `optimizer` is the optimizer
      """
      self.optimizer = optimizer
      self.device = device
      self.dataloader = dataloader
      self.model = model
      self.loss_func = nn.CrossEntropyLoss()
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/transformers/retro/train.py
imports: import torch
  from torch import nn
  from torch.utils.data import DataLoader, RandomSampler
  from labml import monit, lab, tracker, experiment, logger
  from labml.logger import Text
  from labml_helpers.datasets.text import TextFileDataset
  from labml_nn.optimizers.noam import Noam
  from labml_nn.transformers.retro import model
  from labml_nn.transformers.retro.dataset import Dataset, RetroIndex
  from labml_nn.transformers.retro.model import RetroModel, NearestNeighborEncoder
label_desc: Use image node_id 1 to create a new Trainer object  with example: obj = Trainer(device, model, dataloader, optimizer)