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: Returns the state of the optimizer as a :class:`dict`.
  
  It contains:
  * state - current state of the sparsification.
  * groups - a list containing all sparsity configuration groups
      with the key 'tensor_fqn' specifying the path to the sparsified tensor within a model
  
  TODO: Need a clean way of loading the state of the "prepared" module
docstr_tok: ["Returns","the","state","of","the","optimizer","as","a",":","class",":","`","dict","`",".","It","contains",":","*","state","-","current","state","of","the","sparsification",".","*","groups","-","a","list","containing","all","sparsity","configuration","groups","with","the","key","'tensor_fqn","'","specifying","the","path","to","the","sparsified","tensor","within","a","model","TODO",":","Need","a","clean","way","of","loading","the","state","of","the","``","prepared","''","module"]
code: def state_dict(self) -> Dict[str, Any]:
      r"""Returns the state of the optimizer as a :class:`dict`.
  
      It contains:
      * state - current state of the sparsification.
      * groups - a list containing all sparsity configuration groups
          with the key 'tensor_fqn' specifying the path to the sparsified tensor within a model
  
      TODO: Need a clean way of loading the state of the "prepared" module
      """
  
      groups: List[Dict[str, Any]] = [
          dict(
              filter(
                  lambda key_value: key_value[0]
                  not in KEYS_NOT_IN_STATE_DICT,
                  mg.items(),
              )
          )
          for mg in self.groups
      ]
  
      return {
          "state": self.state,
          "groups": groups,
      }
  
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 5 for calling the BaseSparsifier obj's underlying member method code with example usage: obj.state_dict() and returns: dict