yujiepan commited on
Commit
69a78d1
·
verified ·
1 Parent(s): ee77948

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* 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
 
 
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,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ pipeline_tag: image-text-to-text
4
+ inference: true
5
+ widget:
6
+ - text: Hello!
7
+ example_title: Hello world
8
+ group: Python
9
+ ---
10
+
11
+ This tiny model is for debugging. It is randomly initialized with the config adapted from [google/gemma-3-27b-it](https://huggingface.co/google/gemma-3-27b-it).
12
+
13
+ ### Example usage:
14
+
15
+ ```python
16
+ from transformers import pipeline
17
+ model_id = "tiny-random/gemma-3"
18
+ pipe = pipeline(
19
+ "image-text-to-text", model=model_id, device="cuda",
20
+ trust_remote_code=True, max_new_tokens=3,
21
+ )
22
+ messages = [
23
+ {
24
+ "role": "system",
25
+ "content": [{"type": "text", "text": "You are a helpful assistant."}]
26
+ },
27
+ {
28
+ "role": "user",
29
+ "content": [
30
+ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
31
+ {"type": "text", "text": "What animal is on the candy?"}
32
+ ]
33
+ }
34
+ ]
35
+ output = pipe(text=messages, max_new_tokens=5)
36
+ print(output)
37
+ ```
38
+
39
+ ### Codes to create this repo:
40
+
41
+ ```python
42
+ import torch
43
+
44
+ from transformers import (
45
+ AutoConfig,
46
+ AutoModelForCausalLM,
47
+ AutoProcessor,
48
+ AutoTokenizer,
49
+ Gemma3ForConditionalGeneration,
50
+ GenerationConfig,
51
+ pipeline,
52
+ set_seed,
53
+ )
54
+
55
+ source_model_id = "google/gemma-3-27b-it"
56
+ save_folder = "/tmp/tiny-random/gemma-3"
57
+
58
+ processor = AutoProcessor.from_pretrained(
59
+ source_model_id, trust_remote_code=True,
60
+ )
61
+ processor.save_pretrained(save_folder)
62
+
63
+ config = AutoConfig.from_pretrained(
64
+ source_model_id, trust_remote_code=True,
65
+ )
66
+ config.text_config.hidden_size = 32
67
+ config.text_config.intermediate_size = 128
68
+ config.text_config.head_dim = 32
69
+ config.text_config.num_attention_heads = 1
70
+ config.text_config.num_key_value_heads = 1
71
+ config.text_config.num_hidden_layers = 2
72
+ config.text_config.sliding_window_pattern = 2
73
+ config.vision_config.hidden_size = 32
74
+ config.vision_config.num_hidden_layers = 2
75
+ config.vision_config.num_attention_heads = 1
76
+ config.vision_config.intermediate_size = 128
77
+ model = Gemma3ForConditionalGeneration(
78
+ config,
79
+ ).to(torch.bfloat16)
80
+ for layer in model.language_model.model.layers:
81
+ print(layer.is_sliding)
82
+ model.generation_config = GenerationConfig.from_pretrained(
83
+ source_model_id, trust_remote_code=True,
84
+ )
85
+ set_seed(42)
86
+ with torch.no_grad():
87
+ for name, p in sorted(model.named_parameters()):
88
+ torch.nn.init.normal_(p, 0, 0.5)
89
+ print(name, p.shape)
90
+ model.save_pretrained(save_folder)
91
+ ```
added_tokens.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "<image_soft_token>": 262144
3
+ }
chat_template.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "chat_template": "{{ bos_token }}\n{%- if messages[0]['role'] == 'system' -%}\n {%- if messages[0]['content'] is string -%}\n {%- set first_user_prefix = messages[0]['content'] + '\n\n' -%}\n {%- else -%}\n {%- set first_user_prefix = messages[0]['content'][0]['text'] + '\n\n' -%}\n {%- endif -%}\n {%- set loop_messages = messages[1:] -%}\n{%- else -%}\n {%- set first_user_prefix = \"\" -%}\n {%- set loop_messages = messages -%}\n{%- endif -%}\n{%- for message in loop_messages -%}\n {%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%}\n {{ raise_exception(\"Conversation roles must alternate user/assistant/user/assistant/...\") }}\n {%- endif -%}\n {%- if (message['role'] == 'assistant') -%}\n {%- set role = \"model\" -%}\n {%- else -%}\n {%- set role = message['role'] -%}\n {%- endif -%}\n {{ '<start_of_turn>' + role + '\n' + (first_user_prefix if loop.first else \"\") }}\n {%- if message['content'] is string -%}\n {{ message['content'] | trim }}\n {%- elif message['content'] is iterable -%}\n {%- for item in message['content'] -%}\n {%- if item['type'] == 'image' -%}\n {{ '<start_of_image>' }}\n {%- elif item['type'] == 'text' -%}\n {{ item['text'] | trim }}\n {%- endif -%}\n {%- endfor -%}\n {%- else -%}\n {{ raise_exception(\"Invalid content type\") }}\n {%- endif -%}\n {{ '<end_of_turn>\n' }}\n{%- endfor -%}\n{%- if add_generation_prompt -%}\n {{'<start_of_turn>model\n'}}\n{%- endif -%}\n"
3
+ }
config.json ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Gemma3ForConditionalGeneration"
4
+ ],
5
+ "boi_token_index": 255999,
6
+ "eoi_token_index": 256000,
7
+ "eos_token_id": [
8
+ 1,
9
+ 106
10
+ ],
11
+ "image_token_index": 262144,
12
+ "initializer_range": 0.02,
13
+ "mm_tokens_per_image": 256,
14
+ "model_type": "gemma3",
15
+ "text_config": {
16
+ "attention_bias": false,
17
+ "attention_dropout": 0.0,
18
+ "attn_logit_softcapping": null,
19
+ "cache_implementation": "hybrid",
20
+ "final_logit_softcapping": null,
21
+ "head_dim": 32,
22
+ "hidden_activation": "gelu_pytorch_tanh",
23
+ "hidden_size": 32,
24
+ "initializer_range": 0.02,
25
+ "intermediate_size": 128,
26
+ "max_position_embeddings": 131072,
27
+ "model_type": "gemma3_text",
28
+ "num_attention_heads": 1,
29
+ "num_hidden_layers": 2,
30
+ "num_key_value_heads": 1,
31
+ "query_pre_attn_scalar": 168,
32
+ "rms_norm_eps": 1e-06,
33
+ "rope_local_base_freq": 10000.0,
34
+ "rope_scaling": {
35
+ "factor": 8.0,
36
+ "rope_type": "linear"
37
+ },
38
+ "rope_theta": 1000000.0,
39
+ "sliding_window": 1024,
40
+ "sliding_window_pattern": 2,
41
+ "use_cache": true,
42
+ "vocab_size": 262208
43
+ },
44
+ "torch_dtype": "bfloat16",
45
+ "transformers_version": "4.50.0.dev0",
46
+ "vision_config": {
47
+ "attention_dropout": 0.0,
48
+ "hidden_act": "gelu_pytorch_tanh",
49
+ "hidden_size": 32,
50
+ "image_size": 896,
51
+ "intermediate_size": 128,
52
+ "layer_norm_eps": 1e-06,
53
+ "model_type": "siglip_vision_model",
54
+ "num_attention_heads": 1,
55
+ "num_channels": 3,
56
+ "num_hidden_layers": 2,
57
+ "patch_size": 14,
58
+ "vision_use_head": false
59
+ }
60
+ }
generation_config.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 2,
4
+ "cache_implementation": "hybrid",
5
+ "eos_token_id": [
6
+ 1,
7
+ 106
8
+ ],
9
+ "pad_token_id": 0,
10
+ "transformers_version": "4.50.0.dev0"
11
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d7f723f4b5c9009b899a706e042acbfc686c3ef3db677b1909fa262263dde5f1
3
+ size 17209104
preprocessor_config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_convert_rgb": null,
3
+ "do_normalize": true,
4
+ "do_pan_and_scan": null,
5
+ "do_rescale": true,
6
+ "do_resize": true,
7
+ "image_mean": [
8
+ 0.5,
9
+ 0.5,
10
+ 0.5
11
+ ],
12
+ "image_processor_type": "Gemma3ImageProcessor",
13
+ "image_seq_length": 256,
14
+ "image_std": [
15
+ 0.5,
16
+ 0.5,
17
+ 0.5
18
+ ],
19
+ "pan_and_scan_max_num_crops": null,
20
+ "pan_and_scan_min_crop_size": null,
21
+ "pan_and_scan_min_ratio_to_activate": null,
22
+ "processor_class": "Gemma3Processor",
23
+ "resample": 2,
24
+ "rescale_factor": 0.00392156862745098,
25
+ "size": {
26
+ "height": 896,
27
+ "width": 896
28
+ }
29
+ }
processor_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "image_seq_length": 256,
3
+ "processor_class": "Gemma3Processor"
4
+ }
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": "<eos>",
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.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1299c11d7cf632ef3b4e11937501358ada021bbdf7c47638d13c0ee982f2e79c
3
+ size 4689074
tokenizer_config.json ADDED
The diff for this file is too large to render. See raw diff