Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Checkpoint merger error #10460

Closed
1 task done
gee666 opened this issue May 17, 2023 · 14 comments · Fixed by sphuff/stable-diffusion-webui#8
Closed
1 task done

[Bug]: Checkpoint merger error #10460

gee666 opened this issue May 17, 2023 · 14 comments · Fixed by sphuff/stable-diffusion-webui#8
Labels
bug-report Report of a bug, yet to be confirmed

Comments

@gee666
Copy link

gee666 commented May 17, 2023

Is there an existing issue for this?

  • I have searched the existing issues and checked the recent builds/commits

What happened?

Error when trying to merge checkpoint

Loading C:\Automatic1111\models\Stable-diffusion\realisticVisionV20_v20_full.safetensors...
Loading C:\Automatic1111\models\Stable-diffusion\geetesha\oira666-02-v1.5_7000.safetensors...
Merging...
100%|█████████████████████████████████████████████████████████████████████████████| 1131/1131 [00:02<00:00, 449.38it/s]
Saving to C:\Automatic1111\models\Stable-diffusion\oira666_7000_realisticview.safetensors...
Error loading/saving model file:
Traceback (most recent call last):
  File "C:\Automatic1111\modules\ui.py", line 1722, in modelmerger
    results = modules.extras.run_modelmerger(*args)
  File "C:\Automatic1111\modules\extras.py", line 285, in run_modelmerger
    safetensors.torch.save_file(theta_0, output_modelname, metadata=metadata)
  File "C:\Automatic1111\venv\lib\site-packages\safetensors\torch.py", line 232, in save_file
    serialize_file(_flatten(tensors), filename, metadata=metadata)
TypeError: argument 'metadata': 'dict' object cannot be converted to 'PyString'

Steps to reproduce the problem

  1. Go to Checkpoint merger tab
  2. Set up two models (I tried a lot of different combinations with the same result)
  3. Set up params: m 0.15, Weighted sum, safetensors, A, B or C, Bake in vae: none;
  4. Press Merge
  5. Wait for a few seconds
  6. Receive the error

What should have happened?

Should have merged with no errors

Commit where the problem happens

89f9faa

What platforms do you use to access the UI ?

Windows

What browsers do you use to access the UI ?

Google Chrome

Command Line Arguments

--xformers --api

List of extensions

Auto-Photoshop-StableDiffusion-Plugin
deforum-for-automatic1111-webui
sd-webui-controlnet
sd_dreambooth_extension
LDSR
Lora
ScuNET
SwinIR
prompt-bracket-checker

Console logs

Loading C:\Automatic1111\models\Stable-diffusion\realisticVisionV20_v20_full.safetensors...
Loading C:\Automatic1111\models\Stable-diffusion\geetesha\oira666-02-v1.5_7000.safetensors...
Merging...
100%|█████████████████████████████████████████████████████████████████████████████| 1131/1131 [00:02<00:00, 449.38it/s]
Saving to C:\Automatic1111\models\Stable-diffusion\oira666_7000_realisticview.safetensors...
Error loading/saving model file:
Traceback (most recent call last):
  File "C:\Automatic1111\modules\ui.py", line 1722, in modelmerger
    results = modules.extras.run_modelmerger(*args)
  File "C:\Automatic1111\modules\extras.py", line 285, in run_modelmerger
    safetensors.torch.save_file(theta_0, output_modelname, metadata=metadata)
  File "C:\Automatic1111\venv\lib\site-packages\safetensors\torch.py", line 232, in save_file
    serialize_file(_flatten(tensors), filename, metadata=metadata)
TypeError: argument 'metadata': 'dict' object cannot be converted to 'PyString'

Additional information

No response

@gee666 gee666 added the bug-report Report of a bug, yet to be confirmed label May 17, 2023
dongweiming added a commit to dongweiming/stable-diffusion-webui that referenced this issue May 17, 2023
dongweiming added a commit to dongweiming/stable-diffusion-webui that referenced this issue May 17, 2023
Antonytm added a commit to Antonytm/stable-diffusion-webui-automatic1111 that referenced this issue Jun 4, 2023
* Autofix Ruff W (not W605) (mostly whitespace)

* Make live previews use JPEG only when the image is lorge enough

* Bump versions to avoid downgrading them

* fix --data-dir for COMMANDLINE_ARGS

move reading of COMMANDLINE_ARGS into paths_internal.py so --data-dir can be properly read

* Set PyTorch version to 2.0.1 for macOS

* launch.py: make git_tag() and commit_hash() work even when WEBUI_LAUNCH_LIVE_OUTPUT

* Get rid of check_run + run_python

* Redirect Gradio phone home request

This request is sent regardless of Gradio analytics being
enabled or not via the env var.
Idea from text-generation-webui.

