code: def construct_peft_loraconfig(
      info: Dict[str, LoRAInfo]
  ) -> LoraConfig:
      """Constructs LoraConfig from data extracted from kohya checkpoint
  
      Args:
          info (Dict[str, LoRAInfo]): Information extracted from kohya checkpoint
  
      Returns:
          LoraConfig: config for constructing LoRA
      """
  
      # Unpack all ranks and alphas
      ranks = {x[0]: x[1].rank for x in info.items()}
      alphas = {x[0]: x[1].alpha or x[1].rank for x in info.items()}
  
      # Determine which modules needs to be transformed
      target_modules = list(info.keys())
  
      # Determine most common rank and alpha
      r = Counter(ranks.values()).most_common(1)[0]
      lora_alpha = Counter(alphas.values()).most_common(1)[0]
  
      # Determine which modules have different rank and alpha
      rank_pattern = dict(filter(lambda x: x[1] != r, ranks.items()))
      alpha_pattern = dict(
          filter(lambda x: x[1] != lora_alpha, alphas.items())
      )
  
      config = LoraConfig(
          r=r,
          lora_alpha=lora_alpha,
          target_modules=target_modules,
          lora_dropout=0.0,
          bias="none",
          init_lora_weights=False,
          rank_pattern=rank_pattern,
          alpha_pattern=alpha_pattern,
      )
  
      return config
  
file_path: peft/examples/lora_dreambooth/convert_kohya_ss_sd_lora_to_peft.py
imports: import argparse
  import os
  from collections import Counter
  from dataclasses import dataclass
  from typing import Dict, Optional
  import safetensors
  import torch
  from diffusers import UNet2DConditionModel
  from transformers import CLIPTextModel
  from peft import LoraConfig, get_peft_model, get_peft_model_state_dict, set_peft_model_state_dict
label_desc: Use image node_id 1 for calling a global function with example usage: construct_peft_loraconfig(info) and returns: config