code: def test_l1norm_pruner(self):
      torch.manual_seed(100)
      model = TorchModel1()
      dummy_input = torch.rand(3, 1, 28, 28)
      config_list = [{"op_types": ["Conv2d"], "sparsity": 0.5}]
      pruner = L1NormPruner(model=model, config_list=config_list)
      pruned_model, masks = pruner.compress()
      pruner.unwrap_model()
      sparsity_list = compute_sparsity_mask2compact(
          pruned_model, masks, config_list
      )
      # torch.manual_seed(100)
      speedup_model = ModelSpeedup(
          model, dummy_input, masks
      ).speedup_model()
  
      print("before:\n", model)
      print("after:\n", repr(speedup_model))
  
      real_sparsity_list = compute_sparsity_compact2origin(
          TorchModel1(), speedup_model, config_list
      )
      print("sparsity_list:", sparsity_list)
      assert 0.45 < sparsity_list[0]["total_sparsity"] < 0.55
  
      print("real_sparsity_list:", real_sparsity_list)
      assert 0.45 < real_sparsity_list[0]["total_sparsity"] < 0.75
  
      print(
          "the shape of output of the infer:",
          speedup_model(dummy_input).shape,
      )
      assert speedup_model(dummy_input).shape == torch.Size((5, 5))
  
imports: import unittest
  import torch
  import torch.nn.functional
  from nni.compression.pruning import L1NormPruner
  from nni.compression.speedup import ModelSpeedup
  from nni.compression.utils import compute_sparsity_compact2origin, compute_sparsity_mask2compact
label_desc: Use image node_id 1 for calling the AutoConvTestCase obj's underlying member method code with example usage: obj.test_l1norm_pruner() without return types