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

error when loading custom VAE from safetensors file #379

Closed
ssube opened this issue May 27, 2023 · 1 comment
Closed

error when loading custom VAE from safetensors file #379

ssube opened this issue May 27, 2023 · 1 comment
Assignees
Labels
model/diffusion scope/convert status/fixed issues that have been fixed and released type/bug broken features
Milestone

Comments

@ssube
Copy link
Owner

ssube commented May 27, 2023

When converting a model that uses a custom VAE, and the vae key is set to a local file rather than a HF repo, it fails with:

[2023-05-27 17:04:19,193] INFO: 299372 139862552576000 onnx_web.convert.diffusion.diffusers: loading custom VAE: ../models/.cache/vae-ft-mse-840000-ema-pruned.safetensors
loading pretrained ../models/.cache/vae-ft-mse-840000-ema-pruned.safetensors True False                                                                                                                                                     [2023-05-27 17:04:19,255] ERROR: 299372 139862552576000 __main__: error converting diffusion model diffusion-fantastic-mix-25d-v2
Traceback (most recent call last):                                                                                                                                                                                                          
  File "/opt/onnx-web/api/onnx_env/lib/python3.10/site-packages/diffusers/configuration_utils.py", line 410, in load_config
    config_dict = cls._dict_from_json_file(config_file)                                                                                                                                                                                     
  File "/opt/onnx-web/api/onnx_env/lib/python3.10/site-packages/diffusers/configuration_utils.py", line 520, in _dict_from_json_file                                                                                                            text = reader.read()
  File "/usr/lib/python3.10/codecs.py", line 322, in decode                                                                                                                                                                                 
    (result, consumed) = self._buffer_decode(data, self.errors, final)                                         
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8f in position 25730: invalid start byte                                                                                                                                              
                                                                                                                                                                                                                                            
During handling of the above exception, another exception occurred:                                                                                                                                                                         
                                                                                                                      
Traceback (most recent call last):                                                                                                                                                                                                          
  File "/opt/onnx-web/api/onnx_web/convert/__main__.py", line 359, in convert_models                                                                                                                                                        
    converted, dest = convert_diffusion_diffusers(                                                                                                                                                                                          
  File "/opt/onnx-web/api/onnx_env/lib/python3.10/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/opt/onnx-web/api/onnx_web/convert/diffusion/diffusers.py", line 525, in convert_diffusion_diffusers
    vae = AutoencoderKL.from_pretrained(replace_vae)
  File "/opt/onnx-web/api/onnx_env/lib/python3.10/site-packages/diffusers/models/modeling_utils.py", line 494, in from_pretrained
    config, unused_kwargs, commit_hash = cls.load_config(
  File "/opt/onnx-web/api/onnx_env/lib/python3.10/site-packages/diffusers/configuration_utils.py", line 414, in load_config
    raise EnvironmentError(f"It looks like the config file at '{config_file}' is not a valid JSON file.")
OSError: It looks like the config file at '../models/.cache/vae-ft-mse-840000-ema-pruned.safetensors' is not a valid JSON file.

The error is technically correct, the safetensors file is not a JSON file. For some reason, AutoencoderKL.from_pretrained is now looking for a config at the same filename/path, which does not exist and causes the error. I'm not sure how this worked before, but it must have been loading a VAE config from the working Torch model or something.

@ssube ssube added status/planned issues that have been planned but not started type/bug broken features scope/convert model/diffusion labels May 27, 2023
@ssube ssube added this to the v0.10 milestone May 27, 2023
@ssube ssube self-assigned this May 27, 2023
@ssube ssube modified the milestones: v0.10, v0.11 Jun 9, 2023
@ssube ssube modified the milestones: v0.11, v0.10 Dec 3, 2023
@ssube
Copy link
Owner Author

ssube commented Dec 3, 2023

This has been updated to use AutoencoderKL.from_single_file and should support safetensors and pickle tensors.

@ssube ssube closed this as completed Dec 3, 2023
@ssube ssube added status/fixed issues that have been fixed and released and removed status/planned issues that have been planned but not started labels Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
model/diffusion scope/convert status/fixed issues that have been fixed and released type/bug broken features
Projects
None yet
Development

No branches or pull requests

1 participant