Repository: AUTOMATIC1111/stable-diffusion-webui

Issue:
[Bug]: Checkpoint merger error
### Is there an existing issue for this?

- [X] 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

https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/89f9faa63388756314e8a1d96cf86bf5e0663045

### What platforms do you use to access the UI ?

Windows

### What browsers do you use to access the UI ?

Google Chrome

### Command Line Arguments

```Shell
--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

```Shell
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_


Discussion:

Resolving patch:
diff --git a/modules/extras.py b/modules/extras.py
--- a/modules/extras.py
+++ b/modules/extras.py
@@ -242,9 +242,10 @@ def filename_nothing():
     shared.state.textinfo = "Saving"
     print(f"Saving to {output_modelname}...")
 
-    metadata = {"format": "pt", "sd_merge_models": {}, "sd_merge_recipe": None}
+    metadata = None
 
     if save_metadata:
+        metadata = {"format": "pt", "sd_merge_models": {}}
         merge_recipe = {
             "type": "webui", # indicate this model was merged with webui's built-in merger
             "primary_model_hash": primary_model_info.sha256,


Test patch: