code: def cast_lora_weight(model, dtype=torch.bfloat16):
      for name, module in model.named_modules():
          if isinstance(module, LowBitLinear):
              module.compute_dtype = dtype
          if isinstance(module, LoraLayer):
              module = module.to(dtype)
          if isinstance(module, BF16Linear):
              module = module.to(dtype)
              module.compute_dtype = dtype
          if "norm" in name:
              module = module.to(torch.float32)
          if "lm_head" in name or "embed_tokens" in name:
              if hasattr(module, "weight"):
                  if module.weight.dtype == torch.float32:
                      module = module.to(dtype)
  
imports: import torch
  from torch.nn import Linear, Embedding
  from bigdl.llm.transformers.low_bit_linear import LowBitLinear, BF16Linear, get_qk_size
  from peft.tuners.lora import LoraLayer
  from bigdl.llm.utils.common import invalidInputError
  from bigdl.llm.transformers.utils import get_autocast_dtype
  from bigdl.llm.ggml.quantize import ggml_tensor_qtype
  import functools
  from bigdl.llm.transformers import training_patch
  from peft.tuners.lora import LoraModel
  from peft.tuners.lora import LoraConfig
  from dataclasses import dataclass, field
  from peft.mapping import PEFT_TYPE_TO_CONFIG_MAPPING
label_desc: Use image node_id 4 for calling a global function with example usage: cast_lora_weight(model, dtype) without return types