Skip to main content

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.

Metadata

Release files for nanbeige-mlx 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nanbeige-mlx 0.2.1
File Size Uploaded Provenance Actions
nanbeige_mlx-0.2.1.tar.gz 23.9 kB With provenance Details for nanbeige_mlx-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nanbeige-mlx 0.2.1
File Interpreter ABI Platform Actions
nanbeige_mlx-0.2.1-py3-none-any.whl Python 3 none any Details for nanbeige_mlx-0.2.1-py3-none-any.whl

Total release size: 46.9 kB

Release files / nanbeige_mlx-0.2.1.tar.gz

Download URL nanbeige_mlx-0.2.1.tar.gz
Size 23.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3a1e06057870c437cd299e21b4057734d6157cae4eff94dd282b9f6f3373c4dc
BLAKE2b-256 checksum
How to use checksums
db33f1b1e9c716745ee7554e89be297b520a38b3049644b1c7e8671d89af35ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 28, 2026.

Transparency log

Release files / nanbeige_mlx-0.2.1-py3-none-any.whl

Download URL nanbeige_mlx-0.2.1-py3-none-any.whl
Size 22.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e8bbe6561a1630765fe1c75bd5d59df73242e62cd499d484d6e6c1b02fe572ee
BLAKE2b-256 checksum
How to use checksums
3b502ff394f2d753d6ad0a2036d6f84c92a908b85fea4309eb5ef5d9925a076d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 28, 2026.

Transparency log

Security for nanbeige-mlx 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nanbeige_mlx-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page