convert model to safetensors

#2
by keturn - opened

This is the state_dict of the model converted to safetensors.

I think. It is a whole lot smaller than ckpt.pt, but that might be due to the fact that it doesn't include all the optimizer data?

keturn changed pull request title from Upload model.safetensors with huggingface_hub to convert model to safetensors

Hello, have you tried using this directly in huggingface transformers? If so, which type of huggingface transformers model should I use that with? And is there any special config I need to use?

I've been trying to get it to work with regular clip, but have been running into errors.

Oh also @keturn how did you do the conversion to safetensors?

something like this

import numpy.core.multiarray

torch.serialization.add_safe_globals([
    (numpy.core.multiarray.scalar, 'numpy.core.multiarray.scalar'), 
    numpy.dtype, 
    numpy.dtypes.Float64DType
])
ckpt = torch.load('ckpt.pt', 'cpu', weights_only=True)
state_dict = ckpt['state_dict']
import safetensors.torch
safetensors.torch.save_file(state_dict, Path('model.safetensors'), {'format': 'pt'})

and I'm not sure whether it can work with transformers alone. I think it would be CLIPTextModelWithProjection, but the keys in the state dict are named different things than the models that's usually used with, so I don't know if it can be run without the authors' code https://github.com/ivonajdenkoska/tulip

Ah okay yeah, cuz I ran into naming issues when trying to use the model directly as a huggingface clip

Ready to merge
This branch is ready to get merged automatically.
Your need to confirm your account before you can post a new comment.

Sign up or log in to comment