Downloads · 30 days
993
1% of all-time downloads
p1atdev/dart-v1-sft
dart-v1-sft is a text generation model from p1atdev. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
This model is a fine-tuned Dart (Danbooru Tags Transformer) model that generates danbooru tags.
Downloads · 30 days
993
1% of all-time downloads
All-time downloads
181K
Public
Parameters
139M
1.5 GB on disk
Likes
20
Public
Click a slice to open those files.
.onnx695 MB · 71%
From the Hugging Face model README
This model is a fine-tuned Dart (Danbooru Tags Transformer) model that generates danbooru tags.
Demo: 🤗 Space
If you are a developer and want to finetune, it's recommended using the base version, p1atdev/dart-v1-base, instead
🤗 Transformers library is required.
pip install -U transformers
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
MODEL_NAME = "p1atdev/dart-v1-sft"
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, trust_remote_code=True) # trust_remote_code is required for tokenizer
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.bfloat16)
prompt = "<|bos|><rating>rating:sfw, rating:general</rating><copyright>original</copyright><character></character><general><|long|>1girl<|input_end|>"
inputs = tokenizer(prompt, return_tensors="pt").input_ids
with torch.no_grad():
outputs = model.generate(inputs, generation_config=model.generation_config)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
# rating:sfw, rating:general, 1girl, ahoge, braid, closed eyes, collared dress, dress, flower, full body, hair flower, hair ornament, long hair, night, night sky, outdoors, parted lips, pink flower, pink hair, short sleeves, sky, solo, straight hair, sunflower, very long hair, white flower
You can use tokenizer.apply_chat_template to simplify constructiing of prompts:
inputs = tokenizer.apply_chat_template({
"rating": "rating:sfw, rating:general",
"copyright": "original",
"character": "",
"general": "1girl",
"length": "<|long|>"
}, return_tensors="pt", tokenize=True) # tokenize=False to preview prompt
# same as input_ids of "<|bos|><rating>rating:sfw, rating:general</rating><copyright>original</copyright><character></character><general><|long|>1girl<|input_end|>"
with torch.no_grad():
outputs = model.generate(inputs, generation_config=generation_config)
See chat_templating document for more detail about apply_chat_template.
Using flash attention can optimize computations, but it is currently only compatible with Linux.
pip install flash_attn
🤗 Optimum library is also compatible, for the high performance inference using ONNX.
pip install "optimum[onnxruntime]"
Two ONNX models are provided:
Both can be utilized based on the following code:
import torch
from transformers import AutoTokenizer, GenerationConfig
from optimum.onnxruntime import ORTModelForCausalLM
MODEL_NAME = "p1atdev/dart-v1-sft"
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, trust_remote_code=True)
# normal version
ort_model = ORTModelForCausalLM.from_pretrained(MODEL_NAME)
# qunatized version
# ort_model = ORTModelForCausalLM.from_pretrained(MODEL_NAME, file_name="model_quantized.onnx")
inputs = tokenizer.apply_chat_template({
"rating": "rating:sfw, rating:general",
"copyright": "original",
"character": "",
"general": "1girl",
"length": "<|long|>"
}, return_tensors="pt", tokenize=True)
with torch.no_grad():
outputs = ort_model.generate(inputs, generation_config=model.generation_config)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
Due to training with a specialized prompt format, natural language is not supported.
The trained sentences are essentially composed of the following elements, arranged in the strict order shown below:
<|bos|>: The bos (begin of sentence) token
<rating>[RATING_PARENT], [RATING_CHILD]</rating>: The block of rating tags
rating:sfw, rating:nsfw[RATING_PARENT] is rating:sfw: rating:general, rating:sensitiverating:questionable, rating:explicit<copyright>[COPYRIGHT, ...]</copyright>: The block of copyright tags.
<character>[CHARACTER, ...]</character>: The block of character tags.
<general>[LENGTH_TOKEN][GENERAL, ...]<|input_end|>[COMPLETION]</general>: The block of general tags.
<|very_short|>: less than 10 tags<|short|>: less than 20 tags<|long|>: less than 40 tags (recommended)<|very_long|>: more than 40 tags<|input_end|>: A tag to show the end of input. Set this token at last of prompt.<|eos|>: The eos (end of sentence) token
Tags other than special tokens are separated by commas.
You can place tags in any order you like in each block.
Example sentence:
<|bos|><rating>rating:sfw, rating:general</rating><copyright>vocaloid</copyright><character>hatsune miku</character><general><|long|>solo, 1girl, very long hair<|input_end|>blue hair, cowboy shot, ...</general><|eos|>
Therefore, to complete the tags, the input prompt should be as follows:
<|bos|><rating>rating:sfw, rating:general</rating><copyright></copyright><character></character><general><|very_long|>1girl, solo, cat ears<|input_end|>
<|bos|><rating>rating:sfw, rating:general</rating><copyright>sousou no frieren</copyright><character>frieren</character><general><|long|>1girl, solo, from side<|input_end|>
Developed by: Plat
Model type: Causal language model
Language(s) (NLP): Danbooru tags
License: Apache-2.0
Demo: Avaiable on 🤗Space
Since this model is a pre-trained model, it cannot accommodate flexible specifications.
This model was trained with:
Only data from 2020 onwards was used for SFT.
Trained using 🤗 transformers' trainer.
Preprocessing was conducted through the following process:
general tags is null.general tags that appear less than 100 times.watermark and bad anatomy.general tags.copyright tags.character tags.1girl, no humans) tags in the shuffle-group with a 95% probability, and do not do so with a 5% probability.<|input_end|> token and remains in alphabetical order.The following hyperparameters were used during training:
Evaluation has not been done yet and it needs to evaluate.
The architecture of this model is OPT (Open Pretrained Transformer), but the position embeddings was not trained.
In house
1x RTX 3070 Ti
[More Information Needed]