code: def activation_to_func(
      activation: str,
      openai_gelu: bool = False,
      onnx_safe: bool = False,
  ) -> Callable:
      """Converts an activation function represented as a string to a function.
  
      Args:
          activation (str): string representation of an activation function, typically gotten from the model config.
          openai_gelu (bool): whether to use the OpenAI GELU implementation. Used with HF compatibility.
          onnx_safe (bool): whether to use the ONNX-compatible implementation of GELU.
  
      Returns:
          Callable: the activation function.
      """
  
      supported_activations = [
          "gelu",
          "geglu",
          "reglu",
          "swiglu",
          "squared-relu",
          "fast-geglu",
          "fast-swiglu",
          "fast-reglu",
      ]
  
      if activation not in supported_activations:
          raise ValueError(
              f"Unsupported activation {activation}. Supported activations: {supported_activations} "
          )
  
      # Give openai_gelu precedence over other activations if set, for HF compatibility.
      # Normally this is off and shouldn't affect regular model training.
      if openai_gelu:
          activation_func = openai_gelu_func
      elif activation in ["gelu", "geglu", "fast-geglu"]:
          activation_func = F.gelu
      elif onnx_safe:
          activation_func = erf_gelu
      elif activation in ["reglu", "fast-reglu"]:
          activation_func = F.relu
      elif activation in ["swiglu", "fast-swiglu"]:
          # SiLU or sigmoid linear unit is the same as swish with beta = 1 (which is what https://arxiv.org/pdf/2002.05202.pdf uses.)
          activation_func = F.silu
      elif activation == "squared-relu":
          activation_func = squared_relu
  
      return activation_func
  
imports: import os
  import time
  from typing import Callable, Dict, List, Optional, Union
  import numpy
  import torch
  import torch.nn.functional
  from matplotlib import pyplot
  from sklearn.metrics import classification_report, confusion_matrix
  from torch import Tensor
  from nemo.collections.nlp.modules.common.megatron.utils import erf_gelu
  from nemo.collections.nlp.modules.common.megatron.utils import openai_gelu
  from nemo.collections.nlp.modules.common.megatron.utils import squared_relu
  from nemo.utils import logging
label_desc: Use image node_id 9 for calling a global function with example usage: activation_to_func(activation, openai_gelu, onnx_safe) and returns: activation_func