Commit
·
167557f
1
Parent(s):
b8cb7e2
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,30 @@
|
|
| 1 |
---
|
| 2 |
license: gpl-3.0
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: gpl-3.0
|
| 3 |
---
|
| 4 |
+
|
| 5 |
+
# Easy CLIP Embeddings alignment with Guannaco Models
|
| 6 |
+
|
| 7 |
+
```python
|
| 8 |
+
pipe = StableDiffusionPipeline(...)
|
| 9 |
+
# llm_model = load_quant('/GuanacoOnConsumerHardware', 'guanaco7b-4bit-128g.pt', 4, 128, 0)
|
| 10 |
+
llm_tokenizer = LlamaTokenizer.from_pretrained("JosephusCheung/Guanaco",use_fast=False,torch_dtype=torch.float16)
|
| 11 |
+
llm_model = LlamaForCausalLM.from_pretrained("JosephusCheung/Guanaco",device_map="auto",torch_dtype=torch.float16)
|
| 12 |
+
|
| 13 |
+
class LLMToCLIP(nn.Module):
|
| 14 |
+
def __init__(self):
|
| 15 |
+
super(LLMToCLIP, self).__init__()
|
| 16 |
+
self.proj = nn.Linear(4096, 4096, bias=False)
|
| 17 |
+
self.deproj = nn.Linear(4096, 768, bias=False)
|
| 18 |
+
|
| 19 |
+
def forward(self, x):
|
| 20 |
+
a = self.proj(x)
|
| 21 |
+
b = self.deproj(a)
|
| 22 |
+
return b
|
| 23 |
+
|
| 24 |
+
llm_to_clip=LLMToCLIP()
|
| 25 |
+
llm_to_clip.load_state_dict(torch.load("toclip.pth"))
|
| 26 |
+
|
| 27 |
+
llm_embeddings = llm_model(input_ids=input_ids, output_hidden_states=True).hidden_states[-1]
|
| 28 |
+
|
| 29 |
+
image = pipe(prompt_embeds=llm_to_clip(llm_embeddings)).images[0]
|
| 30 |
+
```
|