shibatch commited on
Commit
0e3263a
·
verified ·
1 Parent(s): 996b8d7

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,14 @@ 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
+ tinygemma1m.BF16.gguf filter=lfs diff=lfs merge=lfs -text
37
+ tinygemma1m.F16.gguf filter=lfs diff=lfs merge=lfs -text
38
+ tinygemma1m.F32.gguf filter=lfs diff=lfs merge=lfs -text
39
+ tinygemma1m.Q2_K.gguf filter=lfs diff=lfs merge=lfs -text
40
+ tinygemma1m.Q3_K_M.gguf filter=lfs diff=lfs merge=lfs -text
41
+ tinygemma1m.Q4_0.gguf filter=lfs diff=lfs merge=lfs -text
42
+ tinygemma1m.Q4_1.gguf filter=lfs diff=lfs merge=lfs -text
43
+ tinygemma1m.Q4_K_M.gguf filter=lfs diff=lfs merge=lfs -text
44
+ tinygemma1m.Q5_K_M.gguf filter=lfs diff=lfs merge=lfs -text
45
+ tinygemma1m.Q6_K.gguf filter=lfs diff=lfs merge=lfs -text
46
+ tinygemma1m.Q8_0.gguf filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ base_model: google/gemma-2b
4
+ tags:
5
+ - gemma2
6
+ - gqa
7
+ - gguf
8
+ - safetensors
9
+ - transformers
10
+ - validation
11
+ - test-suite
12
+ ---
13
+
14
+ # TinyStories Gemma 2 1M GQA (tinygemma1m) GGUF & HF Validation Suite
15
+
16
+ This repository provides an ultra-lightweight Gemma 2 model variant featuring a **Custom BPE Tokenizer** combined with a strict **GQA (Grouped-Query Attention)** structural layout. It is trained on the TinyStories dataset and scaled down to a true **1M parameter frame** to act as a pinpoint validation testbed.
17
+
18
+ It is optimized specifically for debugging custom inference engines, and runtime tensor compilers against Gemma 2's advanced mathematical operators.
19
+
20
+ ---
21
+
22
+ ## 📊 Comparison: `tinygemma1m` vs Other 1M Variants
23
+
24
+ To track which runtime features are covered across the 1M parameter test suites, the architectural layout layout is structured below:
25
+
26
+ | Feature / Metric | `tiny1m` (Standard) | `tinybpe1m` (BPE Variant) | `tinymqa1m` (MQA Variant) | `tinygemma1m` (This Repository) |
27
+ | :--- | :--- | :--- | :--- | :--- |
28
+ | **Base Architecture** | Llama 2 | Llama 2 | Llama 2 | **Gemma 2** |
29
+ | **Attention Mechanism** | MHA (Multi-Head) | MHA (Multi-Head) | MQA (Multi-Query) | **GQA (Grouped-Query)** |
30
+ | **Attention Heads ($N_{heads} / N_{kv\_heads}$)** | 2 Heads / 2 KV | 2 Heads / 2 KV | 4 Heads / 1 KV | **2 Heads / 1 KV Head** (2:1 Ratio) |
31
+ | **Activation Function** | SwiGLU | SwiGLU | SwiGLU | **GeGLU** |
32
+ | **RMSNorm Placement** | Pre-layer norm only | Pre-layer norm only | Pre-layer norm only | **Pre- & Post-layer norm** (Double) |
33
+ | **Specialized Quirks** | None | None | None | **Embedding scaling ($\sqrt{d}$), Soft-Capping** |
34
+ | **Tokenizer Type** | Character-level | SentencePiece BPE | SentencePiece BPE | **SentencePiece BPE** |
35
+ | **Primary Debug Target** | Core matrix mult & layout | `byte_fallback` decode | KV-cache alignment | **Gemma 2 advanced execution graph** |
36
+
37
+ ### 💡 Why validate with `tinygemma1m`?
38
+ Compared to standard architectures like Llama 2, Gemma 2 introduces several compute graph complexities that are notorious breeding grounds for execution bugs. Elements such as **dual RMSNorm boundaries** (sandwiching both layer input and block output), **3-tensor GeGLU projections**, **Attention/Final Logit Soft-Capping**, and **GQA cache broadcasting** can be highly error-prone during clean-room engine development.
39
+
40
+ This model executes all of these complex kernels inside a lightweight 1M parameter footprint, making it effortless to isolate math errors without the memory overhead or sluggish processing speeds of full production weights.
41
+
42
+ ---
43
+
44
+ ## 📂 Repository Structure & File Descriptions
45
+
46
+ ### 1. GGUF Formats (Root Directory `./`)
47
+ A comprehensive binary suite built for `llama.cpp` and compatible runtime layers. To circumvent hardcoded string behaviors inside upstream parsers, these files have been explicitly binary-patched to restore text-mapping parameters and prefix logic correctly:
48
+
49
+ | Filename | Type | Size | Purpose / Validation Target |
50
+ | :--- | :--- | :--- | :--- |
51
+ | **`tinygemma1m.F32.gguf`** | `F32` | ~4.0 MB | **Baseline Test.** Validates raw Gemma 2 execution graph topology, matrix dimensions, and RoPE indexing without quantization artifacts noise. |
52
+ | **`tinygemma1m.F16.gguf`**<br>**`tinygemma1m.BF16.gguf`** | `F16`<br>`BF16` | ~2.0 MB | **Half-Precision Test.** Validates 16-bit float parsing, tensor execution boundaries, and compilation stability. |
53
+ | **`tinygemma1m.Q8_0.gguf`** | `Q8_0` | ~1.1 MB | **Uniform Quantization.** Validates block-based uniform scaling with 32 elements under Gemma 2 dimensions. |
54
+ | **`tinygemma1m.Q4_0.gguf`**<br>**`tinygemma1m.Q4_1.gguf`** | `Q4_0`<br>`Q4_1` | ~0.7 MB | **Classic Quantization.** Validates classic 4-bit linear quantization schemes and un-packing layouts. |
55
+ | **`tinygemma1m.Q2_K.gguf`** | `Q2_K` | ~0.5 MB | **Standard K-Quant (2-bit).** Validates extreme 2-bit super-block dequantization loops. |
56
+ | **`tinygemma1m.Q3_K_M.gguf`** | `Q3_K_M` | ~0.6 MB | **Standard K-Quant (3-bit).** Validates medium sub-variant of 3-bit multi-block structures. |
57
+ | **`tinygemma1m.Q4_K_M.gguf`** | `Q4_K_M` | ~0.7 MB | **Standard K-Quant (4-bit).** Validates medium sub-variant of modern 4-bit super-block structures. |
58
+ | **`tinygemma1m.Q5_K_M.gguf`** | `Q5_K_M` | ~0.8 MB | **Standard K-Quant (5-bit).** Validates medium sub-variant of mixed 5-bit precision layouts. |
59
+ | **`tinygemma1m.Q6_K.gguf`** | `Q6_K` | ~0.9 MB | **Standard K-Quant (6-bit).** Validates high-fidelity 6-bit super-block implementations. |
60
+
61
+ ### 2. Hugging Face Native Format (`./hf/`)
62
+ Standard unquantized layers and initialization variables targeted for the PyTorch `transformers` library ecosystem:
63
+ * **`hf/model.safetensors`**: Pure raw matrix parameters utilizing the unquantized Gemma 2 layer topology.
64
+ * **`hf/config.json`**: Structural settings modeling `Gemma2Config` properties (layer counts, specialized thresholds, head allocation ratios).
65
+ * **`hf/generation_config.json`**: Default sampling boundary defaults.
66
+ * **`hf/tokenizer.model`**: The custom 512-vocabulary size SentencePiece BPE master binary file.
67
+ * **`hf/tokenizer_config.json`**: Metadata linking `LlamaTokenizer` parameters to maintain clean sequence processing and handle automatic `<s>` (BOS) injection properly on the PyTorch backend.
68
+ * **`hf/special_tokens_map.json`**: Mappings linking token strings (`<s>`=1, `</s>`=2) back to internal index points.
69
+
70
+ ---
71
+
72
+ ## 🚀 Usage Examples
73
+
74
+ ### A. Running GGUF via llama.cpp
75
+ To verify your local hardware execution runtime or evaluate token generation patterns under Gemma 2 parameters:
76
+ ```bash
77
+ ./llama-cli -m tinygemma1m.Q4_K_M.gguf -p "Tom and Jerry are " -n 64 --temp 0.0
78
+
79
+ ```
80
+
81
+ ### B. Loading Hugging Face Formats via Python
82
+
83
+ Because runtime configurations are correctly aligned with the underlying vocabulary layouts, you can instantiate the components directly using the default automated class interfaces without manual wrapper logic.
84
+
85
+ ```python
86
+ import torch
87
+ from transformers import AutoTokenizer, AutoModelForCausalLM
88
+
89
+ repo_id = "shibatch/tinygemma1m"
90
+
91
+ print("Loading tokenizer and model configuration...")
92
+ tokenizer = AutoTokenizer.from_pretrained(repo_id, subfolder="hf")
93
+ model = AutoModelForCausalLM.from_pretrained(repo_id, subfolder="hf")
94
+
95
+ device = "cuda" if torch.cuda.is_available() else "cpu"
96
+ model = model.to(device)
97
+ model.eval()
98
+
99
+ prompt = "Tom and Jerry are "
100
+ # Text tokenization and automatic <s> (BOS) injection are managed via config metadata
101
+ inputs = tokenizer(prompt, return_tensors="pt").to(device)
102
+
103
+ print("Executing inference loop (Validating Gemma 2 projection tensors)...")
104
+ with torch.no_grad():
105
+ outputs = model.generate(
106
+ **inputs,
107
+ max_length=64,
108
+ do_sample=False
109
+ )
110
+
111
+ generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
112
+
113
+ print("\n--- Inference Test Result ---")
114
+ print("Prompt :", prompt)
115
+ print("Generated:", generated_text)
116
+
117
+ ```
118
+
119
+ ---
120
+
121
+ ## 📝 Model Specifications
122
+
123
+ * **Architecture:** Gemma 2 (`Gemma2ForCausalLM`)
124
+ * **Dataset:** TinyStories
125
+ * **Total Parameters:** ~1M
126
+ * **Vocabulary Size (`vocab_size`):** 512 (Custom SentencePiece BPE with `byte_fallback` enabled)
127
+ * **Hidden Size (`hidden_size`):** 128
128
+ * **Number of Hidden Layers (`num_hidden_layers`):** 3
129
+ * **Number of Attention Heads (`num_heads`):** 2 *(head_dim = 64)*
130
+ * **Number of Key-Value Heads (`num_kv_heads`):** 1 *(GQA Ratio = 2:1)*
131
+ * **Intermediate Size (`intermediate_size`):** 352
132
+ * **Max Position Embeddings (`max_position_embeddings`):** 256
133
+ * **Sliding Window Size:** 256
134
+ * **Logit Soft-Capping Thresholds:** Attention=50.0, Final=30.0
135
+
136
+ ## 📜 Acknowledgments & License
137
+
138
+ * **Original Implementation:** Heavily inspired by elements of the `llama2.c` project.
139
+ * **Dataset:** TinyStories dataset.
140
+ * **License:** **MIT License**. You are free to copy, modify, distribute, and utilize these assets for any commercial or educational goals.
hf/config.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Gemma2ForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "attn_logit_softcapping": 50.0,
8
+ "bos_token_id": 1,
9
+ "dtype": "float32",
10
+ "eos_token_id": 2,
11
+ "final_logit_softcapping": 30.0,
12
+ "head_dim": 64,
13
+ "hidden_activation": "gelu_pytorch_tanh",
14
+ "hidden_size": 128,
15
+ "initializer_range": 0.02,
16
+ "intermediate_size": 352,
17
+ "layer_types": [
18
+ "sliding_attention",
19
+ "full_attention",
20
+ "sliding_attention"
21
+ ],
22
+ "max_position_embeddings": 256,
23
+ "model_type": "gemma2",
24
+ "num_attention_heads": 2,
25
+ "num_hidden_layers": 3,
26
+ "num_key_value_heads": 1,
27
+ "pad_token_id": 2,
28
+ "query_pre_attn_scalar": 256,
29
+ "rms_norm_eps": 1e-06,
30
+ "rope_parameters": {
31
+ "rope_theta": 10000.0,
32
+ "rope_type": "default"
33
+ },
34
+ "sliding_window": 256,
35
+ "tie_word_embeddings": true,
36
+ "transformers_version": "5.9.0",
37
+ "use_bidirectional_attention": null,
38
+ "use_cache": false,
39
+ "vocab_size": 512
40
+ }
hf/generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": 2,
5
+ "output_attentions": false,
6
+ "output_hidden_states": false,
7
+ "pad_token_id": 2,
8
+ "transformers_version": "5.9.0",
9
+ "use_cache": true
10
+ }
hf/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5eadc47046d9135f86cc02616392bcbe85058b124281eb613d5643a3b13e6e15
3
+ size 2484392
hf/special_tokens_map.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "eos_token": "</s>",
4
+ "pad_token": "</s>",
5
+ "unk_token": "<unk>"
6
+ }
hf/tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5d6aadb6dda890bb21d23389f2b53f7f5053144dc5fd3209e6017401b124401d
3
+ size 247525
hf/tokenizer_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "bos_token": "<s>",
5
+ "eos_token": "</s>",
6
+ "model_max_length": 256,
7
+ "pad_token": "</s>",
8
+ "tokenizer_class": "LlamaTokenizer",
9
+ "unk_token": "<unk>"
10
+ }
tinygemma1m.BF16.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c69d2b077b69ba31e9c4d90c48d23e6c0f2ecc04dfef50d165d70ee9adf8b624
3
+ size 1257376
tinygemma1m.F16.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f7d99cad6049967114e189ec74ddad18000d2670e67ab10bc704df43ed015111
3
+ size 1257376
tinygemma1m.F32.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:42cf2dacf67dc439b7c32a6d46073a7c5baafaf4a6fa302991675d8c62bb43c5
3
+ size 2494368
tinygemma1m.Q2_K.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c98dd6dde702fa591c787c4754c517b85c2d7c8e519f20365ea3c3b62c47b809
3
+ size 401056
tinygemma1m.Q3_K_M.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:497f20816fe13ee9de63bfa75d721d1bf15b41bced09190b730370b26975e766
3
+ size 428192
tinygemma1m.Q4_0.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ed77db1085cf29a442c82f2393aa2cfc4b92d9f1f88aa3ce4b9dfc179fe9cb9
3
+ size 401056
tinygemma1m.Q4_1.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9708f10f4237b17acc35c9c8c1cf0cbc461af0003bd203977123b703dd425781
3
+ size 435616
tinygemma1m.Q4_K_M.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4cc96610424ce2e8aa6d97665f6f560bc79cedac6a6b740d47cf912d488d2606
3
+ size 490144
tinygemma1m.Q5_K_M.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e8a77a6dea3e8e1d887ece53ad502f6c936aa5964fc76a60b8f01d11794cb6ae
3
+ size 521376
tinygemma1m.Q6_K.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6fa99fdb5595bd1d6529730261391af1420f12f2974693aa35d7a38c2bcf2e36
3
+ size 677536
tinygemma1m.Q8_0.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5025e1c010f1b49bdb27ddfc5c27406cffc5d98f1608775ed36d3216f2ce9f74
3
+ size 677536