mlboydaisuke commited on
Commit
4c1acb9
·
verified ·
1 Parent(s): aac1186

Replace broken int4 bundle with a working int8 build; rewrite card with measured numbers

Browse files

Thanks for adding a CodeGemma bundle to the community catalog — I ran it as part of a pass running every catalog bundle locally on a Mac.

The published int4 file generates repetitive word-salad on both backends ("sophistic sophistic ..." on CPU, ';" ;"' on GPU; litert-lm 0.15.0 and 0.16.0, file sha256-verified against the Hub). I tried to rebuild int4 from google/codegemma-7b-it and both attempts (channelwise and block-32, two toolchain versions) collapse the same way — this checkpoint doesn't survive data-free int4 PTQ. An int8 export does generate correctly, so this PR replaces the broken file with that build and rewrites the card to match what's inside: measured M4 Max numbers, the desktop-class size stated plainly, and a note on why int4 isn't offered. Generation was verified on CPU and GPU before benchmarking.

If you'd rather keep this repo int4-only or handle it differently, happy to adjust — the working file is the main thing.

README.md CHANGED
@@ -1,111 +1,64 @@
1
  ---
2
  license: gemma
3
  base_model: google/codegemma-7b-it
4
- library_name: litert
 
5
  tags:
6
  - litert
 
7
  - litertlm
8
  - codegemma
9
- - int4
10
- - android
11
  - on-device
12
  pipeline_tag: text-generation
13
  ---
14
 
15
- # CodeGemma 7B IT (INT4 LiteRT LM Model for Android)
16
 
17
- This repository contains Google's **CodeGemma 7B Instruction-Tuned (`google/codegemma-7b-it`)** quantized to **INT4** and exported into the **`.litertlm`** model bundle format for on-device deployment on Android using Google's **LiteRT** runtime (formerly TensorFlow Lite / AI Edge Torch).
 
 
18
 
