Instructions to use Sadanie/Inkling-2-Mini-Memory-Sparse-MoE with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use Sadanie/Inkling-2-Mini-Memory-Sparse-MoE with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # if on a CUDA device, also pip install mlx[cuda] # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("Sadanie/Inkling-2-Mini-Memory-Sparse-MoE") prompt = "Once upon a time in" text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- MLX LM
How to use Sadanie/Inkling-2-Mini-Memory-Sparse-MoE with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Generate some text mlx_lm.generate --model "Sadanie/Inkling-2-Mini-Memory-Sparse-MoE" --prompt "Once upon a time"
- Atomic Chat
|
Download README.md from Sadanie/Inkling-2-Mini-Memory-Sparse-MoE: direct link, hf CLI and curl.
- Browser
- Download file 4.7 kB
-
https://huggingface.co/Sadanie/Inkling-2-Mini-Memory-Sparse-MoE/resolve/main/README.md
- Command line
-
hf download hf://Sadanie/Inkling-2-Mini-Memory-Sparse-MoE/README.md
-
curl -L -o README.md https://huggingface.co/Sadanie/Inkling-2-Mini-Memory-Sparse-MoE/resolve/main/README.md
4.7 kB
| 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: 2x memory efficient | |
| 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](https://medium.com/@rotteveeladan/mixture-of-experts-models-are-built-wrong-for-laptops-and-local-hardware-9a45165d65d6) | |
| ## 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. | |
| ```bash | |
| 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-Memory-Sparse-MoE --local-dir inkling-ms-moe | |
| cd inkling-ms-moe | |
| 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](https://huggingface.co/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](https://huggingface.co/Qwen/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](https://huggingface.co/thinkingmachines/Inkling-2-Mini) 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. | |