Stable-Diffusion-Vertex/Diffusers/train_wo_nfs.py [22:62]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def bin_to_safetensors(output_path):
    newDict = dict();
    checkpoint = torch.load(output_path + '/pytorch_lora_weights.bin');
    for idx, key in enumerate(checkpoint):
      newKey = re.sub('\.processor\.', '_', key);
      newKey = re.sub('mid_block\.', 'mid_block_', newKey);
      newKey = re.sub('_lora.up.', '.lora_up.', newKey);
      newKey = re.sub('_lora.down.', '.lora_down.', newKey);
      newKey = re.sub('\.(\d+)\.', '_\\1_', newKey);
      newKey = re.sub('to_out', 'to_out_0', newKey);
      newKey = 'lora_unet_'+newKey;

      newDict[newKey] = checkpoint[key];

    newLoraName = 'pytorch_lora_weights.safetensors';
    print("Saving " + newLoraName);
    save_file(newDict, output_path + '/' + newLoraName);

def main(args):
    
    subprocess.run("accelerate config default", shell=True)
    subprocess.run("cat /root/.cache/huggingface/accelerate/default_config.yaml", shell=True)

    METHOD = args.method
    MODEL_NAME= args.model_name #"runwayml/stable-diffusion-v1-5"
    INSTANCE_DIR= args.input_storage
    OUTPUT_DIR= args.output_storage
    PROMPT = args.prompt
    CLASS_PROMPT = args.class_prompt
    NUM_CLASS_IMAGES = int(args.num_class_images)
    STEPS = int(args.max_train_steps)
    TEXT_ENCODER = bool(args.text_encoder)
    SET_GRADS_TO_NONE = bool(args.set_grads_to_none)
    
    RESOLUTION = int(args.resolution)
    BATCH_SIZE = int(args.batch_size)
    USE_8BIT = bool(args.use_8bit)
    LR = float(args.lr)
    GRADIENT_ACCU_STEPS = int(args.gradient_accumulation_steps)
    NUM_VALID_IMG = int(args.num_validation_images)
    VALID_PRMOP = args.validation_prompt
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



Stable-Diffusion-Vertex/hpo/diffusers/train_diffusers.py [22:62]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def bin_to_safetensors(output_path):
    newDict = dict();
    checkpoint = torch.load(output_path + '/pytorch_lora_weights.bin');
    for idx, key in enumerate(checkpoint):
      newKey = re.sub('\.processor\.', '_', key);
      newKey = re.sub('mid_block\.', 'mid_block_', newKey);
      newKey = re.sub('_lora.up.', '.lora_up.', newKey);
      newKey = re.sub('_lora.down.', '.lora_down.', newKey);
      newKey = re.sub('\.(\d+)\.', '_\\1_', newKey);
      newKey = re.sub('to_out', 'to_out_0', newKey);
      newKey = 'lora_unet_'+newKey;

      newDict[newKey] = checkpoint[key];

    newLoraName = 'pytorch_lora_weights.safetensors';
    print("Saving " + newLoraName);
    save_file(newDict, output_path + '/' + newLoraName);

def main(args):
    
    subprocess.run("accelerate config default", shell=True)
    subprocess.run("cat /root/.cache/huggingface/accelerate/default_config.yaml", shell=True)

    METHOD = args.method
    MODEL_NAME= args.model_name #"runwayml/stable-diffusion-v1-5"
    INSTANCE_DIR= args.input_storage
    OUTPUT_DIR= args.output_storage
    PROMPT = args.prompt
    CLASS_PROMPT = args.class_prompt
    NUM_CLASS_IMAGES = int(args.num_class_images)
    STEPS = int(args.max_train_steps)
    TEXT_ENCODER = bool(args.text_encoder)
    SET_GRADS_TO_NONE = bool(args.set_grads_to_none)
    
    RESOLUTION = int(args.resolution)
    BATCH_SIZE = int(args.batch_size)
    USE_8BIT = bool(args.use_8bit)
    LR = float(args.lr)
    GRADIENT_ACCU_STEPS = int(args.gradient_accumulation_steps)
    NUM_VALID_IMG = int(args.num_validation_images)
    VALID_PRMOP = args.validation_prompt
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



