code: def __init__(self, sparsifier, last_epoch=-1, verbose=False):
      # Attach sparsifier
      if not isinstance(sparsifier, BaseSparsifier):
          raise TypeError(
              f"{type(sparsifier).__name__} is not an instance of torch.ao.pruning.BaseSparsifier"
          )
      self.sparsifier = sparsifier
  
      # Initialize epoch and base sparsity levels
  
      self.base_sl = [
          group["sparsity_level"] for group in sparsifier.groups
      ]
      self.last_epoch = last_epoch
  
      # Following https://github.com/pytorch/pytorch/issues/20124
      # We would like to ensure that `scheduler.step()` is called after
      # `sparsifier.step()`
      def with_counter(method):
          if getattr(method, "_with_counter", False):
              # `sparsifier.step()` has already been replaced, return.
              return method
  
          # Keep a weak reference to the sparsifier instance to prevent
          # cyclic references.
          instance_ref = weakref.ref(method.__self__)
          # Get the unbound method for the same purpose.
          func = method.__func__
          cls = instance_ref().__class__
          del method
  
          @wraps(func)
          def wrapper(*args, **kwargs):
              instance = instance_ref()
              instance._step_count += 1  # type: ignore[union-attr]
              wrapped = func.__get__(instance, cls)
              return wrapped(*args, **kwargs)
  
          # Note that the returned function here is no longer a bound method,
          # so attributes like `__func__` and `__self__` no longer exist.
          wrapper._with_counter = True  # type: ignore[attr-defined]
          return wrapper
  
      self.sparsifier.step = with_counter(self.sparsifier.step)  # type: ignore[assignment]
      self.sparsifier._step_count = 0  # type: ignore[attr-defined]
      self._step_count: int = 0
      self.verbose = verbose
  
      # Housekeeping
      self._get_sl_called_within_step: bool = False
  
      self.step()
  
file_path: pytorch/torch/ao/pruning/scheduler/base_scheduler.py
imports: from torch.ao.pruning import BaseSparsifier
  from functools import wraps
  import warnings
  import weakref
label_desc: Use image node_id 1 to create a new BaseScheduler object  with example: obj = BaseScheduler(sparsifier, last_epoch, verbose)