class_docstr: This is the base PyTorchTrial for transformers that implements the ``__init__`` and
  ``train_batch`` methods.
  
  You can subclass ``BaseTransformerTrial`` to customize a trial for your own usage by filing in
  the expected methods for data loading and evaluation.
class_docstr_tok: ["This","is","the","base","PyTorchTrial","for","transformers","that","implements","the","``","__init__","``","and","``","train_batch","``","methods",".","You","can","subclass","``","BaseTransformerTrial","``","to","customize","a","trial","for","your","own","usage","by","filing","in","the","expected","methods","for","data","loading","and","evaluation","."]
code: def train_batch(
      self, batch: Any, epoch_idx: int, batch_idx: int
  ) -> Any:
      # By default, all HF models return the loss in the first element.
      # We do not automatically apply a label smoother for the user.
      # If this is something you want to use, please see how it's
      # applied by transformers.Trainer:
      # https://github.com/huggingface/transformers/blob/v4.3.3/src/transformers/trainer.py#L1324
      outputs = self.model(**batch)
      loss = (
          outputs["loss"] if isinstance(outputs, dict) else outputs[0]
      )
      self.context.backward(loss)
      self.context.step_optimizer(self.optimizer, self.grad_clip_fn)
      return loss
  
file_path: determined/model_hub/model_hub/huggingface/_trial.py
imports: import dataclasses
  import logging
  from typing import Any, Dict, List, Optional, Tuple, Union, cast
  import datasets
  import torch
  import transformers
  import transformers.optimization
  import determined.pytorch
  from model_hub import utils
  from model_hub.huggingface import _config_parser
label_desc: Use image node_id 3 for calling the BaseTransformerTrial obj's underlying member method code with example usage: obj.train_batch(batch, epoch_idx, batch_idx) and returns: loss