CellGemma E4B (PLE-safe MLX 4-bit)

google/cellgemma-e4b converted to MLX 4-bit for Apple silicon. This is a quantized derivative of Google DeepMind's CellGemma E4B. The base model, and this conversion, are released under Apache 2.0. Keep the license terms of the base model when you use or redistribute this repo.

CellGemma is not a chat model. It takes a baseline cell (top 1,000 genes) plus a perturbation and writes a ranked residual gene list (+GENE / -GENE). Dataset-specific ExpressionDecoders in the base repo map that list to expression and log-fold change. Do not use it for clinical diagnosis, patient care, or medical decisions.

If you care about gene-list fidelity, prefer the 8-bit companion. In a greedy head-to-head against transformers bf16 on the official example prompts, 8-bit kept the top-10 K562 ranks exactly and stayed close on Tahoe. This 4-bit conversion is faster and smaller, but the ranked lists drift, and the K562 example never emitted a stop token (it ran to the 8,192 token cap and the tail started repeating genes).

Quantization

Converted from the official google/cellgemma-e4b weights with mlx-lm 0.32.2 (mlx / mlx-metal 0.32.4), on CPU, using a PLE-safe predicate:

  • Token embeddings (embed*) stay in bf16. nn.Embedding is not quantized.
  • Per-layer embedding (PLE) linears (per_layer_*) stay in bf16. Quantizing Gemma 4 PLE / ScaledLinear layers has produced garbage in some community conversions.
  • Layer norms stay in bf16.
  • Attention and MLP projections are 4-bit affine, group size 64.
  • router.proj is forced to 8-bit.

Average bits per weight of the saved model: 10.213 (PLE and embeddings dominate the file size). On-disk size: 9.23 GB.

This is not a community conversion of a third-party quant. The official Hugging Face weights were converted directly.

Usage

pip install mlx-lm==0.32.2
from mlx_lm import load
from mlx_lm.generate import stream_generate
from mlx_lm.sample_utils import make_sampler
from mlx_lm.tokenizer_utils import TokenizerWrapper

model, tokenizer = load("pratikgx/cellgemma-e4b-MLX-4bit")
if not isinstance(tokenizer, TokenizerWrapper):
    tokenizer = TokenizerWrapper(tokenizer)
tokenizer.add_eos_token("<turn|>")

# Official CellGemma wrap. Build `prompt` as in the base model card:
# preamble + perturbation + top-1,000 baseline genes + mean-shift list.
# https://huggingface.co/google/cellgemma-e4b
prompt = "<your cell + perturbation prompt>"
wrapped = f"<bos><|turn>user\n{prompt}<turn|>\n<|turn>model\n"

# The wrap already includes <bos>. Do not add special tokens again.
prompt_ids = tokenizer.encode(wrapped, add_special_tokens=False)

# Greedy. The official card also shows temperature 0.7 / do_sample=True.
pieces = []
for resp in stream_generate(
    model,
    tokenizer,
    prompt_ids,
    max_tokens=8192,
    sampler=make_sampler(temp=0.0),
):
    pieces.append(resp.text)
print("".join(pieces))

For a full virtual screen, pass the generated +GENE / -GENE list through the matching ExpressionDecoder from google/cellgemma-e4b (decoders/ in that repo).

Measured on a 64GB M5 Pro Mac mini

Greedy decoding, max_new_tokens=8192, official K562 MYC knockdown and Tahoe Panobinostat 0.5 uM prompts, median of 3 runs. Compared against a new greedy transformers bf16 baseline (not the official card's temperature 0.7 setup). A background app was running.

transformers bf16 this 4-bit MLX 8-bit MLX
Load 8.97 s 1.88 s 2.33 s
Memory 14.4 GB weights 9.19 GB at load, 10.8 GB peak MLX 11.00 GB at load, 12.7 GB peak MLX
Tahoe prefill / decode 2,138 tok/s, 19.0 tok/s 3,946 tok/s, 51.1 tok/s 3,999 tok/s, 37.7 tok/s
Tahoe time to first token / screen 1.93 s, 433 s (8,192 cap) 1.05 s, 162 s (8,192 cap) 1.06 s, 218 s (8,192 cap)
K562 prefill / decode 2,147 tok/s, 20.6 tok/s 3,614 tok/s, 44.4 tok/s 4,037 tok/s, 39.4 tok/s
K562 time to first token / screen 2.09 s, 83 s (1,668 tokens) 1.24 s, 186 s (8,192 cap, did not stop) 1.11 s, 51 s (1,971 tokens, stopped)

Outputs were deterministic across the 3 greedy runs.

Gene-list agreement versus greedy bf16

Direction often holds. Exact rank usually does not. This is not a drop-in replacement for bf16 lists.

Tahoe Panobinostat (both hit the 8,192 cap):

  • Top 10 overlap: 5/10 up (50%), 9/10 down (90%). Exact rank: 0/10 up, 2/10 down.
  • Top 50 overlap: 39/50 up (78%), 45/50 down (90%). Exact rank: 2/50 up, 2/50 down.
  • Sign agreement on 2,949 shared genes: 100%. Spearman 0.921 (signed ranks).
  • ExpressionDecoder LFC Pearson 0.78; sign agreement on both-nonzero genes 94.6%.
  • The head of the up list shuffles: bf16 leads with HSP90AA1, H1-0, H3-3B; 4-bit leads with ER-stress genes (HSP90B1, HSPA5, PDIA4, CALR) before those names appear.

K562 MYC knockdown (bf16 stopped at 1,668 tokens; 4-bit hit the 8,192 cap and did not emit a stop token):

  • Top 10 overlap: 6/10 up (60%), 3/10 down (30%). Exact rank: 0/10 and 0/10.
  • Top 50 overlap: 36/50 up (72%), 19/50 down (38%). Exact rank: 3/50 up, 1/50 down.
  • Sign agreement on 761 shared genes: 99.7%. Spearman 0.900.
  • LFC Pearson 0.29 (the much longer list changes what the decoder sees). Sign agreement on both-nonzero genes 95.4%.
  • The tail of the 4-bit K562 list starts repeating genes (for example DEFB131B 23 times). Top-k overlap above is computed on the ranked heads, so that tail does not inflate those percentages. Hematopoietic names such as GYPB, BLVRB, HBZ, ALAS2, SLC25A37 still appear near the top of the up list, but not in the same order.

Related

Converted and timed by Pratik Gandhi on 1 December 2026.

Downloads last month
3
Safetensors
Model size
8B params
Tensor type
BF16
ยท
U32
ยท
MLX
Hardware compatibility
Log In to add your hardware

4-bit

Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for pratikgx/cellgemma-e4b-MLX-4bit

Quantized
(8)
this model