* Define default fonts for Gradio theme

Allows web UI to (almost) be ran fully offline.
The web UI will hang on load if offline when
these fonts are not manually defined, as it will attempt (and fail)
to pull from Google Fonts.

* update changelog for release

* fix broken prompts from file

* update changelog for release

* Wait for DOMContentLoaded until checking whether localization should be disabled

Refs AUTOMATIC1111#9955 (comment)

* Requested changes

* minor fix

* remove command line option

* Allow bf16 in safe unpickler

* heavily simplify

* move to stable-diffusion tab

* fix for img2img

* Move localization to its own script block and load it first

* Make dump translations work again

* add an option to always refer to lora by filenames
never refer to lora by an alias if multiple loras have same alias or the alias is called none

* fix upscalers disappearing after the user reloads UI

* Merge pull request AUTOMATIC1111#10339 from catboxanon/bf16

Allow bf16 in safe unpickler

* Merge pull request AUTOMATIC1111#10324 from catboxanon/offline

Allow web UI to be ran fully offline

* update readme

* Merge pull request AUTOMATIC1111#10335 from akx/l10n-dis-take-2

Localization fixes

* update readme

* Add/modify CFG callbacks

Required by self-attn guidance extension
https://github.com/ashen-sensored/sd_webui_SAG

* Update script_callbacks.py

* remove output_altered flag from AfterCFGCallbackParams

* updates for AUTOMATIC1111#9256

* Add Tiny AE live preview

* Add live preview mode check

* set up a system to provide extra info for settings elements in python rather than js
add a bit of spacing/styling to settings elements
add link info for token merging

* allow jpeg for extra network preview

* add a bunch of descriptions and reword a lot of settings (sorry, localizers)

* remove auto live previews format option, fix slow PNG generation

* fix model loading twice in some situations

* add a possible fix for 'LatentDiffusion' object has no attribute 'lora_layer_mapping'

* update readme for release

* Add GPU device

Add GPU option to troubleshoot.

* Downgrade Gradio

* Modify pytorch command

* Update bug_report.yml

* fix xyz checkpoint

* launch.py: Don't involve shell for running Python or Git for output

Fixes Linux regression in 451d255

* Revert Gradio version

* Change to extra-index-url

* Minor changes

* Fix extra networks save preview image geninfo

* Add Python version

Many users still use unverified versions of Python and file version-specific issues, often without mentioning version information, making troubleshooting difficult.

* xyz token merging

* Show "Loading..." for extra networks when displaying for the first time

* load extensions' git metadata in parallel to loading the main program to save a ton of time during startup

* update extensions table: show branch, show date in separate column, and show version from tags if available

* add visual progress for extension installation from URL

* suppress ENSD infotext for samplers that don't use it

* add second_order field to sampler config

* restore nqsp in footer that was lost during linting

* add info link for Negative Guidance minimum sigma

* Minor change

* Use ngrok-py library

* Remove max width for model dropdown
Removing the max width for the model dropdown allows the user to see the full name of a model especially when it is long.
Model names are getting more complex and longer and the current width almost always cuts off model names.
If a user leverages folders than it pretty much always cuts off the name...

* Fix remove `textual inversion` prompt

* not clear checkpoints cache when config changes

* add credits

* return live preview defaults to how they were
only download TAESD model when it's needed
return calculations in single_sample_to_image to just if/elif/elif blocks
keep taesd model in its own directory

* Replace state.need_restart with state.server_command + replace poll loop with signal

* Add option for /_stop route (for graceful shutdown)

* Copy s_min_uncond to Processed

Should fix AUTOMATIC1111#10416

* Bump pytorch for AMD Users

So apparently it works now? Before you would get "Pytorch cant use the GPU" but not anymore.

* Fixing webui.sh

If only i proofread what i wrote

* TAESD fix

* simplify single_sample_to_image

* Add basic ESLint configuration for formatting

This doesn't enable any of ESLint's actual possible-issue linting,
but just style normalization based on the Prettier configuration (but without line length limits).

* Add ESLint to CI

* Run `eslint --fix` (and normalize tabs to spaces)

* fix inability to run with --freeze-settings

* Fixed: AUTOMATIC1111#10460

* use a local variable instead of dictionary entry for sd_merge_models in merge model metadata code

* when adding tooltips, do not scan whole document and instead only scan added elements

* Fix typo in syntax

* move some settings to the new Optimization page
add slider for token merging for img2img
rework StableDiffusionProcessing to have the token_merging_ratio field
fix a bug with applying png optimizations for live previews when they shouldn't be applied

* isn't there something you forgot, AUTOMATIC1111#10483?

* use a single function for saving images with metadata both in extra networks and main mode for AUTOMATIC1111#10395

