class_docstr: Magnitude-based static mask pruning method as described in
  `To prune, or not to prune: exploring the efficacy of  pruning for model
  compression <https://arxiv.org/pdf/1710.01878.pdf>`_
class_docstr_tok: ["Magnitude-based","static","mask","pruning","method","as","described","in","`","To","prune",",","or","not","to","prune",":","exploring","the","efficacy","of","pruning","for","model","compression","<","https",":","\/\/arxiv.org\/pdf\/1710.01878.pdf",">","`","_"]
code: def compute_mask(
      self, t: _torch.Tensor, default_mask: _torch.Tensor
  ) -> _torch.Tensor:
      if self.n_m_ratio is not None:
          _, block_size = self.n_m_ratio
          num_zeros = int(self.amount * block_size)
          if num_zeros == 0:
              # when number of zeros is < 0, we increase sparsity gradually
              return _magnitude_ranked_mask(
                  t, self.amount, 1, self.granularity
              ).float()
          else:
              return _n_m_mask(
                  t, (num_zeros, block_size), self.dim
              ).float()
      else:
          return _magnitude_ranked_mask(
              t, self.amount, self.block_size, self.granularity
          ).float()
  
imports: import copy
  import logging
  from collections import OrderedDict
  from typing import Any
  from typing import Callable
  from typing import Dict
  from typing import NewType
  from typing import Optional
  from typing import Tuple
  from typing import Union
  import attrs
  import cattrs
  import torch
  from attr import define
  from attr import field
  from attrs import validators
  from coremltools.optimize.torch._typing import ParamsDict
  from coremltools.optimize.torch.optimization_config import ModuleOptimizationConfig
  from coremltools.optimize.torch.optimization_config import OptimizationConfig
  from coremltools.optimize.torch.optimization_config import _structure_from_dict_hook_factory, _validate_module_type_keys_factory
  from coremltools.optimize.torch.pruning._base_pruner import BasePrunerWithPruningMethod
  from coremltools.optimize.torch.pruning._base_pruner import _allowed_granularity_values
  from coremltools.optimize.torch.pruning._base_pruning_method import ScheduledBaseDynamicPruningMethod
  from coremltools.optimize.torch.pruning._utils import magnitude_ranked_mask
  from coremltools.optimize.torch.pruning._utils import n_m_mask
  from coremltools.optimize.torch.pruning.pruning_scheduler import ConstantSparsityScheduler
  from coremltools.optimize.torch.pruning.pruning_scheduler import PruningScheduler
  from coremltools.optimize.torch.pruning.pruning_scheduler import _PruningSchedulerType
label_desc: Use image node_id 2 for calling the _MagnitudePruningMethod obj's underlying member method code with example usage: obj.compute_mask(t, default_mask) and returns: _magnitude_ranked_mask, _magnitude_ranked_mask, _n_m_mask