code: def test_qat_prep_before_s_prep(self):
      mod, sparsifier, _ = _get_model_and_sparsifier_and_sparse_config(
          tq.get_default_qat_qconfig("fbgemm")
      )
      tq.prepare_qat(mod, inplace=True)
  
      # need to setup sparse_config on new modules
      sparse_config = [
          {
              "tensor_fqn": "5.weight",
              "sparsity_level": 0.7,
              "sparse_block_shape": (1, 4),
              "zeros_per_block": 4,
          },
          {"tensor_fqn": "0.weight"},
      ]
      sparsifier.prepare(mod, config=sparse_config)
  
      # check that correct modules had parametrizations added and
      # that none were lost during qat prepare
      self.assertTrue(hasattr(mod[0], "parametrizations"))
      self.assertTrue(hasattr(mod[5], "parametrizations"))
  
      # check that correct observers were inserted and that matching
      # occurred successfully
      self.assertTrue(hasattr(mod[5], "activation_post_process"))
      self.assertTrue(isinstance(mod[5], torch.ao.nn.qat.Linear))
  
      _squash_mask_calibrate_and_convert(
          mod, sparsifier, torch.randn(1, 4, 4, 4)
      )
  
      # check that final module is the expected quantized module and that the model runs
      self.assertTrue(isinstance(mod[5], torch.ao.nn.quantized.Linear))
      self.assertEqual(
          mod(torch.randn(1, 4, 4, 4)).shape, torch.Size([1, 4, 4, 4])
      )
  
      # check that module was actually sparsified
      cur_sparsity = _calculate_sparsity(mod[5]._weight_bias()[0])
      self.assertGreaterAlmostEqual(
          cur_sparsity, sparse_config[0]["sparsity_level"]
      )
  
imports: import logging
  import torch
  import torch.ao.quantization
  from torch import nn
  from torch.ao import pruning
  from torch.testing._internal.common_utils import TestCase
  from torch.ao.quantization.quantize_fx import prepare_fx, convert_fx, convert_to_reference_fx, prepare_qat_fx
  from torch.ao.pruning import fqn_to_module
label_desc: Use image node_id 7 for calling the TestComposability obj's underlying member method code with example usage: obj.test_qat_prep_before_s_prep() without return types