class_docstr: Common functionality between `Optimizer` and `OptimWrapper`
class_docstr_tok: ["Common","functionality","between","`","Optimizer","`","and","`","OptimWrapper","`"]
code: def _set_require_grad(
      self,
      rg: bool,  # Requires grad: if `True` sets gradient for parameters, else uses state `state["force_train"]`
      p: Tensor,  # Parameters to set gradient
      pg,  # Param groups (unused but needed because unpack *o)
      state: dict,
      h,  # Hyperparameter (unused but needed because unpack *o)
  ):
      p.requires_grad_(rg or state.get("force_train", False))
  
imports: from __future__ import annotations
  from .torch_basics import *
label_desc: Use image node_id 2 for calling the _BaseOptimizer obj's underlying member method code with example usage: obj._set_require_grad(rg, p, pg, state, h) without return types