| Name | Architecture | Param size | Type |
|---|---|---|---|
| v2-moe-sft | Mixtral | 166m | SFT |
| v2-moe-base | Mixtral | 166m | Pretrain |
| v2-sft | Mistral | 114m | SFT |
| v2-base | Mistral | 114m | Pretrain |
| v2-vectors | Embedding | - | Tag Embedding |
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4MODEL_NAME = "p1atdev/dart-v2-sft"
5
6tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
7model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.bfloat16)
8
9prompt = (
10 f"<|bos|>"
11 f"<copyright>vocaloid</copyright>"
12 f"<character>hatsune miku</character>"
13 f"<|rating:general|><|aspect_ratio:tall|><|length:long|>"
14 f"<general>1girl, cat ears<|identity:none|><|input_end|>"
15)
16inputs = tokenizer(prompt, return_tensors="pt").input_ids
17
18with torch.no_grad():
19 outputs = model.generate(
20 inputs,
21 do_sample=True,
22 temperature=1.0,
23 top_p=1.0,
24 top_k=100,
25 max_new_tokens=128,
26 num_beams=1,
27 )
28
29print(", ".join([tag for tag in tokenizer.batch_decode(outputs[0], skip_special_tokens=True) if tag.strip() != ""]))
30# vocaloid, hatsune miku, 1girl, cat ears, closed mouth, detached sleeves, dress, expressionless, from behind, full body, green theme, hair ornament, hair ribbon, headphones, high heels, holding, holding microphone, long hair, microphone, monochrome, necktie, ribbon, short dress, shoulder tattoo, simple background, sleeveless, sleeveless dress, spot color, standing, tattoo, thighhighs, twintails, very long hair, white backgrounddartrs library[!WARNING] This library is very experimental and there will be breaking changes in the future.
pip install -U dartrs1from dartrs.dartrs import DartTokenizer
2from dartrs.utils import get_generation_config
3from dartrs.v2 import (
4 compose_prompt,
5 MistralModel,
6 V2Model,
7)
8import time
9import os
10
11MODEL_NAME = "p1atdev/dart-v2-sft"
12
13model = MistralModel.from_pretrained(MODEL_NAME)
14tokenizer = DartTokenizer.from_pretrained(MODEL_NAME)
15
16config = get_generation_config(
17 prompt=compose_prompt(
18 copyright="vocaloid",
19 character="hatsune miku",
20 rating="general", # sfw, general, sensitive, nsfw, questionable, explicit
21 aspect_ratio="tall", # ultra_wide, wide, square, tall, ultra_tall
22 length="medium", # very_short, short, medium, long, very_long
23 identity="none", # none, lax, strict
24 prompt="1girl, cat ears",
25 ),
26 tokenizer=tokenizer,
27)
28
29start = time.time()
30output = model.generate(config)
31end = time.time()
32
33print(output)
34print(f"Time taken: {end - start:.2f}s")
35# 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
36# Time taken: 0.26s1prompt = (
2 f"<|bos|>"
3 f"<copyright>{copyright_tags_here}</copyright>"
4 f"<character>{character_tags_here}</character>"
5 f"<|rating:general|><|aspect_ratio:tall|><|length:long|>"
6 f"<general>{general_tags_here}<|identity:none|><|input_end|>"
7)<|rating:sfw|>, <|rating:general|>, <|rating:sensitive|>, nsfw, <|rating:questionable|>, <|rating:explicit|>sfw: randomly generates tags in general or sensitive rating categories.general: generates tags in general rating category.sensitive: generates tags in sensitive rating category.nsfw: randomly generates tags in questionable or explicit rating categories.questionable: generates tags in questionable rating category.explicit: generates tags in explicit rating category.<|aspect_ratio:ultra_wide|>, <|aspect_ratio:wide|>, <|aspect_ratio:square|>, <|aspect_ratio:tall|>, <|aspect_ratio:ultra_tall|>ultra_wide: generates tags suits for extremely wide aspect ratio images. (~2:1)wide: generates tags suits for wide aspect ratio images. (2:1~9:8)square: generates tags suits for square aspect ratio images. (9:8~8:9)tall: generates tags suits for tall aspect ratio images. (8:9~1:2)ultra_tall: generates tags suits for extremely tall aspect ratio images. (1:2~)<|length:very_short|>, <|length:short|>, <|length:medium|>, <|length:long|>, <|length:very_long|>very_short: totally generates ~10 number of tags.short: totally generates ~20 number of tags.medium: totally generates ~30 number of tags.long: totally generates ~40 number of tags.very_long: totally generates 40~ number of tags.<|identity:none|>, <|identity:lax|>, <|identity:strict|>none: recommended if the specified general tags are very few. It generates tags very creatively, but sometimes ignores the condition of the general tags.lax: recommended if you want to keep the identity of charaacters or subjects in the general tags. This tag tries not to generate tags which conflict with the input general tags.strict: recommended if you strongly want to keep the identity of charaacters or subjects in the general tags. This tag tries not to generate tags which conflict with the input general tags more strictly than lax. But this is less creative, so if you don't like the result with strict, please try lax or none.202403-at20240423: 7M size of danbooru tags dataset since 2005 to 2024/03/31.