docstr: The expectation is post_training_sparse_quantize function
  1. Takes in a model
  2. Sparsifies the embeddings
  3. Quantize the embeddings
  
  This unit test checks that
  1. Embeddings and EmbeddingBags are sparsified to the right sparsity levels
  2. Embeddings and EmbeddingBags are quantized
  3. Linear modules are not quantized
docstr_tok: ["The","expectation","is","post_training_sparse_quantize","function","1",".","Takes","in","a","model","2",".","Sparsifies","the","embeddings","3",".","Quantize","the","embeddings","This","unit","test","checks","that","1",".","Embeddings","and","EmbeddingBags","are","sparsified","to","the","right","sparsity","levels","2",".","Embeddings","and","EmbeddingBags","are","quantized","3",".","Linear","modules","are","not","quantized"]
code: def test_ptq_sparsify_first(self):
      """The expectation is post_training_sparse_quantize function
      1. Takes in a model
      2. Sparsifies the embeddings
      3. Quantize the embeddings
  
      This unit test checks that
      1. Embeddings and EmbeddingBags are sparsified to the right sparsity levels
      2. Embeddings and EmbeddingBags are quantized
      3. Linear modules are not quantized
      """
      model = Model()
  
      sparse_config = {
          "sparsity_level": 0.80,
          "sparse_block_shape": (1, 1),
      }
      select_embeddings = [model.embbag1, model.emb1]
      post_training_sparse_quantize(
          model,
          data_sparsifier_class=DataNormSparsifier,
          sparsify_first=True,
          select_embeddings=select_embeddings,
          **sparse_config,
      )
  
      assert (
          type(model.emb1)
          == torch.ao.nn.quantized.modules.embedding_ops.Embedding
      )
      assert (
          type(model.embbag1)
          == torch.ao.nn.quantized.modules.embedding_ops.EmbeddingBag
      )
      assert type(model.emb_seq[0] == nn.Embedding)
      assert type(model.emb_seq[1] == nn.EmbeddingBag)
      assert type(model.linear1) == nn.Linear
      assert type(model.linear2) == nn.Linear
  
      dequant_emb1 = torch.dequantize(model.emb1.weight())
      dequant_embbag1 = torch.dequantize(model.embbag1.weight())
  
      threshold = 1e-2
  
      sl_emb1 = (torch.abs(dequant_emb1) < threshold).float().mean()
      sl_embbag1 = (
          (torch.abs(dequant_embbag1) < threshold).float().mean()
      )
  
      assert abs(sl_emb1 - 0.80) <= 0.05  # +- 5% leeway
      assert abs(sl_embbag1 - 0.80) <= 0.05
  
imports: import logging
  import torch
  from torch.nn.utils.parametrize import is_parametrized
  from torch.testing._internal.common_utils import TestCase
  from typing import Tuple
  from torch import nn
  import itertools
  import math
  import copy
  from torch.ao.pruning._experimental.data_sparsifier import BaseDataSparsifier, DataNormSparsifier
  from torch.ao.pruning._experimental.data_sparsifier.quantization_utils import post_training_sparse_quantize
label_desc: Use image node_id 1 for calling the TestQuantizationUtils obj's underlying member method code with example usage: obj.test_ptq_sparsify_first() without return types