Coder Social home page Coder Social logo

distyapps / safe-and-stable-ckpt2safetensors-conversion-tool-gui Goto Github PK

View Code? Open in Web Editor NEW
418.0 418.0 42.0 523 KB

Convert your Stable Diffusion checkpoints quickly and easily.

License: MIT License

Python 100.00%
artificial-intelligence automatic1111 ckpt converter gui gui-application malware pickle python safetensors stable-diffusion

safe-and-stable-ckpt2safetensors-conversion-tool-gui's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

safe-and-stable-ckpt2safetensors-conversion-tool-gui's Issues

Error at first run on Debian Sid

Hi, i followed all step and got this. Thanks

$ python3.8 run_app_gui.py                                                                         
Error: Invalid folder path.
Traceback (most recent call last):
  File "run_app_gui.py", line 310, in <module>
    main() 
  File "run_app_gui.py", line 93, in main
    window = sg.Window(APP_TITLE,layout,finalize=True, resizable=True,enable_close_attempted_event=False,background_color=color.GRAY_9900)
  File "/media/sherlock/data/krita-ai/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.8/site-packages/PySimpleGUI/PySimpleGUI.py", line 9614, in __init__
    self.Finalize()
  File "/media/sherlock/data/krita-ai/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.8/site-packages/PySimpleGUI/PySimpleGUI.py", line 10300, in finalize
    self.Read(timeout=1)
  File "/media/sherlock/data/krita-ai/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.8/site-packages/PySimpleGUI/PySimpleGUI.py", line 10075, in read
    results = self._read(timeout=timeout, timeout_key=timeout_key)
  File "/media/sherlock/data/krita-ai/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.8/site-packages/PySimpleGUI/PySimpleGUI.py", line 10146, in _read
    self._Show()
  File "/media/sherlock/data/krita-ai/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.8/site-packages/PySimpleGUI/PySimpleGUI.py", line 9886, in _Show
    StartupTK(self)
  File "/media/sherlock/data/krita-ai/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.8/site-packages/PySimpleGUI/PySimpleGUI.py", line 16866, in StartupTK
    _convert_window_to_tk(window)
  File "/media/sherlock/data/krita-ai/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.8/site-packages/PySimpleGUI/PySimpleGUI.py", line 16753, in _convert_window_to_tk
    PackFormIntoFrame(window, master, window)
  File "/media/sherlock/data/krita-ai/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.8/site-packages/PySimpleGUI/PySimpleGUI.py", line 15991, in PackFormIntoFrame
    PackFormIntoFrame(element, labeled_frame, toplevel_form)
  File "/media/sherlock/data/krita-ai/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.8/site-packages/PySimpleGUI/PySimpleGUI.py", line 15991, in PackFormIntoFrame
    PackFormIntoFrame(element, labeled_frame, toplevel_form)
  File "/media/sherlock/data/krita-ai/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.8/site-packages/PySimpleGUI/PySimpleGUI.py", line 15520, in PackFormIntoFrame
    max_line_len = max([len(str(l)) for l in element.Values]) if len(element.Values) else 0
TypeError: object of type 'NoneType' has no len()

Error: No module named 'pytorch_lightning'

Current Behavior:

Converting Anything-V3.0-pruned.ckpt, or CandyMissionBerryF222-hassan.ckpt, to safetensors fails with the below error:

Converting H:/ai/models/Stable-diffusion\Anything-V3.0-pruned.ckpt to safetensors.
Saving H:/ai/models/Stable-diffusion\Anything-V3.0-pruned.safetensors.
FILE NOT SUPPORTED
Error: No module named 'pytorch_lightning'

Converting H:/ai/models/Stable-diffusion\CandyMissionBerryF222-hassan.ckpt to safetensors.
Saving H:/ai/models/Stable-diffusion\CandyMissionBerryF222-hassan.safetensors.
FILE NOT SUPPORTED
Error: No module named 'pytorch_lightning'

Expected Behavior:

Ckpt should be converted to safetensors.

Steps To Reproduce:

  1. Open run_app_gui.exe.
  2. Point file dialog at either of the ckpts.
  3. Click Convert.
  4. Error upon conversion start.

Environment:

  • OS: Windows 11 21H2, Build 22000.1219

Anything else:

AUTOMATIC1111/stable-diffusion-webui#4930 (comment)

Use torch.load(..., weight_only=True) (torch 1.13.0 only). But this will fail on the original checkpoint since it uses some real pickled class (pytorch_lightning). There is no way to load those file securely with PyTorch in that format afaik.

missing tkinter

got an error after fresh install

"ModuleNotFoundError: No module named 'tkinter'"

