nanbeige-mlx
An MLX port of the Nanbeige4.2-3B Looped Transformer for Apple Silicon,
plus the HF→MLX conversion and publishing helpers. The model definition in
nanbeige_mlx/model.py is the single source of truth
for the port — it is also copied verbatim into each converted weight directory
as the model_file mlx-lm loads.
This is an independent project; it is not affiliated with or endorsed by the Nanbeige team.
What's here
| module | purpose |
|---|---|
nanbeige_mlx/model.py |
the port — also the shipped model_file |
nanbeige_mlx/convert.py |
HF → MLX quant (non-mutating staging, tokenizer verify) |
nanbeige_mlx/upload.py |
model-card + LICENSE + NOTICE + (opt-in) HF upload |
nanbeige_mlx/pull.py |
pull("4bit") → local path for mlx_lm.load |
Load a published quant (one line)
from nanbeige_mlx import pull
import mlx_lm
model, tok = mlx_lm.load(pull("4bit"))
Convert from the BF16 checkpoint yourself
nanbeige-mlx-convert --src /path/to/Nanbeige4.2-3B --out ./nanbeige-mlx-4bit --bits 4
The source directory is never mutated; the tokenizer round-trip is asserted.
The 44-slot KV cache (a real cost of the looped design)
The looped architecture needs num_loops * num_hidden_layers = 44 KV slots.
At full context that is 44 × 8 KV-heads × 128 dim × 2 (K+V) × 262 144 positions
× 2 bytes ≈ 47 GB — unreachable on a 16 GB machine. Because this model
supplies make_cache, mlx-lm's --max-kv-size knob is inert; use --kv-bits
to reduce KV precision instead. This is a quantifiable cost of the looped
design, not a bug — see make_cache()'s docstring.
Dependencies
Upper-bounded to mlx>=0.32,<0.34 and mlx-lm>=0.31,<0.33. The bounds are
deliberate: model.py uses mlx_lm.models.base / .cache internals and is
copied verbatim into every published weight repo as the model_file, where it
is frozen — a user who already downloaded a quant cannot receive a patch.
Relaxing the bound is a decision to make after testing against a new mlx-lm.
Fidelity status
This port is validated by behaviour, not bit-parity: per-layer arithmetic
agrees with the reference's own NanbeigeDecoderLayer to fp32 precision, the
44-slot loop-aware KV cache passes a prefill-vs-incremental-decode equality
test, and the port's two code paths are bit-identical. End-to-end next-token
logit cosine against the HF reference is 0.847 (top-1 agreement 83%), lower
than a faithful port should give; six candidate causes have been eliminated by
measurement. The full record — including every falsified hypothesis — is in
the evaluation harness repo's
docs/investigation-log.md.
Behaviour on the bilingual agentic suite is unaffected (26–28/30 across
4/6/8-bit).
License
MIT for the code in this package. The Nanbeige model weights are governed by the upstream Apache-2.0 license; convert and redistribute them per that license.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nanbeige_mlx-0.2.1.tar.gz.
File metadata
- Download URL: nanbeige_mlx-0.2.1.tar.gz
- Upload date:
- Size: 23.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a1e06057870c437cd299e21b4057734d6157cae4eff94dd282b9f6f3373c4dc
|
|
| MD5 |
6b601eae0cba18cc4d16ec3b9aa1aa5c
|
|
| BLAKE2b-256 |
db33f1b1e9c716745ee7554e89be297b520a38b3049644b1c7e8671d89af35ee
|
Provenance
The following attestation bundles were made for nanbeige_mlx-0.2.1.tar.gz:
Publisher:
publish.yml on jishnuvenugopal/nanbeige-mlx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nanbeige_mlx-0.2.1.tar.gz -
Subject digest:
3a1e06057870c437cd299e21b4057734d6157cae4eff94dd282b9f6f3373c4dc - Sigstore transparency entry: 2269290306
- Sigstore integration time:
-
Permalink:
jishnuvenugopal/nanbeige-mlx@608a84ab84df0d14c8e431ceded883d847c6b746 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/jishnuvenugopal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@608a84ab84df0d14c8e431ceded883d847c6b746 -
Trigger Event:
push
-
Statement type:
File details
Details for the file nanbeige_mlx-0.2.1-py3-none-any.whl.
File metadata
- Download URL: nanbeige_mlx-0.2.1-py3-none-any.whl
- Upload date:
- Size: 22.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8bbe6561a1630765fe1c75bd5d59df73242e62cd499d484d6e6c1b02fe572ee
|
|
| MD5 |
0ffcf1ac4cc61e6080af523e5de424e0
|
|
| BLAKE2b-256 |
3b502ff394f2d753d6ad0a2036d6f84c92a908b85fea4309eb5ef5d9925a076d
|
Provenance
The following attestation bundles were made for nanbeige_mlx-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on jishnuvenugopal/nanbeige-mlx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nanbeige_mlx-0.2.1-py3-none-any.whl -
Subject digest:
e8bbe6561a1630765fe1c75bd5d59df73242e62cd499d484d6e6c1b02fe572ee - Sigstore transparency entry: 2269290539
- Sigstore integration time:
-
Permalink:
jishnuvenugopal/nanbeige-mlx@608a84ab84df0d14c8e431ceded883d847c6b746 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/jishnuvenugopal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@608a84ab84df0d14c8e431ceded883d847c6b746 -
Trigger Event:
push
-
Statement type: