code: def add_regular_to_grad(
      self, grad, model_weights, fit_intercept=False
  ):
      if self.l2_penalty:
          if fit_intercept:
              weights_sum = torch.concat(
                  (model_weights[:-1], torch.tensor([[0]]))
              )
              # logger.info(f"grad: {grad}, weights sum: {weights_sum}")
              new_grad = grad + self.alpha * weights_sum
          else:
              new_grad = grad + self.alpha * model_weights
      else:
          new_grad = grad
  
      return new_grad
  
imports: import logging
  import numpy
  import torch
label_desc: Use image node_id 10 for calling the Optimizer obj's underlying member method code with example usage: obj.add_regular_to_grad(grad, model_weights, fit_intercept) and returns: new_grad