Downloads · 30 days
18
13% of all-time downloads
perturblab/cellfm-800m
cellfm-800m is a machine learning model from perturblab. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
CellFM is a large-scale foundation model pre-trained on transcriptomics of 100 million human cells using a retention-based architecture (MAE Autobin).
Downloads · 30 days
18
13% of all-time downloads
All-time downloads
140
Public
Repo size
3.2 GB
Likes
1
Public
Click a slice to open those files.
.pt3.2 GB · 100%
From the Hugging Face model README
CellFM is a large-scale foundation model pre-trained on transcriptomics of 100 million human cells using a retention-based architecture (MAE Autobin).
from perturblab.model.cellfm import CellFMModel
# Load pretrained model (automatically downloads if needed)
model = CellFMModel.from_pretrained('cellfm-800m')
# Or use short name
model = CellFMModel.from_pretrained('800m')
# Or from local path
model = CellFMModel.from_pretrained('./weights/cellfm-800m')
import scanpy as sc
# Load your data
adata = sc.read_h5ad('your_data.h5ad')
# Preprocess
adata = CellFMModel.prepare_data(adata)
# Get embeddings (use smaller batch size for 800M model)
embeddings = model.predict_embeddings(
adata,
batch_size=8, # Smaller batch size for larger model
return_cls_token=True,
)
# Access cell embeddings
cell_embeddings = embeddings['cell_embeddings'] # Shape: (n_cells, 1536)
from perturblab.model.cellfm import CellFMModel, CellFMConfig
# Initialize model with classification head
config = CellFMConfig(
model_name='800M',
n_genes=24072,
enc_dims=1536,
enc_nlayers=40,
enc_num_heads=48,
num_cls=10, # Number of cell types
)
model = CellFMModel(config, for_finetuning=True)
# Load pretrained weights
model.load_weights('./weights/cellfm-800m/model.pt')
# Get dataloaders
train_loader = model.get_dataloader(train_data, batch_size=4)['train']
val_loader = model.get_dataloader(val_data, batch_size=4)['train']
# Train
model.train_model(
train_dataloader=train_loader,
val_dataloader=val_loader,
num_epochs=10,
learning_rate=1e-4,
)
from perturblab.model.cellfm import CellFMPerturbationModel
from perturblab.data import PerturbationData
# Load perturbation data
data = PerturbationData.from_anndata(adata)
data.split_data(train=0.7, val=0.15, test=0.15)
# Initialize model
model = CellFMPerturbationModel.from_pretrained('cellfm-800m')
# Initialize perturbation head from dataset
model.init_perturbation_head_from_dataset(data)
# Train (use smaller batch size)
model.train_model(data, epochs=20, batch_size=4)
# Predict
predictions = model.predict_perturbation(data, split='test')
# Evaluate
metrics = model.evaluate(data, split='test')
print(f"Pearson correlation: {metrics['pearson']:.4f}")
| Feature | 80M | 800M |
|---|---|---|
| Parameters | 80M | 800M |
| Hidden Dim | 1536 | 1536 |
| Layers | 2 | 40 |
| Heads | 48 | 48 |
| Genes | 27,855 | 24,072 |
| Memory (Inference) | ~1-2GB | ~3-4GB |
| Speed | Faster | Slower |
| Performance | Good | Better |
The 800M model provides significantly better representation quality due to its deeper architecture (40 layers vs 2 layers), at the cost of increased computational requirements.
config.json: Model configurationmodel.pt: Model weights (PyTorch state dict, ~3.0GB)README.md: This file.gitattributes: Git LFS configurationIf you use CellFM in your research, please cite:
@article{cellfm2024,
title={CellFM: A Large-Scale Foundation Model for Single-Cell Transcriptomics},
author={...},
journal={...},
year={2024}
}
CellFMModel.prepare_data() to automatically preprocess your data