shibatch commited on
Commit
554dc63
·
verified ·
1 Parent(s): 7aab2f4

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -5,6 +5,7 @@
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
 
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
+ *.gguf filter=lfs diff=lfs merge=lfs -text
9
  *.h5 filter=lfs diff=lfs merge=lfs -text
10
  *.joblib filter=lfs diff=lfs merge=lfs -text
11
  *.lfs.* filter=lfs diff=lfs merge=lfs -text
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Naoki Shibata
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md CHANGED
@@ -1,108 +1,210 @@
1
  ---
 
 
 
 
2
  license: mit
 
 
3
  tags:
4
  - gemma3
5
  - safetensors
6
  - transformers
 
 
7
  - tinygemma
8
  - tinystories
9
  - validation
10
  - test-suite
11
  ---
12
 
13
- # TinyStories Gemma3 Text Validation Artifact
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
- This directory contains a tiny Gemma 3 text-only model trained with official
16
- Hugging Face Transformers classes.
 
 
 
 
 
 
 
 
 
 
17
 
18
- It is intended for inference-engine validation, not for production language
19
- quality.
20
 
21
- ## Official classes used
 
 
 
22
 
23
- - `Gemma3TextConfig`
24
- - `Gemma3ForCausalLM`
25
- - `Trainer`
26
 
27
- No custom Gemma 3 modeling code is used.
 
 
 
28
 
29
- ## Key validation targets
 
 
 
 
 
 
30
 
31
- - `model_type = gemma3_text`
32
- - `architectures = Gemma3ForCausalLM`
33
- - local/global attention pattern through `layer_types`
34
- - sliding-window attention
35
- - full attention
36
- - GQA
37
- - per-head `q_norm` / `k_norm`
38
- - Gemma3 four-norm decoder layer structure
39
- - gated MLP: `silu(gate_proj(x)) * up_proj(x)`
40
- - tied output head through `model.embed_tokens.weight`
41
 
42
- ## Tiny architecture
43
 
44
- - vocab_size: 1024
45
- - hidden_size: 128
46
- - intermediate_size: 512
47
- - num_hidden_layers: 6
48
- - num_attention_heads: 4
49
- - num_key_value_heads: 1
50
- - head_dim: 32
51
- - sliding_window: 32
52
- - layer_types: ['sliding_attention', 'sliding_attention', 'sliding_attention', 'sliding_attention', 'sliding_attention', 'full_attention']
53
 
54
- ## Files
 
 
55
 
56
- - `hf/`: Hugging Face model/tokenizer artifact
57
- - `reference/reference.pt`: deterministic reference tensors
58
- - `reference/reference.json`: JSON summary of reference logits
59
- - `gemma3_text_config_dump.json`: normalized config dump
60
- - `safetensors_keys.json`: tensor names and shapes
61
- - `artifact_metadata.json`: generation metadata
62
 
