class_docstr: Model checkpointer which which saves the model every 'period' epochs to the given filepath. `filepath` can
  contain named formatting options, which will be filled any values from state. For example: if `filepath` is
  `weights.{epoch:02d}-{val_loss:.2f}`, then the model checkpoints will be saved with the epoch number and the
  validation loss in the filename.
  
  Example: ::
  
      >>> from torchbearer.callbacks import Interval
      >>> from torchbearer import Trial
      >>> import torch
  
      # Example Trial (without optimiser or loss criterion) which uses this checkpointer
      >>> model = torch.nn.Linear(1,1)
      >>> checkpoint = Interval('my_path.pt', period=100, on_batch=True)
      >>> trial = Trial(model, callbacks=[checkpoint], metrics=['acc'])
  
  Args:
      filepath (str): Path to save the model file
      save_model_params_only (bool): If `save_model_params_only=True`, only model parameters will be saved so that
          the results can be loaded into a PyTorch nn.Module. The other option, `save_model_params_only=False`,
          should be used only if the results will be loaded into a Torchbearer Trial object later.
      period (int): Interval (number of steps) between checkpoints
      on_batch (bool): If true step each batch, if false step each epoch.
      period (int): Interval (number of epochs) between checkpoints
      pickle_module (module): The pickle module to use, default is 'torch.serialization.pickle'
      pickle_protocol (int): The pickle protocol to use, default is 'torch.serialization.DEFAULT_PROTOCOL'
  
  State Requirements:
      - :attr:`torchbearer.state.MODEL`: Model should have the `state_dict` method
      - :attr:`torchbearer.state.METRICS`: Metrics dictionary should exist
      - :attr:`torchbearer.state.SELF`: Self should be the :attr:`torchbearer.Trial` which is running this callback
class_docstr_tok: ["Model","checkpointer","which","which","saves","the","model","every","'period","'","epochs","to","the","given","filepath",".","`","filepath","`","can","contain","named","formatting","options",",","which","will","be","filled","any","values","from","state",".","For","example",":","if","`","filepath","`","is","`","weights",".","{","epoch:02d","}","-","{","val_loss",":",".2f","}","`",",","then","the","model","checkpoints","will","be","saved","with","the","epoch","number","and","the","validation","loss","in","the","filename",".","Example",":",":",":",">",">",">","from","torchbearer.callbacks","import","Interval",">",">",">","from","torchbearer","import","Trial",">",">",">","import","torch","#","Example","Trial","(","without","optimiser","or","loss","criterion",")","which","uses","this","checkpointer",">",">",">","model","=","torch.nn.Linear","(","1,1",")",">",">",">","checkpoint","=","Interval","(","'my_path.pt","'",",","period=100",",","on_batch=True",")",">",">",">","trial","=","Trial","(","model",",","callbacks=","[","checkpoint","]",",","metrics=","[","'acc","'","]",")","Args",":","filepath","(","str",")",":","Path","to","save","the","model","file","save_model_params_only","(","bool",")",":","If","`","save_model_params_only=True","`",",","only","model","parameters","will","be","saved","so","that","the","results","can","be","loaded","into","a","PyTorch","nn.Module",".","The","other","option",",","`","save_model_params_only=False","`",",","should","be","used","only","if","the","results","will","be","loaded","into","a","Torchbearer","Trial","object","later",".","period","(","int",")",":","Interval","(","number","of","steps",")","between","checkpoints","on_batch","(","bool",")",":","If","true","step","each","batch",",","if","false","step","each","epoch",".","period","(","int",")",":","Interval","(","number","of","epochs",")","between","checkpoints","pickle_module","(","module",")",":","The","pickle","module","to","use",",","default","is","'torch.serialization.pickle'","pickle_protocol","(","int",")",":","The","pickle","protocol","to","use",",","default","is","'torch.serialization.DEFAULT_PROTOCOL'","State","Requirements",":","-",":","attr",":","`","torchbearer.state.MODEL","`",":","Model","should","have","the","`","state_dict","`","method","-",":","attr",":","`","torchbearer.state.METRICS","`",":","Metrics","dictionary","should","exist","-",":","attr",":","`","torchbearer.state.SELF","`",":","Self","should","be","the",":","attr",":","`","torchbearer.Trial","`","which","is","running","this","callback"]
code: def __init__(
      self,
      filepath="model.{epoch:02d}-{val_loss:.2f}.pt",
      save_model_params_only=False,
      period=1,
      on_batch=False,
      pickle_module=torch.serialization.pickle,
      pickle_protocol=torch.serialization.DEFAULT_PROTOCOL,
  ):
      super(Interval, self).__init__(
          filepath,
          save_model_params_only=save_model_params_only,
          pickle_module=pickle_module,
          pickle_protocol=pickle_protocol,
      )
      self.period = period
      self.epochs_since_last_save = 0
  
      if on_batch:
          self.on_step_training = self.on_checkpoint
          self.on_checkpoint = lambda _: None
  
imports: import torchbearer
  import torch
  from torchbearer.callbacks.callbacks import Callback
  import os
  import warnings
  from torchbearer.bases import get_metric
label_desc: Use image node_id 1 to create a new Interval object from inherited base classes: _Checkpointer with example: obj = Interval(filepath, save_model_params_only, period, on_batch, pickle_module, pickle_protocol)