code: def test_pruner_finalize(simple_module, granularity):
      config = MagnitudePrunerConfig.from_dict(
          {
              "global_config": {
                  "scheduler": {"update_steps": [2, 3]},
                  "initial_sparsity": 0.5,
                  "target_sparsity": 1.0,
                  "granularity": granularity,
              }
          },
      )
      pruner = MagnitudePruner(simple_module, config)
      simple_module = pruner.prepare()
  
      assert hasattr(simple_module.conv2d, "weight_mask")
      assert hasattr(simple_module.conv2d, "weight_orig")
  
      # Perform 4 iterations
      for _ in range(4):
          pruner.step()
  
      pruner.finalize(inplace=True)
  
      assert not hasattr(simple_module.conv2d, "weight_mask")
      assert not hasattr(simple_module.conv2d, "weight_orig")
  
      weight_data = simple_module.conv2d.weight.detach().numpy()
      np.testing.assert_equal(weight_data, np.zeros_like(weight_data))
  
      # calling finalize again is a no-op
      pruner.finalize(inplace=True)
  
imports: import copy
  from collections import OrderedDict
  import numpy
  import pytest
  import torch
  from coremltools.optimize.torch.pruning import MagnitudePruner, MagnitudePrunerConfig, ModuleMagnitudePrunerConfig
  from coremltools.optimize.torch.pruning._utils import n_m_mask
label_desc: Use image node_id 17 for calling a global function with example usage: test_pruner_finalize(simple_module, granularity) without return types