63
- ## Usage
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  ```python
 
 
66
  import torch
67
  from transformers import Gemma3ForCausalLM, PreTrainedTokenizerFast
68
 
69
- def main():
70
- repo_id = "shibatch/tinygemma3-2m"
71
-
72
- print("Loading tokenizer...")
73
- tokenizer = PreTrainedTokenizerFast.from_pretrained(repo_id, subfolder="hf")
74
-
75
- print("Loading Gemma3 model weights...")
76
- device = "cuda" if torch.cuda.is_available() else "cpu"
77
-
78
- model = Gemma3ForCausalLM.from_pretrained(
79
- repo_id,
80
- subfolder="hf",
81
- torch_dtype=torch.bfloat16 if device == "cuda" else torch.float32,
82
- ).to(device)
83
- model.eval()
84
-
85
- prompt = "Once upon"
86
- print(f"\nInput prompt: {prompt}")
87
-
88
- input_ids = tokenizer.encode(prompt, add_special_tokens=False)
89
- input_ids = [tokenizer.bos_token_id] + input_ids
90
- input_ids = torch.tensor([input_ids], dtype=torch.long, device=device)
91
-
92
- with torch.no_grad():
93
- outputs = model.generate(
94
- input_ids,
95
- max_new_tokens=100,
96
- do_sample=False,
97
- repetition_penalty=1.0,
98
- top_p=1.0,
99
- pad_token_id=tokenizer.pad_token_id or tokenizer.bos_token_id,
100
- eos_token_id=tokenizer.eos_token_id,
101
- )
102
-
103
- generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
104
- print(f"Generated output: {generated_text}")
105
-
106
- if __name__ == "__main__":
107
- main()
108
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ library_name: transformers
3
+ pipeline_tag: text-generation
4
+ language:
5
+ - en
6
  license: mit
7
+ datasets:
8
+ - roneneldan/TinyStories
9
  tags:
10
  - gemma3
11
  - safetensors
12
  - transformers
13
+ - gguf
14
+ - q4-k-m
15
  - tinygemma
16
  - tinystories
17
  - validation
18
  - test-suite
19
  ---
20
 
21
+ # TinyStories Gemma3 2M (HF + Q4_K_M GGUF)
22
+
23
+ This repository contains a tiny Gemma 3 text-only model trained with official
24
+ Hugging Face Transformers classes, together with a llama.cpp-compatible
25
+ Q4_K_M GGUF conversion.
26
+
27
+ The model has 1,560,064 parameters (the `2m` name is an approximate size
28
+ label). It is intended for inference-engine validation and small-model
29
+ experiments, not for production language quality.
30
+
31
+ The Hugging Face artifact was downloaded from
32
+ [`shibatch/tinygemma3-2m`](https://huggingface.co/shibatch/tinygemma3-2m) at
33
+ revision `7aab2f4e525707e046799eb5674f344dc74853d6`.
34
+
35
+ ## Repository contents
36
+
37
+ - `hf/`: original Hugging Face model and tokenizer
38
+ - `gguf/tinygemma3-2m-Q4_K_M.gguf`: ready-to-run Q4_K_M GGUF
39
+ - `convert_to_gguf.py`: reproducible HF -> F16 -> Q4_K_M conversion wrapper
40
+ - `conversion_metadata.json`: source revisions, quantization details, and
41
+ validation result
42
+ - `reference/`: original deterministic Hugging Face reference tensors
43
+ - `gemma3_text_config_dump.json`: normalized configuration dump
44
+ - `safetensors_keys.json`: source tensor names and shapes
45
+ - `artifact_metadata.json`: original training metadata
46
+ - `SHA256SUMS`: checksums for the distributed binary artifacts
47
+
48
+ ## GGUF quick start
49
+
50
+ Install a recent llama.cpp build that supports Gemma 3. On Debian systems with
51
+ the llama.cpp tools package installed, run:
52
+
53
+ ```bash
54
+ llama-completion \
55
+ -m gguf/tinygemma3-2m-Q4_K_M.gguf \
56
+ -p "Once upon" \
57
+ -n 100 \
58
+ --temp 0.8 \
59
+ --top-p 0.95 \
60
+ --seed 1234
61
+ ```
62
 
63
+ The GGUF was load- and generation-tested with Debian llama.cpp build 8681.
64
+ For a deterministic smoke test:
65
+
66
+ ```bash
67
+ llama-completion \
68
+ -m gguf/tinygemma3-2m-Q4_K_M.gguf \
69
+ -p "Once upon" \
70
+ -n 40 \
71
+ --temp 0 \
72
+ --seed 1234 \
73
+ --no-display-prompt
74
+ ```
75
 
76
+ One validated completion was:
 
77
 
78
+ ```text
79
+ a time, there was a little girl named Lily. She loved to play with her toys
80
+ and her favorite thing to do was to go to the park. One day, Lily's
81
+ ```
82
 
83
+ ## Q4_K_M details
 
 
84
 
85
+ The distributed GGUF reports `general.file_type = 15` (Q4_K_M) and contains
86
+ 80 tensors. Because this deliberately tiny architecture has a hidden width of
87
+ 128 while K-quants use 256-value blocks, llama.cpp applies its normal Q4_K_M
88
+ fallback rules to tensors that cannot use Q4_K directly:
89
 
90
+ | Tensor type | Count |
91
+ | --- | ---: |
92
+ | F32 | 37 |
93
+ | Q5_0 | 34 |
94
+ | Q4_K | 4 |
95
+ | Q8_0 | 3 |
96
+ | Q6_K | 2 |
97
 
98
+ This mixed tensor layout is the expected llama.cpp representation of the
99
+ Q4_K_M preset for this model shape. The file is about 1.1 MB, compared with
100
+ about 3.1 MB for the intermediate F16 GGUF.
 
 
 
 
 
 
 
101
 
102
+ ## Reproduce the GGUF
103
 
104
+ Requirements:
 
 
 
 
 
 
 
 
105
 
106
+ - a recent llama.cpp source checkout containing `convert_hf_to_gguf.py`
107
+ - `llama-quantize` on `PATH`, or its path passed explicitly
108
+ - the Python packages required by llama.cpp's converter
109
 
110
+ Run from this repository:
 
 
 
 
 
111
 
112
+ ```bash
113
+ python convert_to_gguf.py \
114
+ --llama-cpp /path/to/llama.cpp \
115
+ --quantizer /path/to/llama-quantize
116
+ ```
117
+
118
+ The wrapper handles two properties of this validation checkpoint that generic
119
+ conversion currently does not infer correctly:
120
+
121
+ 1. The custom tokenizer is a GPT-2-style ByteLevel BPE whose probe hash is not
122
+ in llama.cpp's generated pre-tokenizer table.
123
+ 2. The tokenizer has 1,003 entries, but the model intentionally pads its
124
+ embedding and logits vocabulary to 1,024 rows. Those rows must be retained
125
+ for Gemma 3 runtime shape checks and for compatibility with the reference
126
+ logits.
127
+
128
+ The script validates the tokenizer structure before applying the tokenizer
129
+ override. It creates the F16 intermediate inside `gguf/` and removes it after
130
+ Q4_K_M quantization, including when quantization fails.
131
+
132
+ ## Hugging Face usage
133
 
134
  ```python