fixed it with sudo apt-get install python3-tk, maybe its worth to add to notes or someting.

Error and freez in panda lib

Exception in thread Thread-1 (process_directory):
Traceback (most recent call last):
File "/home/wilk/.local/lib/python3.10/site-packages/pandas/core/arrays/datetimes.py", line 2192, in objects_to_datetime64ns
values, tz_parsed = conversion.datetime_to_datetime64(data.ravel("K"))
File "pandas/_libs/tslibs/conversion.pyx", line 359, in pandas._libs.tslibs.conversion.datetime_to_datetime64
TypeError: Unrecognized value type: <class 'str'>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/usr/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "/media/wilk/PV/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/run_app_gui.py", line 153, in process_directory
cpbar.progress_bar_custom(idx-1,len(input_directory_path_list),start_time,window,PBAR_KEY,"file")
File "/media/wilk/PV/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/util/progress_bar_custom.py", line 110, in progress_bar_custom
time_left = format_sec((range/it_per_sec)-(time_diff))
File "/media/wilk/PV/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/util/progress_bar_custom.py", line 103, in format_sec
formated_sec = pd.to_datetime(formated_sec_step_1).strftime('%H:%M:%S')
File "/home/wilk/.local/lib/python3.10/site-packages/pandas/core/tools/datetimes.py", line 914, in to_datetime
result = convert_listlike(np.array([arg]), format)[0]
File "/home/wilk/.local/lib/python3.10/site-packages/pandas/core/tools/datetimes.py", line 401, in _convert_listlike_datetimes
result, tz_parsed = objects_to_datetime64ns(
File "/home/wilk/.local/lib/python3.10/site-packages/pandas/core/arrays/datetimes.py", line 2198, in objects_to_datetime64ns
raise err
File "/home/wilk/.local/lib/python3.10/site-packages/pandas/core/arrays/datetimes.py", line 2180, in objects_to_datetime64ns
result, tz_parsed = tslib.array_to_datetime(
File "pandas/_libs/tslib.pyx", line 379, in pandas._libs.tslib.array_to_datetime
File "pandas/_libs/tslib.pyx", line 611, in pandas._libs.tslib.array_to_datetime
File "pandas/_libs/tslib.pyx", line 749, in pandas._libs.tslib._array_to_datetime_object
File "pandas/_libs/tslib.pyx", line 740, in pandas._libs.tslib._array_to_datetime_object
File "pandas/_libs/tslibs/parsing.pyx", line 257, in pandas._libs.tslibs.parsing.parse_datetime_string
File "/usr/lib/python3/dist-packages/dateutil/parser/_parser.py", line 1374, in parse
return DEFAULTPARSER.parse(timestr, **kwargs)
File "/usr/lib/python3/dist-packages/dateutil/parser/_parser.py", line 649, in parse
raise ParserError("Unknown string format: %s", timestr)
dateutil.parser._parser.ParserError: Unknown string format: -1 day, 23:59:54.730000

image

Error: Invalid Folder Path

set up the venv and was able to install requirements but get a Error : Invalid folder path when i run python run_app_gui.py. Is there folders I have to create/files I need to move into the env in order for it to work?

Error: Invalid folder path. Traceback (most recent call last): File "/home/fuckyou/workspace/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/run_app_gui.py", line 309, in <module> main() File "/home/fuckyou/workspace/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/run_app_gui.py", line 93, in main window = sg.Window(APP_TITLE,layout,finalize=True, resizable=True,enable_close_attempted_event=False,background_color=color.GRAY_9900) File "/home/fuckyou/workspace/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.9/site-packages/PySimpleGUI/PySimpleGUI.py", line 9614, in __init__ self.Finalize() File "/home/fuckyou/workspace/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.9/site-packages/PySimpleGUI/PySimpleGUI.py", line 10300, in finalize self.Read(timeout=1) File "/home/fuckyou/workspace/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.9/site-packages/PySimpleGUI/PySimpleGUI.py", line 10075, in read results = self._read(timeout=timeout, timeout_key=timeout_key) File "/home/fuckyou/workspace/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.9/site-packages/PySimpleGUI/PySimpleGUI.py", line 10146, in _read self._Show() File "/home/fuckyou/workspace/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.9/site-packages/PySimpleGUI/PySimpleGUI.py", line 9886, in _Show StartupTK(self) File "/home/fuckyou/workspace/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.9/site-packages/PySimpleGUI/PySimpleGUI.py", line 16866, in StartupTK _convert_window_to_tk(window) File "/home/fuckyou/workspace/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.9/site-packages/PySimpleGUI/PySimpleGUI.py", line 16753, in _convert_window_to_tk PackFormIntoFrame(window, master, window) File "/home/fuckyou/workspace/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.9/site-packages/PySimpleGUI/PySimpleGUI.py", line 15991, in PackFormIntoFrame PackFormIntoFrame(element, labeled_frame, toplevel_form) File "/home/fuckyou/workspace/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.9/site-packages/PySimpleGUI/PySimpleGUI.py", line 15991, in PackFormIntoFrame PackFormIntoFrame(element, labeled_frame, toplevel_form) File "/home/fuckyou/workspace/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/venv/lib/python3.9/site-packages/PySimpleGUI/PySimpleGUI.py", line 15520, in PackFormIntoFrame max_line_len = max([len(str(l)) for l in element.Values]) if len(element.Values) else 0 TypeError: object of type 'NoneType' has no len()

Failed to run on macos

environment: macos m1
python 3.9

python3 run_app_gui.py
/Users/songkeys/Library/Python/3.9/lib/python/site-packages/PySimpleGUI/PySimpleGUI.py:24845: UserWarning: You are running a VERY old version of tkinter 8.5.9. You cannot use PNG formatted images for example.  Please upgrade to 8.6.x
  warnings.warn('You are running a VERY old version of tkinter {}. You cannot use PNG formatted images for example.  Please upgrade to 8.6.x'.format(tclversion_detailed), UserWarning)
Mac OS Version is 13.2 and patch enabled so applying the patch
Applyting Mac OS 12.3+ Alpha Channel fix.  Your default Alpha Channel is now 0.99
DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning.
Traceback (most recent call last):
  File "/Users/songkeys/Downloads/convertor/run_app_gui.py", line 309, in <module>
    main()
  File "/Users/songkeys/Downloads/convertor/run_app_gui.py", line 93, in main
    window = sg.Window(APP_TITLE,layout,finalize=True, resizable=True,enable_close_attempted_event=False,background_color=color.GRAY_9900)
  File "/Users/songkeys/Library/Python/3.9/lib/python/site-packages/PySimpleGUI/PySimpleGUI.py", line 9614, in __init__
    self.Finalize()
  File "/Users/songkeys/Library/Python/3.9/lib/python/site-packages/PySimpleGUI/PySimpleGUI.py", line 10300, in finalize
    self.Read(timeout=1)
  File "/Users/songkeys/Library/Python/3.9/lib/python/site-packages/PySimpleGUI/PySimpleGUI.py", line 10075, in read
    results = self._read(timeout=timeout, timeout_key=timeout_key)
  File "/Users/songkeys/Library/Python/3.9/lib/python/site-packages/PySimpleGUI/PySimpleGUI.py", line 10146, in _read
    self._Show()
  File "/Users/songkeys/Library/Python/3.9/lib/python/site-packages/PySimpleGUI/PySimpleGUI.py", line 9886, in _Show
    StartupTK(self)
  File "/Users/songkeys/Library/Python/3.9/lib/python/site-packages/PySimpleGUI/PySimpleGUI.py", line 16866, in StartupTK
    _convert_window_to_tk(window)
  File "/Users/songkeys/Library/Python/3.9/lib/python/site-packages/PySimpleGUI/PySimpleGUI.py", line 16753, in _convert_window_to_tk
    PackFormIntoFrame(window, master, window)
  File "/Users/songkeys/Library/Python/3.9/lib/python/site-packages/PySimpleGUI/PySimpleGUI.py", line 15991, in PackFormIntoFrame
    PackFormIntoFrame(element, labeled_frame, toplevel_form)
  File "/Users/songkeys/Library/Python/3.9/lib/python/site-packages/PySimpleGUI/PySimpleGUI.py", line 15991, in PackFormIntoFrame
    PackFormIntoFrame(element, labeled_frame, toplevel_form)
  File "/Users/songkeys/Library/Python/3.9/lib/python/site-packages/PySimpleGUI/PySimpleGUI.py", line 15216, in PackFormIntoFrame
    photo = tk.PhotoImage(data=element.ImageData)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 4064, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 4009, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize image data

I tried python3.9 run_app_gui.py, it's another error:

python3.9 run_app_gui.py
Traceback (most recent call last):
  File "/Users/songkeys/Downloads/convertor/run_app_gui.py", line 1, in <module>
    import PySimpleGUI as sg
  File "/Users/songkeys/Library/Python/3.9/lib/python/site-packages/PySimpleGUI/__init__.py", line 2, in <module>
    from .PySimpleGUI import *
  File "/Users/songkeys/Library/Python/3.9/lib/python/site-packages/PySimpleGUI/PySimpleGUI.py", line 136, in <module>
    import tkinter as tk
  File "/opt/homebrew/Cellar/[email protected]/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 37, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'

I have run both pip install -r requirements.txt and pip3 install -r requirements.txt.

same Model hash after converting

hi,

Today i just noticed than after converting my 2.1 ckpt, it ended up with the same Model hash as the 2.0 model which is less than convenient when reloading image.

image
image

how to run in ubuntu

ubuntu 20, python3.8
pip install -r requirements worked fine. when i run python3 run_app_gui.py it gives

Traceback (most recent call last): File "run_app_gui.py", line 309, in <module> main() File "run_app_gui.py", line 66, in main file_explorer.layout(), File "/home/user/Data/github/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/util/file_explorer_component.py", line 85, in layout sg.Listbox(key=FILE_EXPLORER_LSTBOX_KEY,values=get_system_files_list(),text_color=color.TERMINAL_BLUE,background_color=color.GRAY_1111, File "/home/user/Data/github/Safe-and-Stable-Ckpt2Safetensors-Conversion-Tool-GUI/util/file_explorer_component.py", line 79, in get_system_files_list return get_system_files(os.path.join(os.getenv("SystemDrive"), "\\")) File "/usr/lib/python3.8/posixpath.py", line 76, in join a = os.fspath(a) TypeError: expected str, bytes or os.PathLike object, not NoneType

How do I run this on Mac

Discussed in #14

Originally posted by Emmadgithub January 7, 2023
Hello, I'm slightly new to coding and I downloaded this to convert some of the Diffusion model files in safe tensor to CKPT to run them in diffusion BEE, Please do let me know how to run this.
thanks
Screenshot 2023-01-07 at 6 10 54 PM

How do you even use this?

am i just stupid? i don't even see anything in this program to actually run the program, an explanation on how to run it would be great.

Error: [Errno 13] Permission denied: 'C:\\Safetensor2-cnvrtd.ckpt'

I try to convert safetensor back to ckpt for using with some old webui with faster iteration feature. Unfortunately it didnt support safetensor so I have to convert it back to ckpt. But when I use your GUI why it shows Error: [Errno 13] Permission denied: 'C:\Safetensor2-cnvrtd.ckpt'?

Thank you

Add non-gui support

It would nice if this could be run as a cmdline, or even better make it a separate python lib w/ cmdline support.

Error when running run_app_gui.exe

After extracting the zip file, I tried running the run_app_gui.exe file and received this error:

image

Traceback (most recent call last):
File "run_app_gui.py", line 3, in
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "torch_init_.py", line 192, in
from torch._C import * # noqa: F403
ImportError: DLL load failed: The specified module could not be found.

long file paths causing a crash

i experienced crashes with long file names, i dont know if there is a limit on the total path length but after debugging it seems that

selected_path = file_explorer.SelectedFileSystem.path

is not the correct full path.

The tool will execute any code in tampered checkpoint files

Line

weights = torch.load(checkpoint_path, map_location=torch.device('cpu'))
loads the .ckpt file without any checks or safety, and will execute any code in a tampered checkpoint file. This implementation is fine if you're running the tool on checkpoints that you know are safe, but the tool needs a VERY BIG WARNING sign to not use it on any checkpoints from unknown sources. It completely negates the benefit of the safetensors format when used in that way.

Edit: Just noticed it is mentioned in the readme, but easily missed by anyone just using the tool. Do not call your tool "safe" if it isn't though.

Error: Key `state_dict` is invalid, expected torch.Tensor but received <class 'dict'>

Current Behavior:

Certain ckpt fail to convert with the following error message:
Error: Key state_dict is invalid, expected torch.Tensor but received <class 'dict'>

Expected Behavior:

Ckpt should be converted to safetensors.

Steps To Reproduce:

  1. Open run_app_gui.exe.
  2. Point file dialog at either of the ckpts.
  3. Click Convert.
  4. Error upon conversion start.

Environment:

  • OS: Windows 11 21H2, Build 22000.1219

Anything else:

https://www.reddit.com/r/StableDiffusion/comments/z8mnak/comment/iylgpvq/?utm_source=share&utm_medium=web2x&context=3

NAI can be converted by adding weights.pop("state_dict") to the conversion script in the GitHub pull request.
Edit: I would also recommend the script from @Tumppi066 which lists and converts models from sub-directories as well as working directory. You can get a NAI compatible version I patched here.

import torch
from safetensors.torch import save_file

weights = torch.load("nai.ckpt")["state_dict"]
weights.pop("state_dict")
save_file(weights, "nai.safetensors")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.