IMvision12 commited on
Commit
2f8d1d2
·
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,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: any-to-any
3
+ license: apache-2.0
4
+ base_model: google/gemma-4-E4B-it
5
+ library_name: kerasformers
6
+ language:
7
+ - en
8
+ tags:
9
+ - keras
10
+ - kerasformers
11
+ - gemma4
12
+ - gemma-4
13
+ - any-to-any
14
+ - pytorch
15
+ - jax
16
+ - tf
17
+ ---
18
+
19
+ *See [our collection](https://huggingface.co/kerasformers) for all Gemma 4 sizes and variants.*
20
+
21
+ # Run Gemma 4 with Keras 3: JAX, PyTorch, or TensorFlow
22
+
23
+ [![GitHub](https://img.shields.io/badge/GitHub-KerasFormers-181717?logo=github)](https://github.com/IMvision12/KerasFormers) [![Docs](https://img.shields.io/badge/Docs-Gemma_4-1f6feb)](https://imvision12.github.io/KerasFormers/gemma4/) [![HuggingFace](https://img.shields.io/badge/HuggingFace-Gemma_4-ffd21e?logo=huggingface&logoColor=black)](https://huggingface.co/kerasformers)
24
+
25
+ # kerasformers/gemma-4-e4b-it
26
+
27
+ Pure-**Keras 3** conversion of [`google/gemma-4-E4B-it`](https://huggingface.co/google/gemma-4-E4B-it) for
28
+ [kerasformers](https://github.com/IMvision12/KerasFormers). One implementation runs unmodified on
29
+ **TensorFlow / Torch / JAX**. This is the **8B** variant, served here as
30
+ **image + audio + text -> text** via `Gemma4Processor`; weights are stored in **bfloat16**.
31
+
32
+ For model details, license, and usage terms, see Google's
33
+ [model card](https://huggingface.co/google/gemma-4-E4B-it).
34
+
35
+ ## Gemma 4 family
36
+
37
+ | Property | E2B | E4B | 12B Unified | 31B Dense |
38
+ | --- | --- | --- | --- | --- |
39
+ | Total Parameters | 2.3B effective (5.1B with embeddings) | 4.5B effective (8B with embeddings) | 11.95B | 30.7B |
40
+ | Layers | 35 | 42 | 48 | 60 |
41
+ | Sliding Window | 512 tokens | 512 tokens | 1024 tokens | 1024 tokens |
42
+ | Context Length | 128K tokens | 128K tokens | 256K tokens | 256K tokens |
43
+ | Vocabulary Size | 262K | 262K | 262K | 262K |
44
+ | Supported Modalities | Text, Image, Audio | Text, Image, Audio | Text, Image, Audio | Text, Image |
45
+ | Vision Encoder Parameters | ~150M | ~150M | - | ~550M |
46
+ | Audio Encoder Parameters | ~300M | ~300M | - | No Audio |
47
+
48
+ ## ✨ Quick start
49
+
50
+ ### Text-only
51
+
52
+ ```python
53
+ import os
54
+ os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
55
+
56
+ from kerasformers.models.gemma4 import Gemma4TextGenerate, Gemma4Tokenizer
57
+
58
+ model = Gemma4TextGenerate.from_weights("kerasformers/gemma-4-e4b-it")
59
+ tokenizer = Gemma4Tokenizer.from_weights("kerasformers/gemma-4-e4b-it")
60
+
61
+ inputs = tokenizer([{"role": "user", "content": "Hello, who are you?"}])
62
+ outputs = model.generate(**inputs, max_new_tokens=64)
63
+ print(tokenizer.decode(outputs[0]))
64
+ ```
65
+
66
+ ### Image + audio + text
67
+
68
+ ```python
69
+ import os
70
+ os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
71
+
72
+ from PIL import Image
73
+ from kerasformers.models.gemma4 import Gemma4ConditionalGenerate, Gemma4Processor
74
+
75
+ model = Gemma4ConditionalGenerate.from_weights("kerasformers/gemma-4-e4b-it")
76
+ processor = Gemma4Processor.from_weights("kerasformers/gemma-4-e4b-it")
77
+
78
+ inputs = processor(conversation=[
79
+ {"role": "user", "content": [
80
+ {"type": "image", "image": Image.open("cat.jpg")},
81
+ {"type": "audio", "path": "clip.wav"},
82
+ {"type": "text", "text": "Describe the image and what you hear."},
83
+ ]}
84
+ ])
85
+ outputs = model.generate(**inputs, max_new_tokens=64)
86
+ print(processor.decode(outputs[0]))
87
+ ```
88
+
89
+ Load any Gemma 4 variant the same way with `from_weights("kerasformers/<variant>")`:
90
+
91
+ | Variant | Hub |
92
+ | --- | --- |
93
+ | `gemma-4-12b` | [kerasformers/gemma-4-12b](https://huggingface.co/kerasformers/gemma-4-12b) |
94
+ | `gemma-4-12b-it` | [kerasformers/gemma-4-12b-it](https://huggingface.co/kerasformers/gemma-4-12b-it) |
95
+ | `gemma-4-26b-a4b` | [kerasformers/gemma-4-26b-a4b](https://huggingface.co/kerasformers/gemma-4-26b-a4b) |
96
+ | `gemma-4-26b-a4b-it` | [kerasformers/gemma-4-26b-a4b-it](https://huggingface.co/kerasformers/gemma-4-26b-a4b-it) |
97
+ | `gemma-4-31b` | [kerasformers/gemma-4-31b](https://huggingface.co/kerasformers/gemma-4-31b) |
98
+ | `gemma-4-31b-it` | [kerasformers/gemma-4-31b-it](https://huggingface.co/kerasformers/gemma-4-31b-it) |
99
+ | `gemma-4-e2b` | [kerasformers/gemma-4-e2b](https://huggingface.co/kerasformers/gemma-4-e2b) |
100
+ | `gemma-4-e2b-it` | [kerasformers/gemma-4-e2b-it](https://huggingface.co/kerasformers/gemma-4-e2b-it) |
101
+ | `gemma-4-e4b` | [kerasformers/gemma-4-e4b](https://huggingface.co/kerasformers/gemma-4-e4b) |
102
+ | `gemma-4-e4b-it` | [kerasformers/gemma-4-e4b-it](https://huggingface.co/kerasformers/gemma-4-e4b-it) |
103
+
104
+ ## Tips
105
+
106
+ - Set `KERAS_BACKEND` **before** importing Keras / kerasformers.
107
+ - Loads in **bfloat16** by default. Pass `load_dtype="float32"` for full precision,
108
+ or `quantization="int8"` to shrink further.
109
+ - See the [Gemma 4 docs](https://imvision12.github.io/KerasFormers/gemma4/).
110
+ - Community / upstream weights still work via the `hf:` prefix:
111
+ `Gemma4ConditionalGenerate.from_weights("hf:google/gemma-4-E4B-it")`.
112
+
113
+ ## Special Thanks
114
+
115
+ A huge thank you to the Google Gemma authors for creating and releasing these models.
116
+
117
+ License: Apache 2.0.
kf_config.json ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "library_name": "kerasformers",
3
+ "kerasformers_version": "1.2.1",
4
+ "model_module": "kerasformers.models.gemma4",
5
+ "model_class": "Gemma4ConditionalGenerate",
6
+ "variant": "gemma-4-e4b-it",
7
+ "weights": "model.weights.json",
8
+ "schema_version": 2,
9
+ "weight_dtype": "bfloat16",
10
+ "model_type": "gemma4",
11
+ "text_config": {
12
+ "vocab_size": 262144,
13
+ "embed_dim": 2560,
14
+ "mlp_dim": 10240,
15
+ "num_layers": 42,
16
+ "num_heads": 8,
17
+ "num_kv_heads": 2,
18
+ "num_global_kv_heads": 2,
19
+ "head_dim": 256,
20
+ "global_head_dim": 512,
21
+ "k_eq_v": false,
22
+ "enable_moe": false,
23
+ "num_experts": 0,
24
+ "num_experts_per_tok": 0,
25
+ "moe_mlp_dim": 0,
26
+ "sliding_window": 512,
27
+ "sliding_window_pattern": 6,
28
+ "layer_types": [
29
+ "sliding_attention",
30
+ "sliding_attention",
31
+ "sliding_attention",
32
+ "sliding_attention",
33
+ "sliding_attention",
34
+ "full_attention",
35
+ "sliding_attention",
36
+ "sliding_attention",
37
+ "sliding_attention",
38
+ "sliding_attention",
39
+ "sliding_attention",
40
+ "full_attention",
41
+ "sliding_attention",
42
+ "sliding_attention",
43
+ "sliding_attention",
44
+ "sliding_attention",
45
+ "sliding_attention",
46
+ "full_attention",
47
+ "sliding_attention",
48
+ "sliding_attention",
49
+ "sliding_attention",
50
+ "sliding_attention",
51
+ "sliding_attention",
52
+ "full_attention",
53
+ "sliding_attention",
54
+ "sliding_attention",
55
+ "sliding_attention",
56
+ "sliding_attention",
57
+ "sliding_attention",
58
+ "full_attention",
59
+ "sliding_attention",
60
+ "sliding_attention",
61
+ "sliding_attention",
62
+ "sliding_attention",
63
+ "sliding_attention",
64
+ "full_attention",
65
+ "sliding_attention",
66
+ "sliding_attention",
67
+ "sliding_attention",
68
+ "sliding_attention",
69
+ "sliding_attention",
70
+ "full_attention"
71
+ ],
72
+ "partial_rotary_factor": 0.25,
73
+ "final_logit_softcapping": 30.0,
74
+ "norm_eps": 1e-06,
75
+ "rope_theta": 1000000.0,
76
+ "rope_local_theta": 10000.0,
77
+ "tie_embeddings": true,
78
+ "hidden_size_per_layer_input": 256,
79
+ "vocab_size_per_layer_input": 262144,
80
+ "num_kv_shared_layers": 18,
81
+ "use_double_wide_mlp": false
82
+ },
83
+ "vision_config": {
84
+ "hidden_size": 768,
85
+ "num_layers": 16,
86
+ "num_heads": 12,
87
+ "num_kv_heads": 12,
88
+ "head_dim": 64,
89
+ "intermediate_size": 3072,
90
+ "patch_size": 16,
91
+ "position_embedding_size": 10240,
92
+ "pooling_kernel_size": 3,
93
+ "rope_theta": 100.0,
94
+ "eps": 1e-06,
95
+ "standardize": false,
96
+ "use_clipped_linears": true
97
+ },
98
+ "audio_config": {
99
+ "hidden_size": 1024,
100
+ "num_layers": 12,
101
+ "num_heads": 8,
102
+ "conv_channels": [
103
+ 128,
104
+ 32
105
+ ],
106
+ "conv_kernel_size": 5,
107
+ "chunk_size": 12,
108
+ "context_left": 13,
109
+ "context_right": 0,
110
+ "logit_cap": 50.0,
111
+ "invalid_logits": -1000000000.0,
112
+ "residual_weight": 0.5,
113
+ "norm_eps": 1e-06,
114
+ "output_proj_dims": 1536,
115
+ "use_clipped_linears": true
116
+ },
117
+ "image_token_id": 258880,
118
+ "video_token_id": 258884,
119
+ "audio_token_id": 258881,
120
+ "pad_token_id": 0,
121
+ "use_bidirectional_vision": false
122
+ }
kf_preprocessor.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "library_name": "kerasformers",
3
+ "kerasformers_version": "1.2.1",
4
+ "preprocessor_module": "kerasformers.models.gemma4",
5
+ "preprocessor_class": "Gemma4ImageProcessor",
6
+ "variant": "gemma-4-e4b-it",
7
+ "patch_size": 16,
8
+ "max_soft_tokens": 280,
9
+ "pooling_kernel_size": 3,
10
+ "rescale_factor": 0.00392156862745098,
11
+ "image_mean": [
12
+ 0.0,
13
+ 0.0,
14
+ 0.0
15
+ ],
16
+ "image_std": [
17
+ 1.0,
18
+ 1.0,
19
+ 1.0
20
+ ]
21
+ }
model.weights.json ADDED
The diff for this file is too large to render. See raw diff
 
model_00000.weights.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6b9e1879a1075238479835ad5b77668cd1d039f94a5ee16effeaed0c48121ad7
3
+ size 1971336616
model_00001.weights.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3599eaba15ec145f57067c1d06d1a9856b7f22fff9405f6c6ca5b3834928fa2d
3
+ size 5644517272
model_00002.weights.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:011a67e6ae475ff62a24f33604f0f9c5c6614ed78f41c19727565fda7fac09e7
3
+ size 5371902362
model_00003.weights.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d9292d2d0e11588653b9a6b433b39d7ebb4dbbe7d866a5d0e232c67cda7e72c5
3
+ size 2924887960
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cc8d3a0ce36466ccc1278bf987df5f71db1719b9ca6b4118264f45cb627bfe0f
3
+ size 32169626