135
+ from pathlib import Path
136
+
137
  import torch
138
  from transformers import Gemma3ForCausalLM, PreTrainedTokenizerFast
139
 
140
+ model_dir = Path("hf")
141
+ tokenizer = PreTrainedTokenizerFast.from_pretrained(model_dir)
142
+ model = Gemma3ForCausalLM.from_pretrained(
143
+ model_dir,
144
+ dtype=torch.float32,
145
+ ).eval()
146
+
147
+ prompt = "Once upon"
148
+ input_ids = torch.tensor(
149
+ [[tokenizer.bos_token_id] + tokenizer.encode(prompt, add_special_tokens=False)]
150
+ )
151
+
152
+ with torch.no_grad():
153
+ output = model.generate(
154
+ input_ids,
155
+ max_new_tokens=100,
156
+ do_sample=False,
157
+ pad_token_id=tokenizer.pad_token_id,
158
+ eos_token_id=tokenizer.eos_token_id,
159
+ )
160
+
161
+ print(tokenizer.decode(output[0], skip_special_tokens=True))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  ```
163
+
164
+ The same example is available as `example_generate.py`.
165
+
166
+ ## Official classes used
167
+
168
+ - `Gemma3TextConfig`
169
+ - `Gemma3ForCausalLM`
170
+ - `Trainer`
171
+
172
+ No custom Gemma 3 modeling code is used by the original HF artifact.
173
+
174
+ ## Architecture
175
+
176
+ ```yaml
177
+ model_type: gemma3_text
178
+ architecture: Gemma3ForCausalLM
179
+ parameter_count: 1,560,064
180
+ vocab_size: 1,024
181
+ tokenizer_entries: 1,003
182
+ hidden_size: 128
183
+ intermediate_size: 512
184
+ num_hidden_layers: 6
185
+ num_attention_heads: 4
186
+ num_key_value_heads: 1
187
+ head_dim: 32
188
+ max_position_embeddings: 256
189
+ sliding_window: 32
190
+ layer_types:
191
+ - sliding_attention
192
+ - sliding_attention
193
+ - sliding_attention
194
+ - sliding_attention
195
+ - sliding_attention
196
+ - full_attention
197
+ tie_word_embeddings: true
198
+ ```
199
+
200
+ The model exercises local/global attention, sliding-window attention, GQA,
201
+ per-head `q_norm` / `k_norm`, Gemma 3's four-norm decoder structure, a gated
202
+ MLP, and a tied output head.
203
+
204
+ ## Limitations
205
+
206
+ This is a synthetic tiny checkpoint. It is not an official Google model and
207
+ does not contain weights from an original Gemma checkpoint. It is not intended
208
+ for instruction following, chat, factual recall, safety-critical use, or
209
+ production deployment. Quantized output may differ from the float32 Hugging
210
+ Face checkpoint.
SHA256SUMS ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ 54e9a48a7d571b01e291f897ac03953b3aae3ab76acfd4d7e3d314f7efc47644 gguf/tinygemma3-2m-Q4_K_M.gguf
2
+ ed87076e1e52de8e315b1e9fe2a551385fcedaed6d11c9c1ac8264804914ac61 hf/model.safetensors
3
+ f21db7a5f75e39b8db16b83937d01fe6ef3e8c888a06fcfdc0aaca8bb0e242e2 reference/reference.pt
4
+
conversion_metadata.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "source": {
3
+ "repo_id": "shibatch/tinygemma3-2m",
4
+ "revision": "7aab2f4e525707e046799eb5674f344dc74853d6",
5
+ "downloaded_utc_date": "2026-08-13"
6
+ },
7
+ "conversion": {
8
+ "script": "convert_to_gguf.py",
9
+ "llama_cpp_source_id": "0b1bad14ff204627636aeb1de22ddcd5acb859d4",
10
+ "intermediate_type": "F16",
11
+ "quantizer": "llama.cpp 8681 (Debian)",
12
+ "requested_quantization": "Q4_K_M",
13
+ "general_file_type": 15,
14
+ "tensor_count": 80,
15
+ "tensor_type_counts": {
16
+ "F32": 37,
17
+ "Q5_0": 34,
18
+ "Q4_K": 4,
19
+ "Q8_0": 3,
20
+ "Q6_K": 2
21
+ },
22
+ "fallback_quantized_tensor_count": 36,
23
+ "tokenizer_pre": "gpt-2",
24
+ "tokenizer_probe_sha256": "a7cd49e25128643b1b7df2df3a699e60225476307c755f246cacfd441d533a7b",
25
+ "padded_vocab_rows_preserved": 1024
26
+ },
27
+ "output": {
28
+ "path": "gguf/tinygemma3-2m-Q4_K_M.gguf",
29
+ "size_bytes": 1153312,
30
+ "sha256": "54e9a48a7d571b01e291f897ac03953b3aae3ab76acfd4d7e3d314f7efc47644"
31
+ },
32
+ "validation": {
33
+ "runtime": "llama.cpp 8681 (Debian)",
34
+ "load_succeeded": true,
35
+ "generation_exit_code": 0,
36
+ "prompt": "Once upon",
37
+ "max_new_tokens": 40,
38
+ "temperature": 0.0,
39
+ "completion": " a time, there was a little girl named Lily. She loved to play with her toys and her favorite thing to do was to go to the park. One day, Lily's"
40
+ }
41
+ }
42
+
convert_to_gguf.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Convert this repository's Hugging Face checkpoint to Q4_K_M GGUF.
3
+
4
+ The tokenizer is a small custom ByteLevel BPE. Its behavior is GPT-2-style,
5
+ but its tokenizer probe hash is not yet present in llama.cpp's generated
6
+ pre-tokenizer lookup table. This wrapper validates the tokenizer structure
7
+ before supplying the corresponding ``gpt-2`` pre-tokenizer identifier.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import argparse
13
+ import json
14
+ import runpy
15
+ import shutil
16
+ import subprocess
17
+ import sys
18
+ from pathlib import Path
19
+
20
+
21
+ def parse_args() -> argparse.Namespace:
22
+ parser = argparse.ArgumentParser(description=__doc__)
23
+ parser.add_argument(
24
+ "--llama-cpp",
25
+ type=Path,
26
+ required=True,
27
+ help="Path to a llama.cpp checkout containing convert_hf_to_gguf.py",
28
+ )
29
+ quantizer = shutil.which("llama-quantize")
30
+ parser.add_argument(
31
+ "--quantizer",
32
+ type=Path,
33
+ default=Path(quantizer) if quantizer else None,
34
+ help="Path to llama-quantize (default: resolve it from PATH)",
35
+ )
36
+ parser.add_argument(
37
+ "--outfile",
38
+ type=Path,
39
+ default=Path("gguf/tinygemma3-2m-Q4_K_M.gguf"),
40
+ )
41
+ return parser.parse_args()
42
+
43
+
44
+ def is_expected_bytelevel_bpe(model_dir: Path) -> bool:
45
+ tokenizer = json.loads((model_dir / "tokenizer.json").read_text())
46
+ return (
47
+ tokenizer.get("normalizer") is None
48
+ and tokenizer.get("model", {}).get("type") == "BPE"
49
+ and tokenizer.get("model", {}).get("byte_fallback") is False
50
+ and tokenizer.get("pre_tokenizer")
51
+ == {
52
+ "type": "ByteLevel",
53
+ "add_prefix_space": False,
54
+ "trim_offsets": False,
55
+ "use_regex": True,
56
+ }
57
+ )
58
+
59
+
60
+ def main() -> None:
61
+ args = parse_args()
62
+ repo_dir = Path(__file__).resolve().parent
63
+ model_dir = repo_dir / "hf"
64
+ converter = args.llama_cpp.resolve() / "convert_hf_to_gguf.py"
65
+ quantizer = args.quantizer.resolve() if args.quantizer else None
66
+ outfile = args.outfile if args.outfile.is_absolute() else repo_dir / args.outfile
67
+ intermediate = outfile.parent / ".tinygemma3-2m-f16.intermediate.gguf"
68
+
69
+ if not converter.is_file():
70
+ raise SystemExit(f"llama.cpp converter not found: {converter}")
71
+ if quantizer is None or not quantizer.is_file():
72
+ raise SystemExit("llama-quantize not found; pass it with --quantizer")
73
+ if not is_expected_bytelevel_bpe(model_dir):
74
+ raise SystemExit("Unexpected tokenizer structure; refusing to guess GGUF metadata")
75
+
76
+ sys.path.insert(0, str(args.llama_cpp.resolve()))
77
+ from conversion import TextModel # noqa: PLC0415
78
+ from conversion.gemma import Gemma3Model # noqa: PLC0415
79
+
80
+ original = TextModel.get_vocab_base_pre
81
+
82
+ def get_vocab_base_pre(self: TextModel, tokenizer: object) -> str:
83
+ if Path(self.dir_model).resolve() == model_dir.resolve():
84
+ return "gpt-2"
85
+ return original(self, tokenizer)
86
+
87
+ def modify_tensors(
88
+ self: Gemma3Model, data_torch: object, name: str, bid: int | None
89
+ ) -> object:
90
+ # This checkpoint intentionally pads the embedding matrix and logits
91
+ # from 1,003 tokenizer entries to config.vocab_size=1,024. Keep those
92
+ # rows so the GGUF architecture and HF reference logits stay aligned.
93
+ f_shift = self.norm_shift(name)
94
+ if f_shift != 0.0:
95
+ data_torch = data_torch + f_shift
96
+ yield from super(Gemma3Model, self).modify_tensors(data_torch, name, bid)
97
+
98
+ TextModel.get_vocab_base_pre = get_vocab_base_pre
99
+ Gemma3Model.modify_tensors = modify_tensors
100
+ outfile.parent.mkdir(parents=True, exist_ok=True)
101
+ sys.argv = [
102
+ str(converter),
103
+ str(model_dir),
104
+ "--outfile",
105
+ str(intermediate),
106
+ "--outtype",
107
+ "f16",
108
+ "--model-name",
109
+ "tinygemma3-2m",
110
+ ]
111
+ try:
112
+ runpy.run_path(str(converter), run_name="__main__")
113
+ subprocess.run(
114
+ [str(quantizer), str(intermediate), str(outfile), "Q4_K_M"],
115
+ check=True,
116
+ )
117
+ finally:
118
+ intermediate.unlink(missing_ok=True)
119
+
120
+
121
+ if __name__ == "__main__":
122
+ main()
example_generate.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+
3
+ import torch
4
+ from transformers import Gemma3ForCausalLM, PreTrainedTokenizerFast
5
+
6
+
7
+ MODEL_DIR = Path(__file__).resolve().parent / "hf"
8
+ PROMPT = "Once upon"
9
+
10
+
11
+ def main() -> None:
12
+ tokenizer = PreTrainedTokenizerFast.from_pretrained(MODEL_DIR)
13
+ model = Gemma3ForCausalLM.from_pretrained(
14
+ MODEL_DIR,
15
+ dtype=torch.float32,
16
+ ).eval()
17
+
18
+ input_ids = torch.tensor(
19
+ [
20
+ [tokenizer.bos_token_id]
21
+ + tokenizer.encode(PROMPT, add_special_tokens=False)
22
+ ]
23
+ )
24
+
25
+ with torch.no_grad():
26
+ output = model.generate(
27
+ input_ids,
28
+ max_new_tokens=100,
29
+ do_sample=False,
30
+ pad_token_id=tokenizer.pad_token_id,
31
+ eos_token_id=tokenizer.eos_token_id,
32
+ )
33
+
34
+ print(tokenizer.decode(output[0], skip_special_tokens=True))
35
+
36
+
37
+ if __name__ == "__main__":
38
+ main()
39
+
gguf/tinygemma3-2m-Q4_K_M.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:54e9a48a7d571b01e291f897ac03953b3aae3ab76acfd4d7e3d314f7efc47644
3
+ size 1153312
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ torch>=2.6.0
2
+ transformers>=5.9.0
3
+ safetensors>=0.4.0
4
+