p1atdev commited on
Commit
b9e85f8
•
1 Parent(s): 5a8886a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +169 -157
README.md CHANGED
@@ -1,89 +1,165 @@
1
  ---
2
  library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
4
  ---
5
-
6
- # Model Card for Model ID
7
-
8
- <!-- Provide a quick summary of what the model is/does. -->
9
-
10
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  ## Model Details
13
 
14
  ### Model Description
15
 
16
- <!-- Provide a longer summary of what this model is. -->
17
-
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
-
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
-
28
- ### Model Sources [optional]
29
-
30
- <!-- Provide the basic links for the model. -->
31
-
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
 
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
 
76
  ## Training Details
77
 
78
  ### Training Data
79
 
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
 
 
81
 
82
- [More Information Needed]
83
 
84
  ### Training Procedure
85
 
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
 
88
  #### Preprocessing [optional]
89
 
@@ -92,110 +168,46 @@ Use the code below to get started with the model.
92
 
93
  #### Training Hyperparameters
94
 
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
 
 
 
 
102
 
103
  ## Evaluation
104
 
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
 
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
 
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
 
 
133
 
134
 
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
  ### Compute Infrastructure
160
 
161
- [More Information Needed]
162
 
163
  #### Hardware
164
 
165
- [More Information Needed]
166
 
167
  #### Software
168
 
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
200
 
 
201
 
 
 
 
 
1
  ---
2
  library_name: transformers
3
+ license: apache-2.0
4
+ datasets:
5
+ - isek-ai/danbooru-tags-2024
6
+ base_model: p1atdev/dart-v2-moe-base
7
+ tags:
8
+ - trl
9
+ - sft
10
+ - optimum
11
+ - danbooru
12
+ inference: false
13
  ---
