How to use this embeddings in diffusers?

#6
by garyfang - opened

Does anybody know how to use the embedding file in .pt or .safetensors format in diffusers? It seems diffusers doesn't have approach to load these file directly and I cannot find any approach to convert the files either.

ask the same....

did you find the solution?

I am a complete amateur, but this is what seems to be working for me:

negative_prompt_embeds = torch.load('/xxx/EasyNegative.pt')['emb_params'].to(device)
negative_prompt_embeds = negative_prompt_embeds.unsqueeze(0).repeat(batch_size, 1, 1)
max_length = pipeline.tokenizer.model_max_length
padding_size = 77 - negative_prompt_embeds.shape[1]
padding_zeros = torch.zeros(batch_size, padding_size, negative_prompt_embeds.shape[-1]).to(device)
 negative_prompt_embeds = torch.cat((negative_prompt_embeds, padding_zeros), dim=1) ```

and then in your pipeline you call it with pipeline(prompt=prompt, negative_prompt_embeds=negative_prompt_embeds)

without the padding the calls of prompt and negative prompt embed are not compatible

https://huggingface.co/docs/diffusers/using-diffusers/loading_adapters

I am a complete amateur, but this is what seems to be working for me:

negative_prompt_embeds = torch.load('/xxx/EasyNegative.pt')['emb_params'].to(device)
negative_prompt_embeds = negative_prompt_embeds.unsqueeze(0).repeat(batch_size, 1, 1)
max_length = pipeline.tokenizer.model_max_length
padding_size = 77 - negative_prompt_embeds.shape[1]
padding_zeros = torch.zeros(batch_size, padding_size, negative_prompt_embeds.shape[-1]).to(device)
 negative_prompt_embeds = torch.cat((negative_prompt_embeds, padding_zeros), dim=1) ```

and then in your pipeline you call it with pipeline(prompt=prompt, negative_prompt_embeds=negative_prompt_embeds)

without the padding the calls of prompt and negative prompt embed are not compatible

I take that back, maybe look here:
https://huggingface.co/docs/diffusers/using-diffusers/loading_adapters, and example easynegative:

pipeline.load_textual_inversion(
    "sayakpaul/EasyNegative-test", weight_name="EasyNegative.safetensors", token="EasyNegative"
)
prompt = "A cute brown bear eating a slice of pizza, stunning color scheme, masterpiece, illustration, EasyNegative"
negative_prompt = "EasyNegative"

image = pipeline(prompt, negative_prompt=negative_prompt, num_inference_steps=50).images[0]
image

Sign up or log in to comment