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: Test that the inverse converted model and hf model have the same modules
docstr_tok: ["Test","that","the","inverse","converted","model","and","hf","model","have","the","same","modules"]
code: def _test_invert_modules(self, model_id, keep_original_model=False):
      r"""
      Test that the inverse converted model and hf model have the same modules
      """
      hf_model = AutoModel.from_pretrained(model_id)
      hf_modules = list(hf_model.modules())
  
      bt_model = BetterTransformer.transform(
          hf_model, keep_original_model=keep_original_model
      )
      bt_model = BetterTransformer.reverse(bt_model)
  
      bt_modules = list(bt_model.modules())
  
      self.assertEqual(len(hf_modules), len(bt_modules))
      for hf_module, bt_module in zip(hf_modules, bt_modules):
          # check the modules have the same signature and code
          # for the `forward` and `__init__` methods
          # as those are the only functions we change
          self.assertEqual(
              inspect.signature(hf_module.forward),
              inspect.signature(bt_module.forward),
          )
          self.assertEqual(
              inspect.signature(hf_module.__init__),
              inspect.signature(bt_module.__init__),
          )
  
          self.assertEqual(
              inspect.getsource(hf_module.forward),
              inspect.getsource(bt_module.forward),
          )
          self.assertEqual(
              inspect.getsource(hf_module.__init__),
              inspect.getsource(bt_module.__init__),
          )
  
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 7 for calling the BetterTransformersTestMixin obj's underlying member method code with example usage: obj._test_invert_modules(model_id, keep_original_model) without return types