code: def QHAdam(
      params: Tensor | Iterable,  # Model parameters
      lr: float | slice,  # Default learning rate
      mom: float = 0.999,  # Gradient moving average (β1) coefficient
      sqr_mom: float = 0.999,  # Gradient squared moving average (β2) coefficient
      nu_1: float = 0.7,  # QH immediate discount factor
      nu_2: float = 1.0,  # QH momentum discount factor
      eps: float = 1e-8,  # Added for numerical stability
      wd: Real = 0.0,  # Optional weight decay (true or L2)
      decouple_wd: bool = True,  # Apply true weight decay (QHAdamW) or L2 regularization (QHAdam)
  ) -> Optimizer:
      "A QHAdam/QHAdamW `Optimizer`"
      cbs = [weight_decay] if decouple_wd else [l2_reg]
      cbs += [
          partial(average_grad, dampening=True),
          partial(average_sqr_grad, dampening=True),
          step_stat,
          qhadam_step,
      ]
      return Optimizer(
          params,
          cbs,
          lr=lr,
          nu_1=nu_1,
          nu_2=nu_2,
          mom=mom,
          sqr_mom=sqr_mom,
          eps=eps,
          wd=wd,
      )
  
imports: from __future__ import annotations
  from .torch_basics import *
label_desc: Use image node_id 18 for calling a global function with example usage: QHAdam(params, lr, mom, sqr_mom, nu_1, nu_2, eps, wd, decouple_wd) and returns: Optimizer