File size: 2,211 Bytes
fe57af1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
license: apache-2.0
language:
- en
- zh
library_name: mlx
pipeline_tag: text-generation
tags:
- llm
- nanbeige
- mlx
base_model: Nanbeige/Nanbeige4.2-3B
---

# harshit2312/Nanbeige4.2-3B-mlx-8bit

This is an **8-bit MLX** conversion of [Nanbeige/Nanbeige4.2-3B](https://huggingface.co/Nanbeige/Nanbeige4.2-3B),
for running on Apple Silicon. Converted from the official weights with
[mlx-lm](https://github.com/ml-explore/mlx-lm) **0.31.3** (8-bit, group size 64).

## ⚠️ Requires a custom architecture module

Nanbeige4.2 is a **looped / recurrent-depth transformer** (`num_loops: 2` — the decoder
stack is executed twice, each pass with its own KV cache). Stock `mlx-lm` does **not**
ship a `nanbeige` architecture, so loading this repo directly will fail with
`Model type nanbeige not supported`. Install the bundled `nanbeige.py` into your mlx-lm first:

```python
import os, shutil, mlx_lm
from huggingface_hub import hf_hub_download

src = hf_hub_download("harshit2312/Nanbeige4.2-3B-mlx-8bit", "nanbeige.py")
dst = os.path.join(os.path.dirname(mlx_lm.__file__), "models", "nanbeige.py")
shutil.copy(src, dst)
print("installed nanbeige architecture ->", dst)
```

## Use with mlx

```bash
pip install mlx-lm
```

```python
from mlx_lm import load, generate

model, tokenizer = load("harshit2312/Nanbeige4.2-3B-mlx-8bit")

messages = [{"role": "user", "content": "What is unified memory on Apple Silicon?"}]
prompt = tokenizer.apply_chat_template(messages, add_generation_prompt=True)

response = generate(model, tokenizer, prompt=prompt, verbose=True, max_tokens=512)
```

> Note: Nanbeige4.2-3B is a **reasoning model** — its chat template opens the assistant
> turn with a `<think>` block, so responses begin with visible chain-of-thought.

## Verification

The MLX architecture port was validated against the official HuggingFace implementation
(fp32, eager attention): **40/40 greedy tokens matched**, with the MLX token being the
reference's argmax at every position.

## Conversion details

| | |
|---|---|
| Precision | 8-bit affine, group size 64 (~8.5 bits/weight) |
| Size | ~4.2 GB |
| Architecture | Llama-style (GQA 48/8 heads, head_dim 128, SwiGLU, RoPE θ=70M) + `num_loops=2` |