code: def get_module_kohya_state_dict(
      module: PeftModel,
      prefix: str,
      dtype: torch.dtype,
      adapter_name: str = LORA_ADAPTER_NAME,
  ) -> Dict[str, torch.Tensor]:
      kohya_ss_state_dict = {}
      for peft_key, weight in get_peft_model_state_dict(
          module, adapter_name=adapter_name
      ).items():
          kohya_key = peft_key.replace("base_model.model", prefix)
          kohya_key = kohya_key.replace("lora_A", "lora_down")
          kohya_key = kohya_key.replace("lora_B", "lora_up")
          kohya_key = kohya_key.replace(
              ".", "_", kohya_key.count(".") - 2
          )
          kohya_ss_state_dict[kohya_key] = weight.to(dtype)
  
          # Set alpha parameter
          if "lora_down" in kohya_key:
              alpha_key = f'{kohya_key.split(".")[0]}.alpha'
              kohya_ss_state_dict[alpha_key] = torch.tensor(
                  module.peft_config[adapter_name].lora_alpha
              ).to(dtype)
  
      return kohya_ss_state_dict
  
file_path: peft/examples/lora_dreambooth/convert_peft_sd_lora_to_kohya_ss.py
imports: import argparse
  import os
  from typing import Dict
  import torch
  from diffusers import UNet2DConditionModel
  from safetensors.torch import save_file
  from transformers import CLIPTextModel
  from peft import PeftModel, get_peft_model_state_dict
label_desc: Use image node_id 1 for calling a global function with example usage: get_module_kohya_state_dict(module, prefix, dtype, adapter_name) and returns: kohya_ss_state_dict