code: def reg_loss(
      model: nn.Module,
      regularizer: str,
      l1: float = 0.01,
      l2: float = 0.01,
  ):
      """Computes the regularization loss for a given model.
  
      Parameters:
          model: torch.nn.Module object to compute regularization loss for.
          regularizer: regularizer to use (currently l1, l2 and l1_l2 supported).
          l1: L1 regularization coefficient.
          l2: L2 regularization coefficient.
  
      Returns:
          Regularization loss for the model (float).
      """
  
      if regularizer == "l1":
          l1_reg = l1 * sum(
              torch.abs(p).sum() for p in model.parameters()
          )
          return l1_reg
      if regularizer == "l2":
          l2_reg = l2 * sum(
              torch.square(p).sum() for p in model.parameters()
          )
          return l2_reg
      if regularizer == "l1_l2":
          l1_reg = l1 * sum(
              torch.abs(p).sum() for p in model.parameters()
          )
          l2_reg = l2 * sum(
              torch.square(p).sum() for p in model.parameters()
          )
          return l1_reg + l2_reg
  
imports: import math
  import os
  import warnings
  from abc import abstractmethod
  from functools import lru_cache
  from typing import List, Optional, Tuple, Union
  import torch
  from torch import nn
  from torch.nn import Module, ModuleDict
  from ludwig.api_annotations import DeveloperAPI
  from ludwig.constants import ENCODER_OUTPUT
  from ludwig.utils.strings_utils import SpecialSymbol
label_desc: Use image node_id 8 for calling a global function with example usage: reg_loss(model, regularizer, l1, l2) and returns: l1_reg, l2_reg, unknown