class_docstr: Base class for all pruners which use a PruningMethod (implemented in
class_docstr_tok: ["Base","class","for","all","pruners","which","use","a","PruningMethod","(","implemented","in"]
docstr: Prepares the model for export. Removes pruning forward pre-hooks
  attached to submodules and commits pruning changes to pruned module parameters by
  multiplying the pruning masks with the parameter matrix.
  
  Args:
      model (:obj:`nn.Module`): model to finalize
      inplace (:obj:`bool`): If ``True``, model transformations are carried out in-place and
          the original module is mutated, otherwise a copy of the model is mutated and returned.
docstr_tok: ["Prepares","the","model","for","export",".","Removes","pruning","forward","pre-hooks","attached","to","submodules","and","commits","pruning","changes","to","pruned","module","parameters","by","multiplying","the","pruning","masks","with","the","parameter","matrix",".","Args",":","model","(",":","obj",":","`","nn.Module","`",")",":","model","to","finalize","inplace","(",":","obj",":","`","bool","`",")",":","If","``","True","``",",","model","transformations","are","carried","out","in-place","and","the","original","module","is","mutated",",","otherwise","a","copy","of","the","model","is","mutated","and","returned","."]
code: def finalize(
      self,
      model: _Optional[_torch.nn.Module] = None,
      inplace: bool = False,
  ) -> _torch.nn.Module:
      """
      Prepares the model for export. Removes pruning forward pre-hooks
      attached to submodules and commits pruning changes to pruned module parameters by
      multiplying the pruning masks with the parameter matrix.
  
      Args:
          model (:obj:`nn.Module`): model to finalize
          inplace (:obj:`bool`): If ``True``, model transformations are carried out in-place and
              the original module is mutated, otherwise a copy of the model is mutated and returned.
      """
      if model is None:
          model = self._model
      finalized_model = model if inplace else _copy.deepcopy(model)
      for _, submodule in finalized_model.named_modules(
          remove_duplicate=True
      ):
          if hasattr(submodule, "pruning_method"):
              submodule.pruning_method.remove(submodule)
      if model is None:
          self._model = finalized_model
      return finalized_model
  
file_path: coremltools/coremltools/optimize/torch/pruning/_base_pruner.py
imports: import copy
  import logging
  from typing import Optional
  from typing import Tuple
  import torch
  from coremltools.optimize.torch._utils.torch_utils import get_eval_model
  from coremltools.optimize.torch.base_model_optimizer import BaseModelOptimizer
  from coremltools.optimize.torch.base_model_optimizer import _Report
  from coremltools.optimize.torch.optimization_config import OptimizationConfig
  from coremltools.optimize.torch.pruning._utils import get_global_sparsity_summaries
label_desc: Use image node_id 5 for calling the BasePrunerWithPruningMethod obj's underlying member method code with example usage: obj.finalize(model, inplace) and returns: finalized_model