code: def stats_to_np(stats_dict):
      """Cast all torch.tensors in dict to numpy arrays."""
      new_dict: Dict[str, Any] = dict()
      for k, v in stats_dict.items():
          if isinstance(v, torch.Tensor):
              new_dict[k] = v.detach().cpu()
              if new_dict[k].dtype == torch.bfloat16:
                  new_dict[k] = new_dict[k].float()
              new_dict[k] = new_dict[k].numpy()
          else:
              new_dict[k] = v
          if np.isscalar(new_dict[k]):
              new_dict[k] = float(new_dict[k])
      return new_dict
  
imports: import math
  import time
  import warnings
  from collections.abc import Mapping
  from typing import Any, Dict, List, Optional, Union
  import numpy
  import torch
  import torch.nn.functional
  from datasets import Dataset
  from huggingface_hub import PyTorchModelHubMixin
  from torch.cuda.amp import autocast
  from torch.nn.utils.rnn import pad_sequence
  from torch.utils.data import DataLoader
  from transformers import DataCollatorForLanguageModeling, PreTrainedTokenizer, PreTrainedTokenizerFast
  from llm_studio.src.utils.modeling_utils import unwrap_model
label_desc: Use image node_id 9 for calling a global function with example usage: stats_to_np(stats_dict) and returns: new_dict