Acly / krita-ai-diffusion

Streamlined interface for generating images with AI in Krita. Inpaint and outpaint with optional text prompt, no tweaking required.
https://www.interstice.cloud
GNU General Public License v3.0
6.47k stars 312 forks source link

Report which files cause issues when exceptions thrown #890

Open Pugsworth opened 3 months ago

Pugsworth commented 3 months ago

Apologies of this has been asked before, I did a couple of searches within the issues and couldn't find anything.

I just solved an error about "error while deserializing header: MetadataIncompleteBuffer". I read all three closed issue reports on the matter and the recommendation was to re-download the models as they might have been corrupted.

Nowhere could I find any output describing which files were the problem. I finally had to edit safetensors/torch.py to catch the error and report what filename it was trying to open. For anybody that has a similar issue, here's the changes I made: starting at line 311, change everything until return result with:

try:
    with safe_open(filename, framework="pt", device=device) as f:
        for k in f.keys():
            result[k] = f.get_tensor(k)
except Exception as ex:
    print(f"Something went wrong when attempting to open file '{filename}'")
    raise ex

My suggestion is this:

  1. When an error is thrown while generating, have some way to report what files were being used when it happened.
  2. In the download_models.py script, add hash verification to the model files to also verify the integrity as well as if they exists. This way, you could just run the downloader again and it should automatically find corrupted files.
Acly commented 2 months ago

First suggestion would be nice but has to be implemented in ComfyUI.

Hash verification is also sensible thing to do, also for the plugin internal downloader.