class_docstr: Here we also overwrite some of the tests of test_modeling_common.py, as Levit does not use input_ids, inputs_embeds,
  attention_mask and seq_length.
class_docstr_tok: ["Here","we","also","overwrite","some","of","the","tests","of","test_modeling_common.py",",","as","Levit","does","not","use","input_ids",",","inputs_embeds",",","attention_mask","and","seq_length","."]
code: def test_hidden_states_output(self):
      def check_hidden_states_output(inputs_dict, config, model_class):
          model = model_class(config)
          model.to(torch_device)
          model.eval()
  
          with torch.no_grad():
              outputs = model(
                  **self._prepare_for_class(inputs_dict, model_class)
              )
  
          hidden_states = outputs.hidden_states
  
          expected_num_layers = len(self.model_tester.depths) + 1
          self.assertEqual(len(hidden_states), expected_num_layers)
  
          image_size = (
              self.model_tester.image_size,
              self.model_tester.image_size,
          )
          height, width = image_size[0], image_size[1]
          for _ in range(4):
              height = floor(
                  (
                      (
                          height
                          + 2 * self.model_tester.padding
                          - self.model_tester.kernel_size
                      )
                      / self.model_tester.stride
                  )
                  + 1
              )
              width = floor(
                  (
                      (
                          width
                          + 2 * self.model_tester.padding
                          - self.model_tester.kernel_size
                      )
                      / self.model_tester.stride
                  )
                  + 1
              )
          # verify the first hidden states (first block)
          self.assertListEqual(
              list(hidden_states[0].shape[-2:]),
              [
                  height * width,
                  self.model_tester.hidden_sizes[0],
              ],
          )
  
      (
          config,
          inputs_dict,
      ) = self.model_tester.prepare_config_and_inputs_for_common()
  
      for model_class in self.all_model_classes:
          inputs_dict["output_hidden_states"] = True
          check_hidden_states_output(inputs_dict, config, model_class)
  
          # check that output_hidden_states also work using config
          del inputs_dict["output_hidden_states"]
          config.output_hidden_states = True
  
          check_hidden_states_output(inputs_dict, config, model_class)
  
imports: import inspect
  import unittest
  import warnings
  from math import ceil, floor
  from transformers import LevitConfig
  from transformers.file_utils import cached_property, is_torch_available, is_vision_available
  from transformers.models.auto import get_values
  from transformers.testing_utils import require_torch, require_vision, slow, torch_device
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
label_desc: Use image node_id 8 for calling the LevitModelTest obj's underlying member method code with example usage: obj.test_hidden_states_output() without return types