class_docstr: Base class for all sparsifiers.
  
  Abstract methods that need to be implemented:
  
  - update_mask: Function to compute a new mask for all keys in the
      `groups`.
  
  Args:
      - model [nn.Module]: model to configure. The model itself is not saved
          but used for the state_dict saving / loading.
      - config [list]: configuration elements should be a dict map that includes
          `tensor_fqn` of tensors to sparsify
      - defaults [dict]: default configurations will be attached to the
          configuration. Only the keys that don't exist in the `config` will
          be updated.
  
  Example::
  
      >>> # xdoctest: +SKIP("Can't instantiate abstract class BaseSparsifier with abstract method update_mask")
      >>> config = [{'tensor_fqn': 'layer1.weight', 'tensor_fqn': 'linear2.weight2', 'sparsity_level': 0.5}]
      >>> defaults = {'sparsity_level': 0.7}
      >>> # model.layer1.weight will have `sparsity_level` = 0.7 (getting default)
      >>> sparsifier = BaseSparsifier(config, defaults)
class_docstr_tok: ["Base","class","for","all","sparsifiers",".","Abstract","methods","that","need","to","be","implemented",":","-","update_mask",":","Function","to","compute","a","new","mask","for","all","keys","in","the","`","groups","`",".","Args",":","-","model","[","nn.Module","]",":","model","to","configure",".","The","model","itself","is","not","saved","but","used","for","the","state_dict","saving","\/","loading",".","-","config","[","list","]",":","configuration","elements","should","be","a","dict","map","that","includes","`","tensor_fqn","`","of","tensors","to","sparsify","-","defaults","[","dict","]",":","default","configurations","will","be","attached","to","the","configuration",".","Only","the","keys","that","do","n't","exist","in","the","`","config","`","will","be","updated",".","Example",":",":",">",">",">","#","xdoctest",":","+SKIP","(","``","Ca","n't","instantiate","abstract","class","BaseSparsifier","with","abstract","method","update_mask","''",")",">",">",">","config","=","[","{","'tensor_fqn","'",":","'layer1.weight","'",",","'tensor_fqn","'",":","'linear2.weight2","'",",","'sparsity_level","'",":","0.5","}","]",">",">",">","defaults","=","{","'sparsity_level","'",":","0.7","}",">",">",">","#","model.layer1.weight","will","have","`","sparsity_level","`","=","0.7","(","getting","default",")",">",">",">","sparsifier","=","BaseSparsifier","(","config",",","defaults",")"]
docstr: Converts submodules in input module to a different module according to `mapping`
  by calling `from_dense` method on the target module class
  Args:
      module: input module
      mapping: a dictionary that maps from source module type to target
          module type, can be overwritten to allow swapping user defined
          Modules
      inplace: carry out model transformations in-place, the original module
          is mutated
docstr_tok: ["Converts","submodules","in","input","module","to","a","different","module","according","to","`","mapping","`","by","calling","`","from_dense","`","method","on","the","target","module","class","Args",":","module",":","input","module","mapping",":","a","dictionary","that","maps","from","source","module","type","to","target","module","type",",","can","be","overwritten","to","allow","swapping","user","defined","Modules","inplace",":","carry","out","model","transformations","in-place",",","the","original","module","is","mutated"]
code: def convert(
      self,
      module: nn.Module,
      mapping: Optional[Dict[Type[nn.Module], Type[nn.Module]]] = None,
      inplace: bool = False,
      parameterization: Type[nn.Module] = FakeSparsity,
  ):
      r"""Converts submodules in input module to a different module according to `mapping`
      by calling `from_dense` method on the target module class
      Args:
          module: input module
          mapping: a dictionary that maps from source module type to target
              module type, can be overwritten to allow swapping user defined
              Modules
          inplace: carry out model transformations in-place, the original module
              is mutated
      """
      if mapping is None:
          raise NotImplementedError("Need to auto generate mapping ")
      if not inplace:
          module = copy.deepcopy(module)
  
      reassign = {}
      for name, mod in module.named_children():
          # leaf node
          if (
              module_contains_param(mod, parameterization)
              and type_before_parametrizations(mod) in mapping
          ):
              reassign[name] = swap_module(mod, mapping)
          else:
              # recurse
              reassign[name] = self.convert(
                  mod,
                  mapping=mapping,
                  inplace=True,
                  parameterization=parameterization,
              )
  
      for key, value in reassign.items():
          module._modules[key] = value
  
      return module
  
imports: import abc
  import copy
  from collections import defaultdict
  from typing import Any, Dict, Optional, Set, Tuple, List, Type
  import torch
  from torch import nn
  from torch.nn.utils import parametrize
  from torch.nn.utils.parametrize import type_before_parametrizations
  from .utils import module_contains_param, swap_module, FakeSparsity, get_arg_info_from_tensor_fqn, module_to_fqn
label_desc: Use image node_id 11 for calling the BaseSparsifier obj's underlying member method code with example usage: obj.convert(module, mapping, inplace, parameterization) and returns: module