metercai / SimpleSDXL

Enhanced version of Fooocus for SDXL, more suitable for Chinese and Cloud
GNU General Public License v3.0
688 stars 32 forks source link

[Bug]: win2_960 Does Not Load LoRAs from Metadata #82

Closed DavidDragonsage closed 2 months ago

DavidDragonsage commented 2 months ago

Checklist

What happened?

When I wanted to work on an image I had created previously, I loaded the image into the metadata window and applied the metadata. Image creation appeared to proceed normally except that just before the image was saved this error occurred: "FileNotFoundError: [Errno 2] No such file or directory: 'F:\SimpleAI\SimpleModels\loras\sd_xl_offset_example-lora_1.0'" this error prevented the new image from being saved.

Steps to reproduce the problem

1) Create an image in the SimpleSDXL2 win2_960 version, using one or more LoRAs 2) Load and apply the metadata from that image 3) Regenerate the image 4) The image appears to regenerate properly but it does not save when the generation is complete. Instead an error appears in the console.

What should have happened?

The image should have regenerated properly.

What browsers do you use to access Fooocus?

Mozilla Firefox

Where are you running Fooocus?

Locally

What operating system are you using?

Windows 10

Console logs

[Comfyd] Starting Comfyd server!

[ToolBox] Reset_params_from_image: -->SDXL-Fooocus params from the image with embedded parameters.
reciver prompt:a Tamil man walks away and climbs the mystic never ending stairs on a dark and stormy night. Sharp background, deep depth of field
[Fooocus] GPU memory: max_reserved=2.080GB, max_allocated=1.973GB, reserved=2.080GB, free=8.903GB, free_torch=0.107GB, free_total=9.011GB, gpu_total=12.000GB, torch_total=2.080GB
[TaskEngine] Task_class:Fooocus, Task_name:default, Task_method:text2image
[TaskEngine] Enable Fooocus backend.
[Comfyd] Comfyd freeing!
[Parameters] Adaptive CFG = 7
[Parameters] CLIP Skip = 2
[Parameters] Sharpness = 8
[Parameters] ControlNet Softness = 0.25
[Parameters] ADM Scale = 1.5 : 0.8 : 0.3
[Parameters] Seed = 7841085968682328112
[Parameters] CFG = 7
[Fooocus] Loading control models ...
[Parameters] Sampler = dpmpp_2m_sde_gpu - karras
[Parameters] Steps = 30 - 18
[Fooocus] Initializing ...
[Fooocus] Loading models ...
Refiner unloaded.
model_type EPS
UNet ADM Dimension 2816
Using xformers attention in VAE
Working with z of shape (1, 4, 32, 32) = 4096 dimensions.
Using xformers attention in VAE
extra {'cond_stage_model.clip_l.logit_scale', 'cond_stage_model.clip_l.text_projection'}
left over keys: dict_keys(['cond_stage_model.clip_l.transformer.text_model.embeddings.position_ids'])
Base model loaded: F:\SimpleAI\SimpleModels\checkpoints\SDXLFaetastic_v24.safetensors
VAE loaded: None
Request to load LoRAs [('sd_xl_offset_example-lora_1.0', 0.5), ('SDXLFaeTastic2400', 0.7), ('blur_control_xl_v1', 1.0), ('SDXL_black_and_color_Sa_May', 1.0)] for model [F:\SimpleAI\SimpleModels\checkpoints\SDXLFaetastic_v24.safetensors].
Lora file not found: F:\SimpleAI\SimpleModels\loras\sd_xl_offset_example-lora_1.0
Lora file not found: F:\SimpleAI\SimpleModels\loras\SDXLFaeTastic2400
Lora file not found: F:\SimpleAI\SimpleModels\loras\blur_control_xl_v1
Lora file not found: F:\SimpleAI\SimpleModels\loras\SDXL_black_and_color_Sa_May
Requested to load SDXLClipModel
Loading 1 new model
[Fooocus Model Management] Moving model(s) has taken 0.85 seconds
[Fooocus] Processing prompts ...
[Wildcards] Copmile text in prompt to arrays: a Tamil man walks away and climbs the mystic never ending stairs on a dark and stormy night. Sharp background, deep depth of field -> arrays:[], mult:0
[Fooocus] Preparing Fooocus text #1 ...
F:\SimpleAI\SimpleSDXL2_win_0916\python_embeded\lib\site-packages\transformers\models\gpt2\modeling_gpt2.py:650: UserWarning: 1Torch was not compiled with flash attention. (Triggered internally at ..\aten\src\ATen\native\transformers\cuda\sdp_utils.cpp:455.)
  attn_output = torch.nn.functional.scaled_dot_product_attention(
[Prompt Expansion] a Tamil man walks away and climbs the mystic never ending stairs on a dark and stormy night. Sharp background, deep depth of field, dramatic light, cinematic, extremely detailed, beautiful, stunning, intricate, elegant, creative, surreal, highly advanced, thought, fancy, glorious, epic, clear, amazing, breathtaking, peaceful, vibrant, unique, artistic, incredible
[Fooocus] Encoding positive #1 ...
[Fooocus Model Management] Moving model(s) has taken 0.14 seconds
[Fooocus] Encoding negative #1 ...
[Parameters] Denoising Strength = 1.0
[Parameters] Initial Latent shape: Image Space (1152, 896)
Preparation time: 5.97 seconds
Using karras scheduler.
[Fooocus] GPU memory: max_reserved=2.111GB, max_allocated=1.991GB, reserved=1.986GB, free=8.966GB, free_torch=0.250GB, free_total=9.216GB, gpu_total=12.000GB, torch_total=1.986GB
[Fooocus] Preparing Fooocus task 1/1 ...
[Sampler] refiner_swap_method = joint
[Sampler] sigma_min = 0.0291671771556139, sigma_max = 14.614643096923828
Requested to load SDXL
Loading 1 new model
[Fooocus Model Management] Moving model(s) has taken 1.83 seconds
100%|██████████████████████████████████████████████████████████████████████████████████| 30/30 [00:23<00:00,  1.25it/s]
Requested to load AutoencoderKL
Loading 1 new model
[Fooocus Model Management] Moving model(s) has taken 2.42 seconds
[Fooocus] Saving image 1/1 to system ...
[Cache] Calculating sha256 for F:\SimpleAI\SimpleModels\loras\sd_xl_offset_example-lora_1.0
Traceback (most recent call last):
  File "F:\SimpleAI\SimpleSDXL2_win_0916\SimpleSDXL\modules\async_worker.py", line 1641, in worker
    handler(task)
  File "F:\SimpleAI\SimpleSDXL2_win_0916\python_embeded\lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "F:\SimpleAI\SimpleSDXL2_win_0916\python_embeded\lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "F:\SimpleAI\SimpleSDXL2_win_0916\SimpleSDXL\modules\async_worker.py", line 1447, in handler
    imgs, img_paths, current_progress = process_task(all_steps, async_task, callback_function, controlnet_canny_path,
  File "F:\SimpleAI\SimpleSDXL2_win_0916\SimpleSDXL\modules\async_worker.py", line 412, in process_task
    img_paths = save_and_log(async_task, height, imgs, task, use_expansion, width, loras, persist_image)
  File "F:\SimpleAI\SimpleSDXL2_win_0916\SimpleSDXL\modules\async_worker.py", line 479, in save_and_log
    metadata_parser.set_data(task['log_positive_prompt'], task['positive'],
  File "F:\SimpleAI\SimpleSDXL2_win_0916\SimpleSDXL\modules\meta_parser.py", line 445, in set_data
    lora_hash = sha256_from_cache(lora_path)
  File "F:\SimpleAI\SimpleSDXL2_win_0916\SimpleSDXL\modules\hash_cache.py", line 31, in sha256_from_cache
    hash_value = sha256(filepath)
  File "F:\SimpleAI\SimpleSDXL2_win_0916\SimpleSDXL\modules\util.py", line 213, in sha256
    sha256_value = calculate_sha256(filename)
  File "F:\SimpleAI\SimpleSDXL2_win_0916\SimpleSDXL\modules\util.py", line 239, in calculate_sha256
    with open(filename, "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'F:\\SimpleAI\\SimpleModels\\loras\\sd_xl_offset_example-lora_1.0'
Total time: 35.16 seconds
[Gallery] Refresh_output_catalog: loaded 435 images_catalogs.
[Gallery] Parse_html_log: loaded 1 image_infos of 24-09-20.
[Gallery] Refresh_images_catalog: loaded 1 image_items of 24-09-20.
[Gallery] Parse_html_log: loaded 1 image_infos of 24-09-20.

Additional information

This problem only occurs when trying to regenerate an image from metadata that contains references to LoRAs.

The image will regenerate correctly if you manually select the LoRAs from the Models tab.

The image will regenerate correctly using the SimpleSDXL2 win2_820 version. No user intervention is required. This bug only affects the win2_960 version.

This is the image log file, and the attached image shows the generation when it works correctly.

{ "prompt": "a Tamil man walks away and climbs the mystic never ending stairs on a dark and stormy night. Sharp background, deep depth of field", "negative_prompt": "blurry background, bokeh", "prompt_expansion": "a Tamil man walks away and climbs the mystic never ending stairs on a dark and stormy night. Sharp background, deep depth of field, dramatic light, cinematic, extremely detailed, beautiful, stunning, intricate, elegant, creative, surreal, highly advanced, thought, fancy, glorious, epic, clear, amazing, breathtaking, peaceful, vibrant, unique, artistic, incredible", "styles": "['Fooocus V2', 'Fooocus Semi Realistic', 'Dark Fantasy']", "performance": "Speed", "steps": 30, "resolution": "(896, 1152)", "guidance_scale": 7, "sharpness": 8, "adm_guidance": "(1.5, 0.8, 0.3)", "base_model": "SDXLFaetastic_v24.safetensors", "refiner_model": "None", "refiner_switch": 0.6, "clip_skip": 2, "sampler": "dpmpp_2m_sde_gpu", "scheduler": "karras", "vae": "Default (model)", "seed": "7841085968682328112", "lora_combined_1": "sd_xl_offset_example-lora_1.0.safetensors : 0.5", "lora_combined_2": "SDXLFaeTastic2400.safetensors : 0.7", "lora_combined_3": "blur_control_xl_v1.safetensors : 1.0", "lora_combined_4": "SDXL_black_and_color_Sa_May.safetensors : 1.0", "backend_engine": "SDXL-Fooocus", "metadata_scheme": "fooocus", "version": "Fooocus v2.5.5 SimpleSDXL_v20240731.baa9f01" }

2024-09-20_13-43-43_9478

metercai commented 2 months ago

Like #81 , bug caused by fooocus schema

DavidDragonsage commented 2 months ago

So it I understand correctly, this issue is resolved in the latest dev version - similar to #81 ?

metercai commented 2 months ago

The official version code has been updated and will be upgraded upon restart without the need to replace the program package. Can you verify if this bug still exists?

DavidDragonsage commented 2 months ago

Well we have partial success. The LoRAs do load correctly from the metadata, so that bug is fixed. Edited to add: WRONG! The LoRAs are not actually used but the logs indicate that they are in use.

However, SimpleSDXL is now creating images that are quite different from the originals. I have attached the new image created this morning, made from the metadata of the image I created yesterday. This image should be identical to the first image in this thread.

The image logs look identical, apart from the difference in how the LoRAs are listed, and the version number of course.

This is the metadata from the original image: { "prompt": "a Tamil man walks away and climbs the mystic never ending stairs on a dark and stormy night. Sharp background, deep depth of field", "negative_prompt": "blurry background, bokeh", "prompt_expansion": "a Tamil man walks away and climbs the mystic never ending stairs on a dark and stormy night. Sharp background, deep depth of field, dramatic light, cinematic, extremely detailed, beautiful, stunning, intricate, elegant, creative, surreal, highly advanced, thought, fancy, glorious, epic, clear, amazing, breathtaking, peaceful, vibrant, unique, artistic, incredible", "styles": "['Fooocus V2', 'Fooocus Semi Realistic', 'Dark Fantasy']", "performance": "Speed", "steps": 30, "resolution": "(896, 1152)", "guidance_scale": 7, "sharpness": 8, "adm_guidance": "(1.5, 0.8, 0.3)", "base_model": "SDXLFaetastic_v24.safetensors", "refiner_model": "None", "refiner_switch": 0.6, "clip_skip": 2, "sampler": "dpmpp_2m_sde_gpu", "scheduler": "karras", "vae": "Default (model)", "seed": "7841085968682328112", "lora_combined_1": "sd_xl_offset_example-lora_1.0.safetensors : 0.5", "lora_combined_2": "SDXLFaeTastic2400.safetensors : 0.7", "lora_combined_3": "blur_control_xl_v1.safetensors : 1.0", "lora_combined_4": "SDXL_black_and_color_Sa_May.safetensors : 1.0", "backend_engine": "SDXL-Fooocus", "metadata_scheme": "fooocus", "version": "Fooocus v2.5.5 SimpleSDXL_v20240916.2952150" }

This is the metadata from today's image: { "prompt": "a Tamil man walks away and climbs the mystic never ending stairs on a dark and stormy night. Sharp background, deep depth of field", "negative_prompt": "blurry background, bokeh", "prompt_expansion": "a Tamil man walks away and climbs the mystic never ending stairs on a dark and stormy night. Sharp background, deep depth of field, dramatic light, cinematic, extremely detailed, beautiful, stunning, intricate, elegant, creative, surreal, highly advanced, thought, fancy, glorious, epic, clear, amazing, breathtaking, peaceful, vibrant, unique, artistic, incredible", "styles": "['Fooocus V2', 'Fooocus Semi Realistic', 'Dark Fantasy']", "performance": "Speed", "steps": 30, "resolution": "(896, 1152)", "guidance_scale": 7, "sharpness": 8, "adm_guidance": "(1.5, 0.8, 0.3)", "base_model": "SDXLFaetastic_v24.safetensors", "refiner_model": "None", "refiner_switch": 0.6, "clip_skip": 2, "sampler": "dpmpp_2m_sde_gpu", "scheduler": "karras", "vae": "Default (model)", "seed": "7841085968682328112", "lora_combined_1": "sd_xl_offset_example-lora_1.0 : 0.5", "lora_combined_2": "SDXLFaeTastic2400 : 0.7", "lora_combined_3": "blur_control_xl_v1 : 1.0", "lora_combined_4": "SDXL_black_and_color_Sa_May : 1.0", "backend_engine": "SDXL-Fooocus", "metadata_scheme": "fooocus", "version": "Fooocus v2.5.5 SimpleSDXL_v20240916.b1b51ab" }

2024-09-21_10-20-00_9478

DavidDragonsage commented 2 months ago

I see what is happening. Although the LoRAs are listed in the metadata, they are having no effect.

I deselected all the LoRAs and regenerated the image. The program produced an image that is identical to the one above.

DavidDragonsage commented 2 months ago

From further experimentation I confirm that all LoRAs are inactive in Fooocus mode. Selecting a LoRA does not change the image at all, although the image log shows that the LoRA is in use.

In Comfy mode, loading metadata for a Flux image created with a LoRA creates an error - see the console log below. But Flux LoRAs do work if manually selected.

Loaded preset: F:\SimpleAI\SimpleSDXL2_win_0916\SimpleSDXL\presets\Flux🚀.json [Comfyd] Comfyd freeing! [ToolBox] Reset_params_from_image: -->Flux.1 params from the image with embedded parameters. [Fooocus] GPU memory: max_reserved=3.344GB, max_allocated=1.982GB, reserved=2.102GB, free=8.831GB, free_torch=0.120GB, free_total=8.951GB, gpu_total=12.000GB, torch_total=2.102GB [TaskEngine] Task_class:Flux, Task_name:Flux, Task_method:flux_base [TaskEngine] Enable Comfyd backend. [Comfyd] Comfyd is active! [Parameters] Adaptive CFG = 7 [Parameters] CLIP Skip = 2 [Parameters] Sharpness = 2 [Parameters] ControlNet Softness = 0.25 [Parameters] ADM Scale = 1.5 : 0.8 : 0.3 [Parameters] Seed = 5350975487230560396 [Parameters] CFG = 3.5 [Fooocus] Loading control models ... [Parameters] Sampler = euler - simple [Parameters] Steps = 12 - 30 [Fooocus] Initializing ... [Fooocus] Processing prompts ... [Wildcards] Copmile text in prompt to arrays: Detailed, masterpiece, professional, bold colors, awe-inspiring, photography inspired by modern fantasy art, medium shot, HDR, futuristic realistic geisha in a cyberpunk theme, neon geisha sparkle face paint, elaborate attire, street lights illuminate her face -> arrays:[], mult:0 [Parameters] Denoising Strength = 1.0 [Parameters] Initial Latent shape: Image Space (1152, 896) Preparation time: 0.01 seconds Using simple scheduler. [Fooocus] GPU memory: max_reserved=2.102GB, max_allocated=1.981GB, reserved=0.023GB, free=10.909GB, free_torch=0.015GB, free_total=10.924GB, gpu_total=12.000GB, torch_total=0.023GB [Fooocus] Preparing Flux task 1/1 ... [ComfyClient] Ready ComfyTask to process: workflow=flux_base2_gguf prompt = Detailed, masterpiece, professional, bold colors, awe-inspiring, photography inspired by modern fantasy art, medium shot, HDR, futuristic realistic geisha in a cyberpunk theme, neon geisha sparkle face paint, elaborate attire, street lights illuminate her face negative_prompt = width = 896 height = 1152 base_model = flux-hyp8-Q5_K_M.gguf sampler = euler scheduler = simple cfg_scale = 3.5 steps = 12 denoise = 1.0 seed = 5350975487230560396 clip_model = t5xxl_fp16.safetensors lora_1 = DracoFelis lora_1_strength = 1.0 [Comfyd] got prompt [Comfyd] Failed to validate prompt for output 27: [Comfyd] LoraLoaderModelOnly 31: [Comfyd] - Value not in list: lora_name: 'DracoFelis' not in (list of length 51) [Comfyd] Output will be ignored [Comfyd] invalid prompt: {'type': 'prompt_outputs_failed_validation', 'message': 'Prompt outputs failed validation', 'details': '', 'extra_info': {}} Traceback (most recent call last): File "F:\SimpleAI\SimpleSDXL2_win_0916\SimpleSDXL\modules\async_worker.py", line 1639, in worker handler(task) File "F:\SimpleAI\SimpleSDXL2_win_0916\python_embeded\lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context return func(args, *kwargs) File "F:\SimpleAI\SimpleSDXL2_win_0916\python_embeded\lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context return func(args, **kwargs) File "F:\SimpleAI\SimpleSDXL2_win_0916\SimpleSDXL\modules\async_worker.py", line 1445, in handler imgs, img_paths, current_progress = process_task(all_steps, async_task, callback_function, controlnet_canny_path, File "F:\SimpleAI\SimpleSDXL2_win_0916\SimpleSDXL\modules\async_worker.py", line 364, in process_task imgs = comfypipeline.process_flow(comfy_task.name, comfy_task.params, comfy_task.images, callback=callback) File "F:\SimpleAI\SimpleSDXL2_win_0916\python_embeded\lib\site-packages\simpleai_base\comfyclient_pipeline.py", line 154, in process_flow images = get_images(ws, prompt_str, callback=callback) File "F:\SimpleAI\SimpleSDXL2_win_0916\python_embeded\lib\site-packages\simpleai_base\comfyclient_pipeline.py", line 51, in get_images prompt_id = queue_prompt(prompt)['prompt_id'] KeyError: 'prompt_id' Total time: 0.91 seconds

DavidDragonsage commented 2 months ago

With today's auto-update from b1b51ab to fe3afb6 the LoRAs are again not loading from the metadata in Fooocus mode. However the Fooocus LoRAs do work if they are selected manually.

metercai commented 2 months ago

Your problem cannot be reproduced. Please simplify and follow the following process with attached images and logs: 1, Generate an image using default presets and an obvious lora, and select simple Metadata schema 2, Extract parameters from the previously generated image and generate another image 3, Cancel Lora and generate another image using the current parameters

DavidDragonsage commented 2 months ago

I understand what is happening now. I had assumed that the Simple designation was just a new name for Fooocus metadata. But I see now that Simple and Fooocus metadata are incompatible.

If I follow your directions - staying exclusively with Simple metadata - I get an exact replica.

But there is a more serious problem. I have a library of over 6000 Fooocus images on my hard drive. Should I choose to work on one of them in the SimpleSDXL win_906 version it is now impossible. And it is not unusual for me to rework old images as I gain more experience with AI generation.

I do not understand why the Fooocus metadata option was removed because this creates a significant incompatibility with mainline Fooocus. I had thought that Fooocus compatibility was one of the driving forces behind this project.

This is another reason I must keep the win_0820 version available on my SSD (the other reason being the better quality in Flux1 Dev). But that is not a good long term solution. And many people simply do not have the space to keep two or three variants of Fooocus on their drives (I did not until last week).

I have recently been testing Fooocus versus SimpleSDXL2. I was delighted to find that in both quality and speed they are a match (I am about to publish the results at the Pure Fooocus Facebook group). As far as quality goes, in some cases Fooocus will generate a better image with the same parameters and seed, and in other cases SimpleSDXL2 will generate a better image. And in many cases each image in the comparison was better in one respect but not as good in another.

My goal has been to actually eliminate both mainline Fooocus and SimpleSDXL win0820 from my PC. It appears that will not be practical.

metercai commented 2 months ago

The simple metadata schema is compatible with fooocus and can be read, but it will be converted to a new one when generated. This is because Simple needs to be compatible with other models, such as Flux and Kolors.

metercai commented 2 months ago

If there are any compatibility issues with reading of fooocus schema, you can submit bugs to fix them. When outputting, it must be a simple schema.

The a1111 schema can be output, but it is irreversible, meaning that it may not be restored after reading due to insufficient parameter information.

DavidDragonsage commented 2 months ago

Thank you, I am relieved that you intend to ensure that Fooocus metadata will load successfully into win2_960.

This thread has become somewhat confusing so I will start a new bug report focused on that one issue, of problems with loading Fooocus metadata.