class_docstr: Common functionality between `Optimizer` and `OptimWrapper`
class_docstr_tok: ["Common","functionality","between","`","Optimizer","`","and","`","OptimWrapper","`"]
code: def freeze_to(self, n: int):  # Freeze up to `n` layers
      self.frozen_idx = n if n >= 0 else len(self.param_lists) + n
      if self.frozen_idx >= len(self.param_lists):
          warn(
              f"Freezing {self.frozen_idx} groups; model has {len(self.param_lists)}; whole model is frozen."
          )
      for o in self.all_params(slice(n, None)):
          self._set_require_grad(True, *o)
      for o in self.all_params(slice(None, n)):
          self._set_require_grad(False, *o)
  
imports: from __future__ import annotations
  from .torch_basics import *
label_desc: Use image node_id 3 for calling the _BaseOptimizer obj's underlying member method code with example usage: obj.freeze_to(n) without return types