14
+ # Dart (Danbooru Tags Transformer) v2
15
+
16
+ This model is a fine-tuned Dart (Danbooru Tags Transformer) v2 base model that generates danbooru tags.
17
+
18
+ Demo: [🤗 Space with ZERO](https://huggingface.co/spaces/p1atdev/danbooru-tags-transformer-v2)
19
+
20
+ ## Model variants
21
+
22
+ |Name|Architecture|Param size|Type|
23
+ |-|-|-|-|
24
+ |[v2-moe-sft](https://huggingface.co/p1atdev/dart-v2-moe-sft)|Mixtral|166m|SFT|
25
+ |[v2-moe-base](https://huggingface.co/p1atdev/dart-v2-moe-base)|Mixtral|166m|Pretrain|
26
+ |[v2-sft](https://huggingface.co/p1atdev/dart-v2-sft)|Mistral|114m|SFT|
27
+ |[v2-base](https://huggingface.co/p1atdev/dart-v2-base)|Mistral|114m|Pretrain|
28
+ |[v2-vectors](https://huggingface.co/p1atdev/dart-v2-vectors)|Embedding|-|Tag Embedding|
29
+
30
+ ## Usage
31
+
32
+ ### Using 🤗Transformers
33
+
34
+ ```py
35
+ import torch
36
+ from transformers import AutoTokenizer, AutoModelForCausalLM
37
+ MODEL_NAME = "p1atdev/dart-v2-base"
38
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
39
+ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.bfloat16)
40
+ prompt = (
41
+ f"<|bos|>"
42
+ f"<copyright>vocaloid</copyright>"
43
+ f"<character>hatsune miku</character>"
44
+ f"<|rating:general|><|aspect_ratio:tall|><|length:long|>"
45
+ f"<general>1girl"
46
+ )
47
+ inputs = tokenizer(prompt, return_tensors="pt").input_ids
48
+ with torch.no_grad():
49
+ outputs = model.generate(
50
+ inputs,
51
+ do_sample=True,
52
+ temperature=1.0,
53
+ top_p=1.0,
54
+ top_k=100,
55
+ max_new_tokens=128,
56
+ num_beams=1,
57
+ )
58
+ print(", ".join([tag for tag in tokenizer.batch_decode(outputs[0], skip_special_tokens=True) if tag.strip() != ""]))
59
+ ```
60
+
61
+ ### Using 📦`dartrs` library
62
+
63
+ > [!WARNING]
64
+ > This library is very experimental and there will be breaking changes in the future.
65
+
66
+ [📦`dartrs`](https://github.com/p1atdev/dartrs) is a [🤗`candle`](https://github.com/huggingface/candle) backend inference library for Dart v2 models.
67
+
68
+ ```py
69
+ pip install -U dartrs
70
+ ```
71
+
72
+ ```py
73
+ from dartrs.dartrs import DartTokenizer
74
+ from dartrs.utils import get_generation_config
75
+ from dartrs.v2 import (
76
+ compose_prompt,
77
+ MixtralModel,
78
+ V2Model,
79
+ )
80
+ import time
81
+ import os
82
+ MODEL_NAME = "p1atdev/dart-v2-base"
83
+ model = MixtralModel.from_pretrained(MODEL_NAME)
84
+ tokenizer = DartTokenizer.from_pretrained(MODEL_NAME)
85
+ config = get_generation_config(
86
+ prompt=compose_prompt(
87
+ copyright="vocaloid",
88
+ character="hatsune miku",
89
+ rating="general", # sfw, general, sensitive, nsfw, questionable, explicit
90
+ aspect_ratio="tall", # ultra_wide, wide, square, tall, ultra_tall
91
+ length="medium", # very_short, short, medium, long, very_long
92
+ prompt="1girl, cat ears",
93
+ do_completion=False
94
+ ),
95
+ tokenizer=tokenizer,
96
+ )
97
+ start = time.time()
98
+ output = model.generate(config)
99
+ end = time.time()
100
+ print(output)
101
+ print(f"Time taken: {end - start:.2f}s")
102
+ # cowboy shot, detached sleeves, empty eyes, green eyes, green hair, green necktie, hair in own mouth, hair ornament, letterboxed, light frown, long hair, long sleeves, looking to the side, necktie, parted lips, shirt, sleeveless, sleeveless shirt, twintails, wing collar
103
+ # Time taken: 0.26s
104
+ ```
105
+
106
+ ## Prompt Format
107
+
108
+ ```py
109
+ prompt = (
110
+ f"<|bos|>"
111
+ f"<copyright>{copyright_tags_here}</copyright>"
112
+ f"<character>{character_tags_here}</character>"
113
+ f"<|rating:general|><|aspect_ratio:tall|><|length:long|>"
114
+ f"<general>{general_tags_here}"
115
+ )
116
+ ```
117
+
118
+ - Rating tag: `<|rating:sfw|>`, `<|rating:general|>`, `<|rating:sensitive|>`, `nsfw`, `<|rating:questionable|>`, `<|rating:explicit|>`
119
+ - `sfw`: randomly generates tags in `general` or `sensitive` rating categories.
120
+ - `general`: generates tags in `general` rating category.
121
+ - `sensitive`: generates tags in `sensitive` rating category.
122
+ - `nsfw`: randomly generates tags in `questionable` or `explicit` rating categories.
123
+ - `questionable`: generates tags in `questionable` rating category.
124
+ - `explicit`: generates tags in `explicit` rating category.
125
+
126
+ - Aspect ratio tag: `<|aspect_ratio:ultra_wide|>`, `<|aspect_ratio:wide|>`, `<|aspect_ratio:square|>`, `<|aspect_ratio:tall|>`, `<|aspect_ratio:ultra_tall|>`
127
+ - `ultra_wide`: generates tags suits for extremely wide aspect ratio images. (~2:1)
128
+ - `wide`: generates tags suits for wide aspect ratio images. (2:1~9:8)
129
+ - `square`: generates tags suits for square aspect ratio images. (9:8~8:9)
130
+ - `tall`: generates tags suits for tall aspect ratio images. (8:9~1:2)
131
+ - `ultra_tall`: generates tags suits for extremely tall aspect ratio images. (1:2~)
132
+
133
+ - Length tag: `<|length:very_short|>`, `<|length:short|>`, `<|length:medium|>`, `<|length:long|>`, `<|length:very_long|>`
134
+ - `very_short`: totally generates ~10 number of tags.
135
+ - `short`: totally generates ~20 number of tags.
136
+ - `medium`: totally generates ~30 number of tags.
137
+ - `long`: totally generates ~40 number of tags.
138
+ - `very_long`: totally generates 40~ number of tags.
139
 
140
  ## Model Details
141
 
142
  ### Model Description
143
 
144
+ - **Developed by:** Plat
145
+ - **Model type:** Causal language model
146
+ - **Language(s) (NLP):** Danbooru tags
147
+ - **License:** Apache-2.0
148
+ - **Demo:** Available on [🤗 Space](https://huggingface.co/spaces/p1atdev/danbooru-tags-transformer-v2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
  ## Training Details
152
 
153
  ### Training Data
154
 
155
+ This model was trained with:
156
+
157
+ - [isek-ai/danbooru-tags-2024](https://huggingface.co/datasets/isek-ai/danbooru-tags-2024/tree/202403-at20240423) with revision `202403-at20240423`: 7M size of danbooru tags dataset since 2005 to 2024/03/31.
158
 
 
159
 
160
  ### Training Procedure
161
 
162
+ TODO
163
 
164
  #### Preprocessing [optional]
165
 
 
168
 
169
  #### Training Hyperparameters
170
 
171
+ The following hyperparameters were used during training:
172
+ - learning_rate: 0.0005
173
+ - train_batch_size: 1024
174
+ - eval_batch_size: 256
175
+ - seed: 42
176
+ - gradient_accumulation_steps: 2
177
+ - total_train_batch_size: 2048
178
+ - optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
179
+ - lr_scheduler_type: cosine
180
+ - lr_scheduler_warmup_steps: 1000
181
+ - num_epochs: 5
182
 
183
  ## Evaluation
184
 
185
+ Evaluation has not been done yet and it needs to evaluate.
 
 
 
 
 
 
 
 
 
 
186
 
 
187
 
188
+ #### Model Architecture and Objective
 
 
 
 
 
 
 
 
 
 
 
 
189
 
190
+ The architecture of this model is [Mistral](https://huggingface.co/docs/transformers/model_doc/mistral). See details in [config.json](./config.json).
191
 
192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  ### Compute Infrastructure
194
 
195
+ Private server.
196
 
197
  #### Hardware
198
 
199
+ 8x RTX A6000
200
 
201
  #### Software
202
 
203
+ - Dataset processing: [🤗 Datasets](https://github.com/huggingface/datasets)
204
+ - Training: [🤗 Transformers](https://github.com/huggingface/transformers)
205
+ - SFT: [🤗 TRL](https://github.com/huggingface/trl)
206
+ - Inference library: [📦 dartrs](https://github.com/p1atdev/dartrs)
207
+ - Backend: [🤗 candle](https://github.com/huggingface/candle)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
 
209
+ ## Related Projects
210
 
211
+ - [dart-v1](https://huggingface.co/p1atdev/dart-v1): The first version of the Dart model.
212
+ - [KBlueLeaf/DanTagGen](https://huggingface.co/collections/KBlueLeaf/dantaggen-65f82fa9335881a67573556b): The Aspect Ratio tag was inspired by this project.
213
+ - [furusu/danbooru-tag-similarity](https://huggingface.co/spaces/furusu/danbooru-tag-similarity): The idea of clustering tags and its training method was inspired by this project.