docstr: Fit the model.
  
  Parameters
  ---------- 
  dataset: dc.data.Dataset
    Dataset object holding training data 
  nb_epoch: 10
    Number of training epochs.
  max_checkpoints_to_keep: int
    Maximum number of checkpoints to keep; older checkpoints will be deleted.
  log_every_N_batches: int
    Report every N batches. Useful for training on very large datasets,
    where epochs can take long time to finish.
  checkpoint_interval: int
    Frequency at which to write checkpoints, measured in epochs
  
  Raises
  ------
  AssertionError
    If model is not in training mode.
docstr_tok: ["Fit","the","model",".","Parameters","--","--","--","--","--","dataset",":","dc.data.Dataset","Dataset","object","holding","training","data","nb_epoch",":","10","Number","of","training","epochs",".","max_checkpoints_to_keep",":","int","Maximum","number","of","checkpoints","to","keep",";","older","checkpoints","will","be","deleted",".","log_every_N_batches",":","int","Report","every","N","batches",".","Useful","for","training","on","very","large","datasets",",","where","epochs","can","take","long","time","to","finish",".","checkpoint_interval",":","int","Frequency","at","which","to","write","checkpoints",",","measured","in","epochs","Raises","--","--","--","AssertionError","If","model","is","not","in","training","mode","."]
code: def fit(
      self,
      dataset,
      nb_epoch=10,
      max_checkpoints_to_keep=5,
      log_every_N_batches=50,
      checkpoint_interval=10,
      **kwargs,
  ):
      """Fit the model.
  
      Parameters
      ----------
      dataset: dc.data.Dataset
        Dataset object holding training data
      nb_epoch: 10
        Number of training epochs.
      max_checkpoints_to_keep: int
        Maximum number of checkpoints to keep; older checkpoints will be deleted.
      log_every_N_batches: int
        Report every N batches. Useful for training on very large datasets,
        where epochs can take long time to finish.
      checkpoint_interval: int
        Frequency at which to write checkpoints, measured in epochs
  
      Raises
      ------
      AssertionError
        If model is not in training mode.
      """
      ############################################################## TIMING
      time1 = time.time()
      ############################################################## TIMING
      log("Training for %d epochs" % nb_epoch, self.verbose)
      for epoch in range(nb_epoch):
          avg_loss, n_batches = 0.0, 0
          for ind, (X_b, y_b, w_b, ids_b) in enumerate(
              # Turns out there are valid cases where we don't want pad-batches
              # on by default.
              # dataset.iterbatches(batch_size, pad_batches=True)):
              dataset.iterbatches(
                  self.batch_size, pad_batches=self.pad_batches
              )
          ):
              if ind % log_every_N_batches == 0:
                  log("On batch %d" % ind, self.verbose)
              # Run training op.
              self.optimizer.zero_grad()
              X_b_input = torch.autograd.Variable(
                  torch.cuda.FloatTensor(X_b)
              )
              y_b_input = torch.autograd.Variable(
                  torch.cuda.FloatTensor(y_b)
              )
              w_b_input = torch.autograd.Variable(
                  torch.cuda.FloatTensor(w_b)
              )
              outputs = self.forward(X_b_input, training=True)
              loss = self.add_training_cost(
                  outputs, y_b_input, w_b_input
              )
              loss.backward()
              self.optimizer.step()
              avg_loss += loss
              n_batches += 1
          avg_loss = float(avg_loss.data.cpu().numpy()) / n_batches
          log(
              "Ending epoch %d: Average loss %g" % (epoch, avg_loss),
              self.verbose,
          )
      time2 = time.time()
      print(
          "TIMING: model fitting took %0.3f s" % (time2 - time1),
          self.verbose,
      )
  
file_path: deepchem/contrib/torch/torch_model.py
imports: import torch
  import time
  import numpy
  from deepchem.trans import undo_transforms
  from deepchem.utils.save import log
  from deepchem.models import Model
label_desc: Use image node_id 4 for calling the TorchMultitaskModel obj's underlying member method code with example usage: obj.fit(dataset, nb_epoch, max_checkpoints_to_keep, log_every_N_batches, checkpoint_interval) without return types