RichardErkhov commited on
Commit
23a68be
·
verified ·
1 Parent(s): 880c0df

uploaded readme

Browse files
Files changed (1) hide show
  1. README.md +109 -0
README.md ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Quantization made by Richard Erkhov.
2
+
3
+ [Github](https://github.com/RichardErkhov)
4
+
5
+ [Discord](https://discord.gg/pvy7H8DZMG)
6
+
7
+ [Request more models](https://github.com/RichardErkhov/quant_request)
8
+
9
+
10
+ distilgpt2-stable-diffusion-v2 - bnb 8bits
11
+ - Model creator: https://huggingface.co/FredZhang7/
12
+ - Original model: https://huggingface.co/FredZhang7/distilgpt2-stable-diffusion-v2/
13
+
14
+
15
+
16
+
17
+ Original model description:
18
+ ---
19
+ license: creativeml-openrail-m
20
+ tags:
21
+ - stable-diffusion
22
+ - prompt-generator
23
+ - arxiv:2210.14140
24
+ widget:
25
+ - text: "amazing"
26
+ - text: "a photo of"
27
+ - text: "a sci-fi"
28
+ - text: "a portrait of"
29
+ - text: "a person standing"
30
+ - text: "a boy watching"
31
+ datasets:
32
+ - FredZhang7/stable-diffusion-prompts-2.47M
33
+ - poloclub/diffusiondb
34
+ - Gustavosta/Stable-Diffusion-Prompts
35
+ - bartman081523/stable-diffusion-discord-prompts
36
+ ---
37
+ # Fast GPT2 PromptGen
38
+
39
+ <style>
40
+ .container {
41
+ padding-left: 20px;
42
+ border-left: 5px solid gray;
43
+ }
44
+ </style>
45
+
46
+ <div class="container">
47
+ <p><strong><a href="https://huggingface.co/FredZhang7/anime-anything-promptgen-v2">Fast Anime PromptGen</a></strong> generates descriptive safebooru and danbooru tags for anime text-to-image models.</p>
48
+ </div>
49
+
50
+
51
+ This model was trained on 2,470,000 descriptive stable diffusion prompts on the [FredZhang7/distilgpt2-stable-diffusion](https://huggingface.co/FredZhang7/distilgpt2-stable-diffusion) checkpoint for another 4,270,000 steps.
52
+
53
+ Compared to other prompt generation models using GPT2, this one runs with 50% faster forwardpropagation and 40% less disk space & RAM.
54
+
55
+ Major improvements from v1 are:
56
+ - 25% more variations
57
+ - faster and more fluent prompt generation
58
+ - cleaned training data
59
+ * removed prompts that generate images with nsfw scores > 0.5
60
+ * removed duplicates, including prompts that differ by capitalization and punctuations
61
+ * removed punctuations at random places
62
+ * removed prompts shorter than 15 characters
63
+
64
+
65
+ ## Live WebUI Demo
66
+ See the Prompt Generator tab of [Paint Journey Demo](https://huggingface.co/spaces/FredZhang7/paint-journey-demo).
67
+
68
+
69
+ ## Contrastive Search
70
+
71
+ ```bash
72
+ pip install --upgrade transformers
73
+ ```
74
+
75
+ ```python
76
+ from transformers import GPT2Tokenizer, GPT2LMHeadModel
77
+ tokenizer = GPT2Tokenizer.from_pretrained('distilgpt2')
78
+ tokenizer.add_special_tokens({'pad_token': '[PAD]'})
79
+ model = GPT2LMHeadModel.from_pretrained('FredZhang7/distilgpt2-stable-diffusion-v2')
80
+
81
+ prompt = r'a cat sitting' # the beginning of the prompt
82
+ temperature = 0.9 # a higher temperature will produce more diverse results, but with a higher risk of less coherent text
83
+ top_k = 8 # the number of tokens to sample from at each step
84
+ max_length = 80 # the maximum number of tokens for the output of the model
85
+ repitition_penalty = 1.2 # the penalty value for each repetition of a token
86
+ num_return_sequences=5 # the number of results to generate
87
+
88
+ # generate the result with contrastive search
89
+ input_ids = tokenizer(prompt, return_tensors='pt').input_ids
90
+ output = model.generate(input_ids, do_sample=True, temperature=temperature, top_k=top_k, max_length=max_length, num_return_sequences=num_return_sequences, repetition_penalty=repitition_penalty, penalty_alpha=0.6, no_repeat_ngram_size=1, early_stopping=True)
91
+
92
+ print('\nInput:\n' + 100 * '-')
93
+ print('\033[96m' + prompt + '\033[0m')
94
+ print('\nOutput:\n' + 100 * '-')
95
+ for i in range(len(output)):
96
+ print('\033[92m' + tokenizer.decode(output[i], skip_special_tokens=True) + '\033[0m\n')
97
+ ```
98
+
99
+ No comma style:
100
+ ![constrastive search](./constrastive_search.png)
101
+
102
+
103
+ To bring back the commas, assign output without `penalty_alpha` and `no_repeat_ngram_size`:
104
+ ```python
105
+ output = model.generate(input_ids, do_sample=True, temperature=temperature, top_k=top_k, max_length=max_length, num_return_sequences=num_return_sequences, repetition_penalty=repitition_penalty, early_stopping=True)
106
+ ```
107
+
108
+ ![constrastive search](./contrastive_comma_style.png)
109
+