Instructions to use tenzro/cellgemma-e4b-gguf with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use tenzro/cellgemma-e4b-gguf with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf tenzro/cellgemma-e4b-gguf:Q8_0 # Run inference directly in the terminal: llama cli -hf tenzro/cellgemma-e4b-gguf:Q8_0
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf tenzro/cellgemma-e4b-gguf:Q8_0 # Run inference directly in the terminal: llama cli -hf tenzro/cellgemma-e4b-gguf:Q8_0
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf tenzro/cellgemma-e4b-gguf:Q8_0 # Run inference directly in the terminal: ./build/bin/llama cli -hf tenzro/cellgemma-e4b-gguf:Q8_0
Use Docker
docker model run hf.co/tenzro/cellgemma-e4b-gguf:Q8_0
- Llama new
- LM Studio
- Jan
- Ollama
How to use tenzro/cellgemma-e4b-gguf with Ollama:
ollama run hf.co/tenzro/cellgemma-e4b-gguf:Q8_0
- Unsloth Desktop
- Docker Model Runner
How to use tenzro/cellgemma-e4b-gguf with Docker Model Runner:
docker model run hf.co/tenzro/cellgemma-e4b-gguf:Q8_0
- Lemonade
How to use tenzro/cellgemma-e4b-gguf with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull tenzro/cellgemma-e4b-gguf:Q8_0
Run and chat with the model
lemonade run user.cellgemma-e4b-gguf-Q8_0
List all available models
lemonade list
- Atomic Chat
Download stage2_decode.py from tenzro/cellgemma-e4b-gguf: direct link, hf CLI and curl.
- Browser
- Download file 5.61 kB
-
https://huggingface.co/tenzro/cellgemma-e4b-gguf/resolve/main/stage2_decode.py
- Command line
-
hf download hf://tenzro/cellgemma-e4b-gguf/stage2_decode.py
-
curl -L -o stage2_decode.py https://huggingface.co/tenzro/cellgemma-e4b-gguf/resolve/main/stage2_decode.py
5.61 kB
| #!/usr/bin/env python3 | |
| """CellGemma Stage 2: ranked +GENE/-GENE list -> expression values. | |
| Self-contained (numpy, torch, safetensors). Follows the ExpressionDecoder code | |
| in the google/cellgemma-e4b model card. The language model is not needed here. | |
| Inputs | |
| --genes-text text file with the language model's output ("+GENE -GENE ...") | |
| --decoder-dir directory with model.safetensors, config.json, mean_delta_global.json | |
| (decoders/<dataset>/ from the model repo) | |
| --control JSON with the control cell. Either | |
| {"genes": [...], "expression": [...]} or | |
| the repo's controls_sample.json (then give --dataset and --cell-idx) | |
| --out output JSON: genes, control, baseline, predicted_expression, predicted_lfc | |
| Example | |
| stage2_decode.py --genes-text out.txt --decoder-dir decoders/tahoe \ | |
| --control controls_sample.json --dataset tahoe --cell-idx 0 --out pred.json | |
| """ | |
| import argparse | |
| import json | |
| import os | |
| import numpy as np | |
| import safetensors.torch | |
| import torch | |
| from torch import nn | |
| class ExpressionDecoder(nn.Module): | |
| """MLP that predicts the expression change relative to baseline (model card code).""" | |
| def __init__(self, input_dim, hidden_dims, max_exp_arg=88.0): | |
| super().__init__() | |
| self.input_dim = input_dim | |
| self.max_exp_arg = max_exp_arg | |
| self.bn0 = nn.BatchNorm1d(input_dim + 1) | |
| layers, d = [self.bn0], input_dim + 1 | |
| for h in hidden_dims: | |
| layers += [nn.Linear(d, h), nn.ReLU()] | |
| d = h | |
| self.mlp = nn.Sequential(*layers, nn.Linear(d, 1)) | |
| def forward(self, features, control_expression): | |
| eps, ctrl = 1e-6, control_expression.view(-1, 1) | |
| x = self.mlp(torch.cat([features, ctrl], dim=1)) | |
| ctrl_safe = ctrl - torch.where(x >= 0, eps, -eps) | |
| exp_term = (x / ctrl_safe).clamp(max=self.max_exp_arg) | |
| neg_delta = ctrl_safe * (torch.exp(exp_term) - 1.0) | |
| return torch.where(x > 0, x, neg_delta) + eps | |
| def jload(path): | |
| with open(path, encoding="utf-8") as f: | |
| return json.load(f) | |
| def parse_genes(text, gene_to_idx): | |
| tokens = text.split() | |
| up = [t[1:].upper() for t in tokens if t.startswith("+")] | |
| down = [t[1:].upper() for t in tokens if t.startswith("-")] | |
| return [g for g in up if g in gene_to_idx], [g for g in down if g in gene_to_idx] | |
| def decode(text, genes, ctrl_expr, mean_deltas, decoder): | |
| md = {k.upper(): float(v) for k, v in mean_deltas.items()} | |
| mean_vec = np.array([md[g] for g in genes], dtype=np.float32) | |
| baseline = np.maximum(0.0, ctrl_expr + mean_vec) | |
| gene_to_idx = {g: i for i, g in enumerate(genes)} | |
| up, down = parse_genes(text, gene_to_idx) | |
| residual = np.zeros_like(baseline) | |
| if up or down: | |
| task_oh = [0.0] * 7 + [1.0] # mean_global residual task | |
| feats, ctrl_vals, idxs = [], [], [] | |
| for is_up, g_list in ((1.0, up), (0.0, down)): | |
| for rank, g in enumerate(g_list): | |
| idx = gene_to_idx[g] | |
| feats.append([is_up, float(rank), float(len(up)), float(len(down))] + task_oh) | |
| ctrl_vals.append(float(baseline[idx])) | |
| idxs.append(idx) | |
| with torch.no_grad(): | |
| deltas = decoder(torch.tensor(feats, dtype=torch.float32), torch.tensor(ctrl_vals, dtype=torch.float32)) | |
| residual[idxs] = deltas.cpu().numpy().flatten() | |
| pred = baseline + residual | |
| return baseline, pred, pred - ctrl_expr, up, down | |
| def main(): | |
| ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) | |
| ap.add_argument("--genes-text", required=True) | |
| ap.add_argument("--decoder-dir", required=True) | |
| ap.add_argument("--control", required=True) | |
| ap.add_argument("--dataset") | |
| ap.add_argument("--cell-idx", type=int, default=0) | |
| ap.add_argument("--out", required=True) | |
| a = ap.parse_args() | |
| cfg = jload(os.path.join(a.decoder_dir, "config.json")) | |
| decoder = ExpressionDecoder(cfg["input_dim"], cfg["hidden_dims"]) | |
| decoder.load_state_dict(safetensors.torch.load_file(os.path.join(a.decoder_dir, "model.safetensors"))) | |
| decoder.eval() | |
| mean_deltas = jload(os.path.join(a.decoder_dir, "mean_delta_global.json")) | |
| ctl = jload(a.control) | |
| if "expression" in ctl: | |
| genes, expr = ctl["genes"], ctl["expression"] | |
| else: | |
| if not a.dataset: | |
| ap.error("--dataset is required with a controls_sample.json style file") | |
| genes, expr = ctl[a.dataset]["genes"], ctl[a.dataset]["cells"][a.cell_idx]["expression"] | |
| genes = [g.upper() for g in genes] | |
| ctrl_expr = np.array(expr, dtype=np.float32) | |
| text = open(a.genes_text, encoding="utf-8").read() | |
| baseline, pred, lfc, up, down = decode(text, genes, ctrl_expr, mean_deltas, decoder) | |
| finite = bool(np.isfinite(pred).all() and np.isfinite(lfc).all()) | |
| json.dump( | |
| { | |
| "genes": genes, | |
| "control_expression": ctrl_expr.tolist(), | |
| "baseline": baseline.tolist(), | |
| "predicted_expression": pred.tolist(), | |
| "predicted_lfc": lfc.tolist(), | |
| "n_up": len(up), | |
| "n_down": len(down), | |
| "all_finite": finite, | |
| }, | |
| open(a.out, "w"), | |
| ) | |
| print(json.dumps({ | |
| "shape": list(pred.shape), "n_genes": len(genes), "n_up": len(up), "n_down": len(down), | |
| "all_finite": finite, "min": float(pred.min()), "max": float(pred.max()), | |
| "n_changed_vs_baseline": int((pred != baseline).sum()), | |
| })) | |
| if __name__ == "__main__": | |
| main() | |