code: def cast_training_params(
      model: Union[torch.nn.Module, List[torch.nn.Module]],
      dtype=torch.float32,
  ):
      if not isinstance(model, list):
          model = [model]
      for m in model:
          for param in m.parameters():
              # only upcast trainable parameters into fp32
              if param.requires_grad:
                  param.data = param.to(dtype)
  
imports: import contextlib
  import copy
  import random
  from typing import Any, Dict, Iterable, List, Optional, Union
  import numpy
  import torch
  from torchvision import transforms
  from .models import UNet2DConditionModel
  from .utils import convert_state_dict_to_diffusers, convert_state_dict_to_peft, deprecate, is_peft_available, is_transformers_available
label_desc: Use image node_id 5 for calling a global function with example usage: cast_training_params(model, dtype) without return types