Instructions to use galinilin/cellgemma-e4b-MLX-8bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use galinilin/cellgemma-e4b-MLX-8bit 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("galinilin/cellgemma-e4b-MLX-8bit") 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 galinilin/cellgemma-e4b-MLX-8bit with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Generate some text mlx_lm.generate --model "galinilin/cellgemma-e4b-MLX-8bit" --prompt "Once upon a time"
- Atomic Chat
CellGemma E4B for MLX, 8-bit
CellGemma (Google DeepMind, Apache-2.0) for Apple Silicon with mlx-lm: weights in 8-bit (affine, groups of 64, embeddings included), 8.2 GB instead of 15.6 GB. The tokenizer is the original's, gene-symbol tokens included.
from mlx_lm import load, generate
model, tokenizer = load("galinilin/cellgemma-e4b-MLX-8bit")
prompt = f"<bos><|turn>user\n{cellgemma_prompt}<turn|>\n<|turn>model\n"
ids = tokenizer.encode(prompt, add_special_tokens=False)
print(generate(model, tokenizer, prompt=ids, max_tokens=1024)) # "+GENE -GENE ...", greedy by default
Build cellgemma_prompt exactly as in the original card and turn the
gene list into expression changes with its ExpressionDecoders. The original's sampling is temperature 0.7, top-k 64,
top-p 0.95 (mlx_lm.sample_utils.make_sampler). Converted with mlx-lm 0.32.2 (mlx 0.32.5).
What 8-bit costs
Measured on Linux (a Colab T4): the dequantized 8-bit weights in the transformers model, against the original bf16 weights, on 12 CellGemma prompts (6 CRISPR knockdowns in K562, 6 drugs in A549 from the Tahoe controls):
| 8-bit | 4-bit (not published) | |
|---|---|---|
| mean KL divergence per token (teacher-forced, 256 tokens per prompt) | 0.0025 | 0.17 |
| same top-1 token as bf16 | 92.8% | 68.7% |
| greedy 256-token outputs vs bf16: Pearson of the predicted residual expression change | 0.85 [0.77, 0.93] | 0.67 [0.55, 0.78] |
| same genes in the top 50 (Jaccard) | 0.87 | 0.55 |
For scale, two bf16 implementations (transformers and llama.cpp) agree on the top-1 token 92% of the time and reach a residual Pearson of 0.53 between their greedy outputs, because many steps are near-ties between genes. 8-bit stays within that; 4-bit changes the outputs noticeably, so it is not published.
mlx-lm itself was run on the CPU on a short prompt: its first 16 output tokens match the transformers model with the same 8-bit weights exactly. Speed on Apple Silicon was not measured (no Mac).
Intended use
As the original: research on predicting transcriptional responses to perturbations. Not for clinical diagnosis, patient care or medical decisions; predictions need laboratory validation.
Licence
Apache-2.0, as the original. Model by Google DeepMind. Changes: converted with mlx_lm.convert and quantized to
8 bits. Conversion and card by galinilin.
- Downloads last month
- -
8-bit