mlboydaisuke commited on
Commit
2f1a6ad
Β·
verified Β·
1 Parent(s): 41b1d06

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +93 -0
README.md ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: Nanbeige/Nanbeige4.1-3B
4
+ tags:
5
+ - litert
6
+ - litert-lm
7
+ - litertlm
8
+ - on-device
9
+ - edge
10
+ - reasoning
11
+ pipeline_tag: text-generation
12
+ library_name: litert-lm
13
+ ---
14
+
15
+ # Nanbeige4.1-3B β€” LiteRT-LM (blockwise int4)
16
+
17
+ [Nanbeige/Nanbeige4.1-3B](https://huggingface.co/Nanbeige/Nanbeige4.1-3B) converted to the
18
+ **LiteRT-LM** (`.litertlm`) format for on-device inference with Google's
19
+ [LiteRT-LM](https://github.com/google-ai-edge/litert-lm) runtime (the engine behind the
20
+ official `litert-community/*` models).
21
+
22
+ Nanbeige4.1-3B is a fresh (Dec 2025) **phone-size reasoning** model on a plain dense
23
+ Llama architecture (Apache-2.0), reported to be competitive with much larger models. It
24
+ works the problem inside a `<think>…</think>` block before giving the final answer.
25
+
26
+ | | |
27
+ |---|---|
28
+ | **File** | `model.litertlm` (~2.2 GB; embedding externalized so every section is <2 GiB β†’ loads on iOS) |
29
+ | **Quantization** | int4 weights β€” **blockwise (block 32) + OCTAV** optimal-clipping, symmetric; embedding INT8 |
30
+ | **Compute** | integer |
31
+ | **Context (KV cache)** | 4096 |
32
+ | **Base model** | Nanbeige/Nanbeige4.1-3B (Apache-2.0) |
33
+ | **Decode speed** | ~89 tok/s (Mac M4 Max, Metal GPU, greedy) |
34
+
35
+ ## Usage
36
+
37
+ ```bash
38
+ # build litert-lm from https://github.com/google-ai-edge/litert-lm, then:
39
+ litert_lm_main \
40
+ --model_path model.litertlm \
41
+ --backend gpu \
42
+ --input_prompt "A robe takes 2 bolts of blue fiber and half that much white fiber. How many bolts total?"
43
+ ```
44
+
45
+ The `.litertlm` bundle carries the tokenizer and the prompt template (ChatML β€”
46
+ `<|im_start|>role\n … <|im_end|>`), so no separate tokenizer files are needed. This is a
47
+ **reasoning** model: it emits a `<think>…</think>` chain then the final answer (best
48
+ evaluated with a generous token budget), and stops cleanly at `<|im_end|>`.
49
+
50
+ ## Run on Android
51
+
52
+ Install a recent [Google AI Edge Gallery](https://github.com/google-ai-edge/gallery)
53
+ (1.0.16+ can import `.litertlm` directly from Hugging Face), download `model.litertlm`
54
+ (or import this repo in-app), pick the **GPU** backend (CPU also works), and chat. Give it
55
+ a high max-tokens β€” it's a reasoning model with long chains of thought.
56
+
57
+ ## Quality β€” GSM8K
58
+
59
+ Measured on GSM8K (n=50, greedy, 0-shot chain-of-thought, **max-tokens 2048** β€” a
60
+ reasoning model needs the budget to finish; scoring it at 512 tokens falsely penalises it):
61
+
62
+ | Configuration | GSM8K |
63
+ |---|---|
64
+ | **This model β€” LiteRT int4 (block32 + OCTAV)** | **84.0%** |
65
+
66
+ 84% is a strong on-device GSM8K for a 3B, non-degenerate; the model also passes the local
67
+ quality gate **8/8** with a clean stop at `<|im_end|>`. Blockwise-32 + OCTAV optimal-clipping
68
+ (data-free) preserves the accuracy versus a naive min-max int4.
69
+
70
+ ## Conversion
71
+
72
+ Converted with [`litert-torch`](https://github.com/google-ai-edge/litert) using a
73
+ **blockwise int4** recipe (INT4 weights, block size 32, symmetric, OCTAV optimal-clipping)
74
+ with the embedding at INT8, KV cache 4096, and a ChatML prompt template. Nanbeige4.1 is a
75
+ standard dense `LlamaForCausalLM`, so it rides the existing converter and runtime with no
76
+ custom graph code.
77
+
78
+ **`externalize_embedder=True` (required for iPhone).** The large 166k-token vocab makes the
79
+ weights a >2 GiB single TFLite section, which exceeds the ~2 GiB single-section `mmap` limit
80
+ on iOS. Externalizing the embedding drops the main section under 2 GiB so the model loads on
81
+ **iPhone (Metal GPU)** as well as Android/desktop. Same weights, so GSM8K is unchanged.
82
+
83
+ **Added-tokens tokenizer fix.** Nanbeige's 10 special tokens (`<|im_start|>`, `<|im_end|>`,
84
+ `<think>`, `</think>`, `<tool_call>`, …) live at vocab ids 166100–166109, above the base
85
+ SentencePiece vocab (166100). The base SP conversion drops them, so the reasoning model would
86
+ generate `<think>` (id 166103) and the runtime would crash with *"Token id out of range."* The
87
+ converted tokenizer here appends those added tokens as USER_DEFINED SentencePiece pieces at
88
+ their exact ids (padded to the model vocab), so `<think>` and friends decode correctly.
89
+
90
+ ## License
91
+
92
+ Apache-2.0, inherited from the base model
93
+ [Nanbeige/Nanbeige4.1-3B](https://huggingface.co/Nanbeige/Nanbeige4.1-3B).