class_docstr: <a id="NLPAutoRegressionConfigs"></a>
  
  ## Trainer configurations
  
  This has the basic configurations for NLP auto-regressive task training.
  All the properties are configurable.
class_docstr_tok: ["<","a","id=","''","NLPAutoRegressionConfigs","''",">","<","\/a",">","#","#","Trainer","configurations","This","has","the","basic","configurations","for","NLP","auto-regressive","task","training",".","All","the","properties","are","configurable","."]
docstr: ### Training or validation step
docstr_tok: ["#","#","#","Training","or","validation","step"]
code: def step(self, batch: any, batch_idx: BatchIndex):
      """
      ### Training or validation step
      """
  
      # Set training/eval mode
      self.model.train(self.mode.is_train)
  
      # Move data to the device
      data, target = batch[0].to(self.device), batch[1].to(self.device)
  
      # Update global step (number of tokens processed) when in training mode
      if self.mode.is_train:
          tracker.add_global_step(data.shape[0] * data.shape[1])
  
      # Whether to capture model outputs
      with self.mode.update(
          is_log_activations=batch_idx.is_last
          and self.is_log_model_activations
      ):
          # Get model outputs.
          # It's returning a tuple for states when using RNNs.
          # This is not implemented yet. 😜
          output, *_ = self.model(data)
  
      # Calculate and log loss
      loss = self.loss_func(output, target)
      tracker.add("loss.", loss)
  
      # Calculate and log accuracy
      self.accuracy(output, target)
      self.accuracy.track()
  
      self.other_metrics(output, target)
  
      # Train the model
      if self.mode.is_train:
          # Calculate gradients
          loss.backward()
          # Clip gradients
          torch.nn.utils.clip_grad_norm_(
              self.model.parameters(), max_norm=self.grad_norm_clip
          )
          # Take optimizer step
          self.optimizer.step()
          # Log the model parameters and gradients on last batch of every epoch
          if batch_idx.is_last and self.is_log_model_params_grads:
              tracker.add("model", self.model)
          # Clear the gradients
          self.optimizer.zero_grad()
  
      # Save the tracked metrics
      tracker.save()
  
imports: from typing import Callable
  import torch
  import torch.nn
  from torch.utils.data import DataLoader, RandomSampler
  from labml import lab, monit, logger, tracker
  from labml.configs import option
  from labml.logger import Text
  from labml_helpers.datasets.text import TextDataset, SequentialDataLoader, SequentialUnBatchedDataset, TextFileDataset
  from labml_helpers.device import DeviceConfigs
  from labml_helpers.metrics.accuracy import Accuracy
  from labml_helpers.module import Module
  from labml_helpers.train_valid import TrainValidConfigs, hook_model_outputs, BatchIndex
  from labml_nn.optimizers.configs import OptimizerConfigs
label_desc: Use image node_id 3 for calling the NLPAutoRegressionConfigs obj's underlying member method code with example usage: obj.step(batch, batch_idx) without return types