shb777 commited on
Commit
893c0e6
·
verified ·
0 Parent(s):

Super-squash branch 'main' using huggingface_hub

Browse files
.gitattributes ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ base_model: unsloth/gemma-3-270m
4
+ tags:
5
+ - text-generation-inference
6
+ - transformers
7
+ - unsloth
8
+ - gemma3_text
9
+ - trl
10
+ license: gemma
11
+ ---
12
+
13
+ # PromptTuner v0.1
14
+
15
+ **PromptTuner-v0.1** is a fine-tuned [gemma-3-270M-it](https://huggingface.co/google/gemma-3-270m-it) model specifically designed to enhance text prompts for text-to-image models.
16
+
17
+ This model takes a basic image concept and expands into rich, detailed descriptions including:
18
+ - Visual composition and perspective
19
+ - Artistic style and medium
20
+ - Color palette and lighting
21
+ - Atmosphere and mood
22
+ - Textures and materials
23
+ - Environmental context
24
+
25
+ The model tries preserves the core intent of your original prompt while adding professional-quality visual descriptors.
26
+
27
+ ## Dataset
28
+
29
+ The model was trained on a curated collection of prompt/magic-prompt pairs.
30
+
31
+ The dataset underwent extensive cleaning to ensure quality:
32
+ - Removed duplicates
33
+ - Removed prompts consisting only of numbers and spaces
34
+ - Filtered out magic prompts containing error messages or refusal responses
35
+ - Removed magic prompts below quality thresholds
36
+ - Cleaned up quotation marks at prompt boundaries
37
+ - Removed rows with excessively short prompts (length <= 2)
38
+ - Filtered out web links and URLs
39
+ - Removed gibberish inputs
40
+ - Filtered pairs where prompt and magic prompt were too similar
41
+
42
+ The training dataset was balanced using K-means clustering on prompt embeddings to ensure diverse representation of creative concepts.
43
+
44
+ ## Training
45
+
46
+ [<img src="https://raw.githubusercontent.com/wandb/assets/main/wandb-github-badge-28.svg" alt="Visualize in Weights & Biases" width="150" height="24"/>](https://api.wandb.ai/links/shb777-self/ugs1nrkm)
47
+
48
+ - **Training Method**: LoRA
49
+ - Rank: 16
50
+ - Alpha: 32
51
+ - Target modules: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
52
+ - **Epochs**: 3
53
+ - **Batch Size**: 16
54
+ - **Learning Rate**: 2e-4
55
+ - **Optimizer**: adamw_8bit
56
+ - **LR Scheduler**: Cosine
57
+ - **Warmup Ratio**: 0.1
58
+ - **Train/Test Split**: 90/10
59
+
60
+ ## Usage
61
+
62
+ ```python
63
+ from transformers import AutoTokenizer, AutoModelForCausalLM
64
+
65
+ model = AutoModelForCausalLM.from_pretrained("shb777/PromptTuner-v0.1")
66
+ tokenizer = AutoTokenizer.from_pretrained("shb777/PromptTuner-v0.1")
67
+
68
+ SYSTEM_PROMPT = """You are an expert creative director specializing in visual descriptions for image generation.
69
+
70
+ Your task: Transform the user's concept into a rich, detailed image description while PRESERVING their core idea.
71
+
72
+ IMPORTANT RULES:
73
+ 1. Keep ALL key elements (intents, entities) from the original concept
74
+ 2. Enhance with artistic details, NOT change the fundamental idea
75
+ 3. Maintain the user's intended subject, action, and setting
76
+
77
+ You should elaborate on:
78
+ - Visual composition and perspective
79
+ - Artistic style (photorealistic, impressionist, etc.)
80
+ - Color palette and color temperature
81
+ - Lighting (golden hour, dramatic shadows, etc.)
82
+ - Atmosphere and mood
83
+ - Textures and materials
84
+ - Technical details (medium, brushwork, rendering style)
85
+ - Environmental context (time of day, weather, season, era)
86
+ - Level of detail and focus points
87
+
88
+ Output format: A single, flowing paragraph that reads naturally as an image prompt."""
89
+
90
+ user_input = "fox, red tail, blue moon, clouds"
91
+
92
+ messages = [
93
+ {"role": "system", "content": SYSTEM_PROMPT},
94
+ {"role": "user", "content": user_input}
95
+ ]
96
+
97
+ prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
98
+ inputs = tokenizer(prompt, return_tensors="pt")
99
+
100
+ outputs = model.generate(
101
+ **inputs,
102
+ max_new_tokens=512,
103
+ temperature=1.0,
104
+ top_p=0.95,
105
+ top_k=64
106
+ )
107
+
108
+ enhanced_prompt = tokenizer.decode(outputs[0], skip_special_tokens=True)
109
+ print(enhanced_prompt)
110
+ ```
111
+
112
+ ### Recommended Generation Parameters
113
+
114
+ > [!NOTE]
115
+ > You must use the exact system prompt shown above, as the model was trained on it.
116
+
117
+ - `max_new_tokens`: 512
118
+ - `temperature`: 1.0
119
+ - `top_p`: 0.95
120
+ - `top_k`: 64
121
+
122
+ You can try the model directly at [TinkerSpace](https://huggingface.co/spaces/shb777/TinkerSpace) HF Space.
123
+
124
+ ## Limitations
125
+
126
+ This is only the first version of PromptTuner. As an initial release, the model may:
127
+ - Occasionally lose details and relationships from multi-entity prompts
128
+ - Sometimes introduce stylistic elements and text not present in the original concept
129
+
130
+ Feedback and suggestions for improvement are welcome.
131
+
132
+ ## License
133
+
134
+ This model is built upon Google's Gemma 3. Please refer to the Gemma license for usage terms.
135
+
136
+ ## Citation
137
+
138
+ If you use this model in your work, please cite:
139
+
140
+ ```bibtex
141
+ @model{prompt_tuner_v0.1,
142
+ title={PromptTuner-v0.1: A Fine-tuned Gemma3-270M for Prompt Enhancement},
143
+ author={shb777},
144
+ year={2025},
145
+ url={https://huggingface.co/shb777/PromptTuner-v0.1}
146
+ }
147
+ ```
148
+
149
+ ## Acknowledgments
150
+
151
+ - Base model: [google/gemma-3-270M-it](https://huggingface.co/google/gemma-3-270M-it)
152
+ - Training framework: [Unsloth](https://github.com/unslothai/unsloth)
added_tokens.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "<image_soft_token>": 262144
3
+ }
chat_template.jinja ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {# Unsloth Chat template fixes #}
2
+
3
+ {%- if messages[0]['role'] == 'system' -%}
4
+ {%- if messages[0]['content'] is string -%}
5
+ {%- set first_user_prefix = messages[0]['content'] + '
6
+
7
+ ' -%}
8
+ {%- else -%}
9
+ {%- set first_user_prefix = messages[0]['content'][0]['text'] + '
10
+
11
+ ' -%}
12
+ {%- endif -%}
13
+ {%- set loop_messages = messages[1:] -%}
14
+ {%- else -%}
15
+ {%- set first_user_prefix = "" -%}
16
+ {%- set loop_messages = messages -%}
17
+ {%- endif -%}
18
+ {%- for message in loop_messages -%}
19
+ {%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%}
20
+ {{ raise_exception("Conversation roles must alternate user/assistant/user/assistant/...") }}
21
+ {%- endif -%}
22
+ {%- if (message['role'] == 'assistant') -%}
23
+ {%- set role = "model" -%}
24
+ {%- else -%}
25
+ {%- set role = message['role'] -%}
26
+ {%- endif -%}
27
+ {{ '<start_of_turn>' + role + '
28
+ ' + (first_user_prefix if loop.first else "") }}
29
+ {%- if message['content'] is string -%}
30
+ {{ message['content'] | trim }}
31
+ {%- elif message['content'] is iterable -%}
32
+ {%- for item in message['content'] -%}
33
+ {%- if item['type'] == 'image' -%}
34
+ {{ '<start_of_image>' }}
35
+ {%- elif item['type'] == 'text' -%}
36
+ {{ item['text'] | trim }}
37
+ {%- endif -%}
38
+ {%- endfor -%}
39
+ {%- elif message['content'] is defined -%}
40
+ {{ raise_exception("Invalid content type") }}
41
+ {%- endif -%}
42
+ {{ '<end_of_turn>
43
+ ' }}
44
+ {%- endfor -%}
45
+ {%- if add_generation_prompt -%}
46
+ {{'<start_of_turn>model
47
+ '}}
48
+ {%- endif -%}
49
+
50
+ {# Copyright 2025-present Unsloth. Apache 2.0 License. #}
config.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_sliding_window_pattern": 6,
3
+ "architectures": [
4
+ "Gemma3ForCausalLM"
5
+ ],
6
+ "attention_bias": false,
7
+ "attention_dropout": 0.0,
8
+ "attn_logit_softcapping": null,
9
+ "bos_token_id": 2,
10
+ "dtype": "bfloat16",
11
+ "eos_token_id": 106,
12
+ "final_logit_softcapping": null,
13
+ "head_dim": 256,
14
+ "hidden_activation": "gelu_pytorch_tanh",
15
+ "hidden_size": 640,
16
+ "initializer_range": 0.02,
17
+ "intermediate_size": 2048,
18
+ "layer_types": [
19
+ "sliding_attention",
20
+ "sliding_attention",
21
+ "sliding_attention",
22
+ "sliding_attention",
23
+ "sliding_attention",
24
+ "full_attention",
25
+ "sliding_attention",
26
+ "sliding_attention",
27
+ "sliding_attention",
28
+ "sliding_attention",
29
+ "sliding_attention",
30
+ "full_attention",
31
+ "sliding_attention",
32
+ "sliding_attention",
33
+ "sliding_attention",
34
+ "sliding_attention",
35
+ "sliding_attention",
36
+ "full_attention"
37
+ ],
38
+ "max_position_embeddings": 32768,
39
+ "model_type": "gemma3_text",
40
+ "num_attention_heads": 4,
41
+ "num_hidden_layers": 18,
42
+ "num_key_value_heads": 1,
43
+ "pad_token_id": 0,
44
+ "query_pre_attn_scalar": 256,
45
+ "rms_norm_eps": 1e-06,
46
+ "rope_local_base_freq": 10000.0,
47
+ "rope_scaling": null,
48
+ "rope_theta": 1000000.0,
49
+ "sliding_window": 512,
50
+ "transformers_version": "4.57.3",
51
+ "unsloth_fixed": true,
52
+ "unsloth_version": "2025.12.9",
53
+ "use_bidirectional_attention": false,
54
+ "use_cache": true,
55
+ "vocab_size": 262144
56
+ }
generation_config.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 2,
4
+ "eos_token_id": 106,
5
+ "max_length": 32768,
6
+ "pad_token_id": 0,
7
+ "transformers_version": "4.57.3"
8
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d749f35a81ff0884023bb2b74f1441f1c0c870e1fa41054d603c9da4a566201d
3
+ size 536334056
special_tokens_map.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "boi_token": "<start_of_image>",
3
+ "bos_token": {
4
+ "content": "<bos>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false
9
+ },
10
+ "eoi_token": "<end_of_image>",
11
+ "eos_token": {
12
+ "content": "<end_of_turn>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false
17
+ },
18
+ "image_token": "<image_soft_token>",
19
+ "pad_token": {
20
+ "content": "<pad>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false
25
+ },
26
+ "unk_token": {
27
+ "content": "<unk>",
28
+ "lstrip": false,
29
+ "normalized": false,
30
+ "rstrip": false,
31
+ "single_word": false
32
+ }
33
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4667f2089529e8e7657cfb6d1c19910ae71ff5f28aa7ab2ff2763330affad795
3
+ size 33384568
tokenizer_config.json ADDED
The diff for this file is too large to render. See raw diff