Inkling-2-Mini-Half / README.md
Sadanie's picture
Inkling 2 Mini MS-MoE
192c38d
|
Raw History Blame Contribute Delete
4.7 kB
metadata
license: apache-2.0
base_model: thinkingmachines/Inkling-2-Mini
base_model_relation: adapter
library_name: mlx
pipeline_tag: text-generation
language: en
tags:
  - mlx
  - apple-silicon
  - mixture-of-experts
  - inkling
  - lora
  - memory-sparse-moe

Inkling 2 Mini MS-MoE: half of the experts in memory

Inkling 2 Mini is 17.3 GB at 4-bit, so it doesn't fit on a 16 GB Mac. With the files in this repository it runs in about 9 GB at about 10 tokens per second on an M1, and scores within 2.5 points of the full model on code, math and knowledge tests.

A mixture-of-experts model is compute-efficient: each token only runs through a few experts (8 of 128 per layer here), not through the whole network. It is not memory-efficient, because all 128 are still held in memory. That isn't necessary: an answer mostly uses a subset of the experts, and fine-tuning makes the model work even better with only that subset.

Memory-Sparse MoE (MS-MoE) is the approach used here: keep only the experts a question needs in memory. A small prediction model (the receptionist) reads the question first and picks 64 experts per layer. Only those are loaded. The router and a small attention adapter are fine-tuned so the model works with that team. The experts themselves are unchanged.

Full write-up: Mixture-of-experts models are built wrong for laptops and local hardware

Results

Inkling 2 Mini with half of the experts in memory (64 of 128 per layer), greedy decoding, thinking effort 0.

Test Full model Ours, no fine-tuning MS-MoE (ours)
Code, MBPP (257 problems) 91.4% 73.2% 89.1%
Math, GSM8K (1,319 problems) 95.4% 92.6% 95.3%
Knowledge, MMLU (3,000 questions) 78.0% 75.4% 76.0%

On a 16 GB M1 MacBook: 9.0 GB peak memory, about 10 tokens per second, about 20 seconds to load the experts for the first question.

Usage

You need an Apple Silicon Mac with 16 GB of memory and about 20 GB of free disk space.

pip install "mlx==0.32.4" "mlx-lm @ git+https://github.com/ml-explore/mlx-lm.git@0c4c99192230f1943dd468d297f0b8a64ae7b7c2" transformers safetensors numpy huggingface_hub
hf download Sadanie/Inkling-2-Mini-Half --local-dir inkling-half
cd inkling-half
python run.py "Write a Python function that checks if a word is a palindrome."
python run.py --chat

The 4-bit base model (mlx-community/Inkling-2-Mini-4bit, 17 GB) is downloaded on first use. If you already have it, set INKLING_DIR=/path/to/Inkling-2-Mini-4bit. The pinned mlx-lm commit is the one that adds Inkling support.

python run.py --check compares the experts picked on your Mac with reference picks. It should report about 99%.

Close other heavy apps first. The script checks free memory and warns you if there isn't enough.

Files

  • run.py: the program. It picks the experts, loads only those, and answers.
  • receptionist.safetensors: the prediction model that picks the experts. A small network on top of Qwen3-Embedding-0.6B and Inkling's own token embeddings.
  • router.safetensors: fine-tuned router weights for all 24 layers.
  • attention_lora.safetensors: fine-tuned LoRA (rank 16) on the attention projections.
  • expert_prior.npy, meta.json: tie-breaks and settings for the receptionist, plus the reference picks for --check.
  • embed_f16.npy: Inkling 2 Mini's token embedding table in fp16, used by the receptionist (0.9 GB, unchanged from the original model).

How MS-MoE was applied to Inkling

  • The full model answered 18,271 questions (code, math, science, general chat, several languages), and we recorded which experts each answer used.
  • The receptionist was trained to predict that from the question alone. Its 64 picks per layer cover about 90% of the expert use of an answer.
  • The router and the attention LoRA were then fine-tuned for two epochs with the team restricted to the receptionist's picks, using the full model's outputs as the target. The expert weights were frozen.

In chat, each new message gets its own picks, mixed half and half with the picks so far, so only a few experts are swapped between messages.

Limits

  • Mac only for now (MLX).

Credits

Inkling 2 Mini is made by Thinking Machines and released under Apache 2.0. The 4-bit MLX conversion is from mlx-community. This repository adds files on top of that model and does not change its expert weights.