Views
No views yet
1from perturblab.model.cellfm import CellFMModel
2
3# Load pretrained model (automatically downloads if needed)
4model = CellFMModel.from_pretrained('cellfm-800m')
5
6# Or use short name
7model = CellFMModel.from_pretrained('800m')
8
9# Or from local path
10model = CellFMModel.from_pretrained('./weights/cellfm-800m')1import scanpy as sc
2
3# Load your data
4adata = sc.read_h5ad('your_data.h5ad')
5
6# Preprocess
7adata = CellFMModel.prepare_data(adata)
8
9# Get embeddings (use smaller batch size for 800M model)
10embeddings = model.predict_embeddings(
11 adata,
12 batch_size=8, # Smaller batch size for larger model
13 return_cls_token=True,
14)
15
16# Access cell embeddings
17cell_embeddings = embeddings['cell_embeddings'] # Shape: (n_cells, 1536)1from perturblab.model.cellfm import CellFMModel, CellFMConfig
2
3# Initialize model with classification head
4config = CellFMConfig(
5 model_name='800M',
6 n_genes=24072,
7 enc_dims=1536,
8 enc_nlayers=40,
9 enc_num_heads=48,
10 num_cls=10, # Number of cell types
11)
12model = CellFMModel(config, for_finetuning=True)
13
14# Load pretrained weights
15model.load_weights('./weights/cellfm-800m/model.pt')
16
17# Get dataloaders
18train_loader = model.get_dataloader(train_data, batch_size=4)['train']
19val_loader = model.get_dataloader(val_data, batch_size=4)['train']
20
21# Train
22model.train_model(
23 train_dataloader=train_loader,
24 val_dataloader=val_loader,
25 num_epochs=10,
26 learning_rate=1e-4,
27)1from perturblab.model.cellfm import CellFMPerturbationModel
2from perturblab.data import PerturbationData
3
4# Load perturbation data
5data = PerturbationData.from_anndata(adata)
6data.split_data(train=0.7, val=0.15, test=0.15)
7
8# Initialize model
9model = CellFMPerturbationModel.from_pretrained('cellfm-800m')
10
11# Initialize perturbation head from dataset
12model.init_perturbation_head_from_dataset(data)
13
14# Train (use smaller batch size)
15model.train_model(data, epochs=20, batch_size=4)
16
17# Predict
18predictions = model.predict_perturbation(data, split='test')
19
20# Evaluate
21metrics = model.evaluate(data, split='test')
22print(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 |
config.json: Model configurationmodel.pt: Model weights (PyTorch state dict, ~3.0GB)README.md: This file.gitattributes: Git LFS configuration1@article{cellfm2024,
2 title={CellFM: A Large-Scale Foundation Model for Single-Cell Transcriptomics},
3 author={...},
4 journal={...},
5 year={2024}
6}CellFMModel.prepare_data() to automatically preprocess your data