19
- ---
20
-
21
- ## Model Summary
22
-
23
- - **Developed by**: Google DeepMind / Google AI Edge
24
- - **Model Architecture**: Gemma Transformer (`GemmaForCausalLM`)
25
- - **Base Checkpoint**: [`google/codegemma-7b-it`](https://huggingface.co/google/codegemma-7b-it)
26
- - **Quantization**: INT4 Weight-Only Dynamic Quantization (`dynamic_wi4_afp32`)
27
- - **Export Tool**: `litert-torch` (`litert_torch.generative.export_hf`)
28
- - **Target Platform**: Android (ARM64-v8a / Qualcomm Snapdragon / MediaTek / Google Tensor)
29
- - **Output File Format**: `.litertlm` (Unified model flatbuffer + tokenizer + prompt templates)
30
-
31
- ---
32
 
33
- ## Technical Specifications
 
34
 
35
- | Parameter | Value |
36
- |---|---|
37
- | **Parameters** | 7.0 Billion |
38
- | **Hidden Size** | 3072 |
39
- | **Num Layers** | 28 |
40
- | **Num Heads** | 16 |
41
- | **Vocab Size** | 256,000 |
42
- | **Prefill Seq Len** | 256 |
43
- | **Max KV Cache Len** | 512 |
44
- | **Quantization** | INT4 (`dynamic_wi4_afp32`) |
45
- | **File Size** | ~3.85 GB |
46
 
47
- ---
48
-
49
- ## On-Device Android Integration (LiteRT-LM SDK)
50
-
51
- ### 1. Model Deployment
52
- Place the downloaded `.litertlm` file inside your Android app's `assets/` directory or internal storage directory.
53
 
54
- ### 2. Dependencies (`build.gradle.kts`)
55
- ```kotlin
56
- dependencies {
57
- implementation("com.google.ai.edge.litert:litert-lm:1.0.0")
58
- }
59
  ```
60
 
61
- ### 3. Execution Code (Kotlin)
62
- ```kotlin
63
- import com.google.ai.edge.litert.lm.LiteRtLmEngine
64
- import com.google.ai.edge.litert.lm.ModelOptions
65
- import java.io.File
66
 
67
- fun runCodeGemma(context: Context, userPrompt: String): String {
68
- val modelFile = File(context.filesDir, "codegemma-7b-it-int4.litertlm")
69
-
70
- val options = ModelOptions.builder()
71
- .setModelPath(modelFile.absolutePath)
72
- .build()
73
 
74
- val engine = LiteRtLmEngine.create(options)
75
-
76
- // CodeGemma instruction format is automatically handled by the .litertlm bundle metadata
77
- val response = engine.generate(userPrompt)
78
-
79
- engine.close()
80
- return response
81
- }
82
- ```
83
 
84
- ---
 
 
 
85
 
86
- ## Prompt Template Format
 
87
 
88
- The `.litertlm` bundle automatically packages the official CodeGemma chat template:
89
 
90
- ```text
91
- <bos><start_of_turn>user
92
- Write a Kotlin function to check prime numbers.<end_of_turn>
93
- <start_of_turn>model
94
- ```
95
-
96
- ---
97
-
98
- ## Citation & Attribution
99
-
100
- If you use this model in your research or applications, please cite the official Google CodeGemma paper and Hugging Face repository:
101
-
102
- ```bibtex
103
- @article{codegemma2024,
104
- title={CodeGemma: Open Code Models},
105
- author={Google CodeGemma Team},
106
- year={2024}
107
- }
108
- ```
109
-
110
- ---
111
- *Converted using Google LiteRT Torch (`litert-torch`).*
 
1
  ---
2
  license: gemma
3
  base_model: google/codegemma-7b-it
4
+ base_model_relation: quantized
5
+ library_name: litert-lm
6
  tags:
7
  - litert
8
+ - litert-lm
9
  - litertlm
10
  - codegemma
 
 
11
  - on-device
12
  pipeline_tag: text-generation
13
  ---
14
 
15
+ # CodeGemma 7B IT (LiteRT-LM)
16
 
17
+ [google/codegemma-7b-it](https://huggingface.co/google/codegemma-7b-it) in the
18
+ LiteRT-LM `.litertlm` format for local inference with
19
+ [LiteRT-LM](https://github.com/google-ai-edge/LiteRT-LM).
20
 
21
+ | File | Quantization | Size | Notes |
22
+ |---|---|---:|---|
23
+ | `codegemma-7b-it-int8.litertlm` | dynamic int8 (weights int8, activations fp32) | 8.6 GB | KV cache 4096 tokens |
 
 
 
 
 
 
 
 
 
 
24
 
25
+ This is a desktop-class file: at 8.6 GB it needs a machine with ample RAM
26
+ (tested on Apple silicon); it does not fit 8 GB-RAM phones.
27
 
28
+ **Why int8 and not int4:** codegemma-7b-it collapses under data-free int4
29
+ post-training quantization — int4 builds (channelwise and block-32, two
30
+ different toolchain versions) all produce repetitive word-salad on every
31
+ backend. The int8 build generates correctly. If you need this model smaller,
32
+ it will take a calibration-based method, not a recipe change.
 
 
 
 
 
 
33
 
34
+ ## Usage
 
 
 
 
 
35
 
36
+ ```bash
37
+ pip install litert-lm
38
+ litert-lm run codegemma-7b-it-int8.litertlm \
39
+ --prompt "Write a Python function that returns the square of a number."
 
40
  ```
41
 
42
+ The bundle embeds CodeGemma's chat template (`<start_of_turn>user … <end_of_turn>`),
43
+ so plain prompts work; no manual formatting needed.
 
 
 
44
 
45
+ ## Performance (Apple M4 Max, measured)
 
 
 
 
 
46
 
47
+ Measured with the LiteRT-LM CLI: `litert-lm benchmark -p 256 -d 256 --runs 3
48
+ --cache no` (litert-lm 0.15.0) on an idle Apple M4 Max (macOS); 256 prefill /
49
+ 256 decode tokens, 3 iterations averaged by the tool.
 
 
 
 
 
 
50
 
51
+ | Backend | Prefill (tokens/s) | Decode (tokens/s) | Time-to-first-token (s) |
52
+ |---|---|---|---|
53
+ | CPU | 239.1 | 9.1 | 1.18 |
54
+ | GPU | 455.7 | 29.7 | 0.60 |
55
 
56
+ Generation was verified on both backends before quoting numbers (a coding
57
+ prompt returns a correct, well-formed function).
58
 
59
+ ## Conversion
60
 
61
+ Exported with [litert-torch](https://github.com/google-ai-edge/litert-torch)
62
+ 0.9.3 (`python -m litert_torch.generative.export_hf`, `--cache_length 4096`;
63
+ weights come out as dynamic int8 with fp32 activations) from the original
64
+ safetensors checkpoint (sha256-verified download).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
codegemma-7b-it-int4-litertlm.litertlm → codegemma-7b-it-int8.litertlm RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:895b4ef975512d67d3a9160305f1e9d7525bf87bbfa01ec33225325b35983f5b
3
- size 4724446544
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d17210866e31d9444179ed13de8c4f2a49655c62c4aaa36e8f2dba672f0b969c
3
+ size 8596756992