* add options to show/hide hidden files and dirs, and to not list models/files in hidden directories

* add /sdapi/v1/script-info api

* alternative solution to fix styles load when edited by human AUTOMATIC1111#9765 as suggested by akx

* simplify name pattern setting tooltips

* add option to reorder tabs
fix Reload UI not working

* remove some code duplication from AUTOMATIC1111#9348

* option to specify editor height for img2img

* rework AUTOMATIC1111#8863 to work with all img2img tabs

* Error Improvement for install torch

* extend eslint config

* eslint related file edits

* eslint the merged code

* keep old option for ngrok

* python linter fixes

* add --gradio-allowed-path commandline option

* Modify xformers instead of pytorch

* if sd_model is None, do not always try to load it

* add messages about Loras that failed to load to UI

* .change -> .release for hires input

Improves overall UI responsiveness.

* rework hires prompts/sampler code to among other things support different extra networks in first/second pass
rework quoting for infotext items that have commas in them to use json (should be backwards compatible except for cases where it didn't work previously)
add some locals from processing function into the Processing class as fields

* bump gradio

* Reorder variable assignment

* Revert "Merge pull request AUTOMATIC1111#10440 from grimatoma/increaseModelPickerWidth"

This reverts commit 4b07f2f, reversing
changes made to 4071fa4.

* Fix blinking text of hr and scale res

goodbye

* make it possible for scripts to add cross attention optimizations
add UI selection for cross attention optimization

* rework AUTOMATIC1111#10519

* Use name instead of hash in xyz_grid

X/Y/Z grid was still using the old hash, prone to collisions. This changes it to use the name instead.

Should fix AUTOMATIC1111#10521.

* set Navigate image viewer with gamepad option to false by default, by request

* update CHANGELOG

* fix linter issues

* Added the refresh-loras post request

* rewrite uiElementIsVisible

rewrite visibility checking to be more generic/cleaner as well as add functionality to check if the element is scrolled on screen for more intuitive paste-target selection

* Spel chek changelog some

* make links to http://<...>.git git extensions work in the extension tab

* change upscalers to download models into user-specified directory (from commandline args) rather than the default models/<...>

* Apply suggestions from code review

Co-authored-by: Aarni Koskela <akx@iki.fi>

* split visibility method and sort instead

split out the visibility method for pasting and use a sort inside the paste handler to prioritize on-screen fields rather than targeting ONLY on screen fields

* linter fixes

* make it actually work after suggestions

* Add .git-blame-ignore-revs

* Fix ruff lint

* eslintrc: Sort eslint rules

* eslintrc: Use a file-local `global` comment for module

* eslintrc: mark most globals read-only

* eslintrc: enable no-redeclare but with builtinGlobals: false

* Replace args_to_array (and facsimiles) with Array.from

* get_tab_index(): use a for loop with early-exit for performance

* Fix typo "intialize"

* Deduplicate default extra network registration

* Simplify CORS middleware configuration

* Make load_scripts create new runners (removes reload_scripts)

* Refactor validate_tls_options out, fix typo (keyfile was there twice)

* Refactor configure_sigint_handler out

* Refactor configure opts_onchange out

* Note pending PR for app_kwargs

* Refactor gradio auth

* Deduplicate webui.py initial-load/reload code

* Overhaul tests to use py.test

* simplify PR page

* change width/heights slider steps to 64 from 8

* allow hiding buttons in ui-config.json

* calculate hashes for Lora
add lora hashes to infotext
when pasting infotext, use infotext's lora hashes to find local loras for <lora:xxx:1> entries whose hashes match loras the user has

* Use Optional[] to preserve Python 3.9 compatability

* preserve declarations

* extensions clone depth 1

* Update keyboard shortcut instructions for MacOS users in text selection guidance

* Support edit attn shortcut in hires fix prompts

* hiresfix prompt: add classes, update css sel

* Add a couple `from __future__ import annotations`es for Py3.9 compat

* add DPM-Solver++(2M) SDE from new k-diffusion

* Discard penultimate sigma for dpmpp_2m_sde

* --filter=blob:none

Co-Authored-By: Aarni Koskela <akx@iki.fi>
Co-Authored-By: catboxanon <122327233+catboxanon@users.noreply.github.com>

* revert git describe --always --tags for extensions because it seems to be causing issues

* reworking launch.py: rename

* reworking launch.py: add references to renamed file

* Revert "change width/heights slider steps to 64 from 8"

This reverts commit 9a86932.

* update readme

* fix bad styling for thumbs view in extra networks AUTOMATIC1111#10639

* possible fix for empty list of optimizations AUTOMATIC1111#10605

* update the changelog to mention 1.3.0 version

* fix serving images that have already been saved without temp files function that broke after updating gradio

* fix linter issue for 1.3.0

* add quoting for infotext values that have a colon in them

* Merge pull request AUTOMATIC1111#10785 from nyqui/fix-hires.fix

fix "hires. fix" prompt sharing same labels with txt2img_prompt

* Merge pull request AUTOMATIC1111#10804 from AUTOMATIC1111/fix-xyz-clip

Fix get_conds_with_caching()

* Merge pull request AUTOMATIC1111#10808 from AUTOMATIC1111/fix-disable-png-info

fix disable png info

* fix [Bug]: LoRA don't apply on dropdown list sd_lora AUTOMATIC1111#10880

* add changelog

* assign devices.dtype early because it's needed before the model is loaded

* update readme

* revert default cross attention optimization to Doggettx
make --disable-opt-split-attention command line option work again

* update readme

---------

Co-authored-by: Aarni Koskela <akx@iki.fi>
Co-authored-by: AUTOMATIC1111 <16777216c@gmail.com>
Co-authored-by: papuSpartan <30642826+papuSpartan@users.noreply.github.com>
Co-authored-by: w-e-w <40751091+w-e-w@users.noreply.github.com>
Co-authored-by: brkirch <brkirch@users.noreply.github.com>
Co-authored-by: catboxanon <122327233+catboxanon@users.noreply.github.com>
Co-authored-by: Sakura-Luna <53183413+Sakura-Luna@users.noreply.github.com>
Co-authored-by: Keith <1868690+wk5ovc@users.noreply.github.com>
Co-authored-by: bobzilladev <bob@ngrok.com>
Co-authored-by: grimatoma <grimatoma@gmail.com>
Co-authored-by: Weiming <ciici123@hotmail.com>
Co-authored-by: dennissheng <dennismtsg@gmail.com>
Co-authored-by: Baptiste Rajaut <pokexpert30@gmail.com>
Co-authored-by: Iheuzio <97270760+Iheuzio@users.noreply.github.com>
Co-authored-by: Kamil Krzyżanowski <kamnxt@kamnxt.com>
Co-authored-by: ryankashi <ryankashi@berkeley.edu>
Co-authored-by: Thottyottyotty <thot@thiic.cc>
Co-authored-by: anonCantCode <133663594+anonCantCode@users.noreply.github.com>
Co-authored-by: shinshin86 <beagles1986@gmail.com>
@joebbowers
Copy link

This has not been resolved as of 10/13/23

`*** Error loading/saving model file
Traceback (most recent call last):
File "C:\stablediffusion\stable-diffusion-webui\modules\ui_checkpoint_merger.py", line 21, in modelmerger
results = extras.run_modelmerger(*args)
File "C:\stablediffusion\stable-diffusion-webui\modules\extras.py", line 315, in run_modelmerger
safetensors.torch.save_file(theta_0, output_modelname, metadata=metadata if len(metadata)>0 else None)
File "C:\stablediffusion\stable-diffusion-webui\venv\lib\site-packages\safetensors\torch.py", line 232, in save_file
serialize_file(_flatten(tensors), filename, metadata=metadata)
TypeError: argument 'metadata': 'dict' object cannot be converted to 'PyString'

---`

@dennisvink
Copy link

Same issue

@Webtransformer
Copy link

Same here

@mikerodrigues
Copy link

Also seeing this issue.

@AvaCadava
Copy link

still a problem

@blackorbit1
Copy link

Same here

@cvar66
Copy link

cvar66 commented Nov 30, 2023

Just ran into this issue today

@J-Cott
Copy link

J-Cott commented Dec 7, 2023

For me saving as a .ckpt works but not as .safetensors for some models. Annoying to have to convert them in a 3rd party app afterwards.

@joebbowers
Copy link

joebbowers commented Dec 7, 2023 via email

@Flo0
Copy link

Flo0 commented Dec 22, 2023

Unchecking "Copy metadata from merged models" helped me avoid this issue.

@Paul-Williams
Copy link

Paul-Williams commented Dec 22, 2023

Snap :(

For me it only seems to happen for SDXL models

@Paul-Williams
Copy link

Paul-Williams commented Dec 22, 2023

@Flo0 - Any idea how/if excluding this effects the model?

@armentix
Copy link

To exclude this issue, i needed to load each models i wanted to merge first (having the hash tag wrote in the title) then i could merge them afterwards. Don't know why this is needed.

@YashamonSensei
Copy link

@Flo0 - Any idea how/if excluding this effects the model?

Shouldn't affect model itself, only information that is passed with it (i.e. authors, how they were made, ...).

As for topic, it seems like it affects only some checkpoints, and since removing metadata fixes the issue, my guess is that some models have metadata Checkpoint Merger can't parse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-report Report of a bug, yet to be confirmed
Projects
None yet
Development

Successfully merging a pull request may close this issue.