stable-diffusion.cpp icon indicating copy to clipboard operation
stable-diffusion.cpp copied to clipboard

Add support for autodetecting tensor_storage.type from the size of the stream

Open lmagder opened this issue 1 year ago • 0 comments

I'm honestly not sure if this is even valid as per the official format, but I have some existing .ckpt files which were written using the automatic1111 DreamBooth extension and they contain some f16 tensors without GLOBAL 'torch HalfStorage' opcodes in the pkl stream.

These load fine on the Python implementation, but fail here since PickleTensorReader skips those tensors due a mismatched size. It seems the other loader is guessing the f16 format based on the size of the tensor data file, whereas this code always assumes f32 if the pickle header doesn't contain a specifier.

With this change my checkpoints load and work fine with stable-diffuision.cpp so I figured I would make a PR incase there are other .ckpts out there that need this same fixup to load and maybe it helps somebody else.

lmagder avatar Jun 16 '24 03:06 lmagder