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","`","."]
code: def _test_save_load_invertible(
      self, model_id, keep_original_model=True
  ):
      with tempfile.TemporaryDirectory() as tmpdirname:
          hf_model = AutoModel.from_pretrained(model_id).eval()
          hf_model_state_dict = copy.deepcopy(hf_model.state_dict())
  
          bt_model = BetterTransformer.transform(
              hf_model, keep_original_model=keep_original_model
          )
  
          bt_model = BetterTransformer.reverse(bt_model)
  
          for name, param in bt_model.named_parameters():
              self.assertFalse(
                  param.device.type == "meta",
                  f"Parameter {name} is on the meta device.",
              )
  
          bt_model.save_pretrained(tmpdirname)
  
          bt_model_from_load = AutoModel.from_pretrained(tmpdirname)
  
          self.assertEqual(
              set(bt_model.state_dict().keys()),
              set(bt_model_from_load.state_dict().keys()),
          )
  
          self.assertEqual(
              hf_model_state_dict.keys(),
              set(bt_model_from_load.state_dict().keys()),
          )
  
          for key in bt_model.state_dict().keys():
              self.assertTrue(
                  torch.allclose(
                      bt_model.state_dict()[key],
                      bt_model_from_load.state_dict()[key],
                  )
              )
  
              self.assertTrue(
                  torch.allclose(
                      hf_model_state_dict[key],
                      bt_model_from_load.state_dict()[key],
                  )
              )
  
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 8 for calling the BetterTransformersTestMixin obj's underlying member method code with example usage: obj._test_save_load_invertible(model_id, keep_original_model) without return types