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 __init__(self, context: det_torch.PyTorchTrialContext) -> None:
      self.context = context
      # A subclass of BaseTransformerTrial may have already set hparams and data_config
      # attributes so we only reset them if they do not exist.
      if not hasattr(self, "hparams"):
          self.hparams = utils.AttrDict(context.get_hparams())
      if not hasattr(self, "data_config"):
          self.data_config = utils.AttrDict(context.get_data_config())
      if not hasattr(self, "exp_config"):
          self.exp_config = utils.AttrDict(
              context.get_experiment_config()
          )
      # Check to make sure all expected hyperparameters are set.
      self.check_hparams()
  
      # Parse hparams and data_config.
      (
          self.config_kwargs,
          self.tokenizer_kwargs,
          self.model_kwargs,
      ) = hf_parse.default_parse_config_tokenizer_model_kwargs(
          self.hparams
      )
      (
          optimizer_kwargs,
          scheduler_kwargs,
      ) = hf_parse.default_parse_optimizer_lr_scheduler_kwargs(
          self.hparams
      )
  
      self.config, self.tokenizer, self.model = build_using_auto(
          self.config_kwargs,
          self.tokenizer_kwargs,
          self.hparams.model_mode,
          self.model_kwargs,
          use_pretrained_weights=self.hparams.use_pretrained_weights,
      )
      self.model = self.context.wrap_model(self.model)
  
      self.optimizer = self.context.wrap_optimizer(
          build_default_optimizer(self.model, optimizer_kwargs)
      )
  
      if self.hparams.use_apex_amp:
          self.model, self.optimizer = self.context.configure_apex_amp(
              models=self.model,
              optimizers=self.optimizer,
          )
  
      self.lr_scheduler = self.context.wrap_lr_scheduler(
          build_default_lr_scheduler(self.optimizer, scheduler_kwargs),
          det_torch.LRScheduler.StepMode.STEP_EVERY_BATCH,
      )
  
      self.grad_clip_fn = None
  
      if optimizer_kwargs.max_grad_norm > 0:  # type: ignore
          self.grad_clip_fn = lambda x: torch.nn.utils.clip_grad_norm_(
              x, optimizer_kwargs.max_grad_norm
          )
  
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 1 to create a new BaseTransformerTrial object from inherited base classes: det_torch with example: obj = BaseTransformerTrial(context)