class_docstr: `BetterTransformersTestMixin` to wrap necessary functions for testing `BetterTransformer`
  integration. This includes the following tests:
      - `test_logits`: This tests if the converted model produces the same logits
      than the original model.
      - `test_raise_on_save`: Test if the converion properly raises an error if someone tries to save the model using `save_pretrained`.
class_docstr_tok: ["`","BetterTransformersTestMixin","`","to","wrap","necessary","functions","for","testing","`","BetterTransformer","`","integration",".","This","includes","the","following","tests",":","-","`","test_logits","`",":","This","tests","if","the","converted","model","produces","the","same","logits","than","the","original","model",".","-","`","test_raise_on_save","`",":","Test","if","the","converion","properly","raises","an","error","if","someone","tries","to","save","the","model","using","`","save_pretrained","`","."]
docstr: A tests that checks if the training works as expected for decoder models.
docstr_tok: ["A","tests","that","checks","if","the","training","works","as","expected","for","decoder","models","."]
code: def _test_train_decoder(
      self, model_id: str, model_type: str, **kwargs
  ):
      r"""
      A tests that checks if the training works as expected for decoder models.
      """
      inputs = self.prepare_inputs_for_class(
          model_id=model_id, model_type=model_type, **kwargs
      )
  
      hf_random_model = AutoModel.from_pretrained(model_id).eval()
  
      bt_model = BetterTransformer.transform(
          hf_random_model, keep_original_model=True
      )
      bt_model.train()
      output = bt_model(**inputs)[0]
      loss = output.sum()
      loss.backward()
  
      # check if gradients are not None
      for name, param in bt_model.named_parameters():
          # TODO: is this normal? None even without bettertransformer
          if (
              hf_random_model.config.model_type == "pegasus"
              and "embed_positions.weight" in name
          ):
              continue
          self.assertIsNotNone(param.grad)
  
imports: import copy
  import inspect
  import tempfile
  import unittest
  import torch
  from transformers import AutoModel
  from optimum.bettertransformer import BetterTransformer
  from optimum.utils.testing_utils import flatten_dict, require_torch_gpu
label_desc: Use image node_id 6 for calling the BetterTransformersTestMixin obj's underlying member method code with example usage: obj._test_train_decoder(model_id, model_type) without return types