Skip to content
WPBaLTYPublic

About

Accelerating single-cell foundation model inference through biology-preserving optimization

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

scInfer

Systematic Inference Optimization Framework for Single-Cell Foundation Models

scInfer is a systematic inference optimization framework for single-cell foundation models (scGPT, Geneformer, scFoundation, UCE). It adapts LLM inference optimization techniques β€” quantization, FlashAttention, knowledge distillation, compilation optimization, and dynamic batch scheduling β€” to the single-cell domain, achieving 3–5x inference speedup while preserving biological fidelity.

Key Features

  • Unified Model Interface β€” A single API for scGPT / Geneformer / scFoundation / UCE
  • Modular Optimization Engines β€” Quantization (INT8/INT4), FlashAttention, torch.compile, knowledge distillation β€” plug and play
  • Composable Optimization Pipeline β€” Multiple optimization techniques safely composable with automatic conflict detection
  • Biological Fidelity Monitoring β€” Concurrent tracking of inference speed and biological metrics (ARI, NMI, F1, PCC)
  • Hardware Awareness β€” Automatic GPU detection and optimal strategy selection
  • Extensible β€” Register new models and optimization strategies via decorators

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        scinfer API                              β”‚
β”‚   encode()  Β·  optimize()  Β·  benchmark()  Β·  profile()        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚              Optimization Combiner                       β”‚   β”‚
β”‚  β”‚  quantization + attention + compilation + scheduling    β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚  Quantization β”‚  β”‚  Attention   β”‚  β”‚  Compilation     β”‚     β”‚
β”‚  β”‚  Engine       β”‚  β”‚  Accelerator β”‚  β”‚  Engine          β”‚     β”‚
β”‚  β”‚  (INT8/INT4)  β”‚  β”‚  (FlashAttn) β”‚  β”‚  (torch.compile) β”‚     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β”‚                                                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚              Model Adapter Layer                         β”‚   β”‚
β”‚  β”‚  scGPT  Β·  Geneformer  Β·  scFoundation  Β·  UCE         β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚              Evaluation Layer                            β”‚   β”‚
β”‚  β”‚  Profiler  Β·  Benchmark  Β·  Metrics  Β·  Report          β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Installation

# Basic installation
pip install scinfer

# With all model dependencies
pip install scinfer[all-models]

# With optimization engines
pip install scinfer[optimization]

# Full installation (all optional dependencies)
pip install scinfer[all]

# Development installation
git clone [GitHub URL β€” TODO: update before release]  <!-- TODO: update before release -->
cd scinfer
pip install -e ".[all]"

Optional Dependencies

Dependency Group Included
scinfer[scgpt] scGPT model dependencies
scinfer[geneformer] Geneformer model dependencies
scinfer[scfoundation] scFoundation model dependencies
scinfer[uce] UCE model dependencies
scinfer[optimization] FlashAttention, GPTQ, ONNX, and other optimization engines
scinfer[all] All optional dependencies

Quick Start

import scanpy as sc
import scinfer

# Load single-cell data
adata = sc.read_h5ad("pbmc_10k.h5ad")

# Generate embeddings in one line (automatically selects optimal optimization strategy)
adata = scinfer.encode(adata, model="scgpt", optimize=True)

# Retrieve optimized embeddings
embeddings = adata.obsm["scinfer_embedding"]

Cross-Model Benchmarking

# Compare across models
results = scinfer.benchmark(
    model_names=["scgpt", "geneformer", "scfoundation"],
    datasets=["pbmc_10k", "pancreas"],
    metrics=["throughput", "latency", "ari", "nmi"],
)

# Inference bottleneck profiling
profile = scinfer.profile("scgpt", input_lengths=[512, 1024, 2048])
print(profile.summary())

Experiment Script Guide

Inference Profiling

# Profile all models
python scripts/profile_models.py --models scgpt geneformer scfoundation uce --output results/profiling/

Quantization Experiments

# Run quantization evaluation experiment
python scripts/quantization_experiment.py --config configs/quantization/experiment_config.yaml

# Evaluate quantization effects
python scripts/evaluate_quantization.py --data-dir results/quantization/ --output results/quant_eval/

FlashAttention Experiments

python scripts/flash_attention_experiment.py --versions v1 v2 v3 --seq-lengths 128 256 512 1024 2048

Knowledge Distillation

python scripts/distillation_experiment.py --teacher scgpt --student-sizes 12M 6M 3M --epochs 100

Combined Optimization

python scripts/combined_optimization_experiment.py --config configs/optimization/combined.yaml

GPU Configuration Comparison

# Compare inference performance across different GPUs
python scripts/compare_gpu_configs.py \
    --gpus T4 V100 A100 H100 RTX4090 \
    --models scgpt geneformer scfoundation \
    --output results/gpu_comparison/

# Run real benchmarks (requires GPU)
python scripts/compare_gpu_configs.py --real-benchmark --output results/gpu_comparison/

Paper Figure Generation

# Generate paper Fig.1-7
python scripts/generate_figures.py --data-dir results/ --output-dir figures/ --format pdf --dpi 350

# Generate Extended Data Figures
python scripts/generate_extended_data.py --data-dir results/ --output-dir figures/extended/ --format pdf

# Generate specific figures only
python scripts/generate_figures.py --figs 1 3 5 --format png --dpi 300

Million-Cell Demo

python scripts/million_cell_demo.py --n-cells 1000000 --model scgpt --batch-size 256

Project Structure

scInfer/
β”œβ”€β”€ configs/                    # Configuration files
β”‚   β”œβ”€β”€ models/                 # Model configs (scgpt, geneformer, ...)
β”‚   β”œβ”€β”€ optimization/           # Optimization strategy configs
β”‚   β”œβ”€β”€ quantization/           # Quantization experiment configs
β”‚   └── default.yaml            # Default configuration
β”œβ”€β”€ notebooks/                  # Jupyter Notebooks
β”‚   β”œβ”€β”€ 01_profiling_exploration.ipynb
β”‚   β”œβ”€β”€ 02_benchmark_results.ipynb
β”‚   β”œβ”€β”€ 03_quantization_analysis.ipynb
β”‚   β”œβ”€β”€ 04_distillation_analysis.ipynb
β”‚   β”œβ”€β”€ 05_combined_optimization.ipynb
β”‚   β”œβ”€β”€ 06_biological_validation.ipynb
β”‚   └── 07_paper_figures.ipynb  # Paper figure collection
β”œβ”€β”€ results/                    # Experimental results
β”œβ”€β”€ scinfer/                    # Core package
β”‚   β”œβ”€β”€ adapters/               # Model adapters
β”‚   β”‚   β”œβ”€β”€ base.py             # Adapter base class
β”‚   β”‚   β”œβ”€β”€ scgpt.py            # scGPT adapter
β”‚   β”‚   β”œβ”€β”€ geneformer.py       # Geneformer adapter
β”‚   β”‚   β”œβ”€β”€ scfoundation.py     # scFoundation adapter
β”‚   β”‚   └── uce.py              # UCE adapter
β”‚   β”œβ”€β”€ core/                   # Core modules
β”‚   β”‚   β”œβ”€β”€ config.py           # Configuration management
β”‚   β”‚   β”œβ”€β”€ registry.py         # Model/strategy registry
β”‚   β”‚   └── types.py            # Type definitions
β”‚   β”œβ”€β”€ engines/                # Optimization engines
β”‚   β”‚   β”œβ”€β”€ quantization.py     # Quantization engine (INT8/INT4)
β”‚   β”‚   β”œβ”€β”€ attention.py        # FlashAttention acceleration
β”‚   β”‚   β”œβ”€β”€ compilation.py      # torch.compile / ONNX
β”‚   β”‚   β”œβ”€β”€ scheduling.py       # Dynamic batch scheduling
β”‚   β”‚   └── combiner.py         # Optimization combiner
β”‚   β”œβ”€β”€ evaluation/             # Evaluation module
β”‚   β”‚   β”œβ”€β”€ benchmark.py        # Benchmark framework
β”‚   β”‚   β”œβ”€β”€ profiler.py         # Inference profiler
β”‚   β”‚   β”œβ”€β”€ bio_validation.py   # Biological validation
β”‚   β”‚   β”œβ”€β”€ report.py           # Report generation
β”‚   β”‚   └── metrics/            # Evaluation metrics
β”‚   β”‚       β”œβ”€β”€ biological.py   # Biological metrics (ARI, NMI, F1)
β”‚   β”‚       └── inference.py    # Inference metrics (throughput, latency)
β”‚   β”œβ”€β”€ utils/                  # Utility functions
β”‚   └── api.py                  # Public API
β”œβ”€β”€ scripts/                    # Experiment scripts
β”‚   β”œβ”€β”€ profile_models.py       # Model profiling
β”‚   β”œβ”€β”€ benchmark_inference.py  # Inference benchmark
β”‚   β”œβ”€β”€ quantization_experiment.py
β”‚   β”œβ”€β”€ evaluate_quantization.py
β”‚   β”œβ”€β”€ flash_attention_experiment.py
β”‚   β”œβ”€β”€ combined_optimization_experiment.py
β”‚   β”œβ”€β”€ million_cell_demo.py    # Million-cell demonstration
β”‚   β”œβ”€β”€ generate_figures.py     # Paper figure generation (Fig.1-7)
β”‚   β”œβ”€β”€ generate_extended_data.py  # Extended Data Figures
β”‚   └── compare_gpu_configs.py  # GPU configuration comparison
β”œβ”€β”€ tests/                      # Unit tests
β”œβ”€β”€ pyproject.toml              # Project configuration
└── LICENSE                     # Apache 2.0

Comparison with Existing Tools

Feature scInfer Native Model Code vLLM / TGI
Single-cell model support βœ… Native ❌ Per-model adaptation ❌ LLM only
Quantization (INT8/INT4) βœ… Unified interface ⚠️ Manual implementation βœ…
FlashAttention βœ… Automatic selection ⚠️ Manual integration βœ…
Biological metrics βœ… ARI/NMI/F1/PCC ⚠️ Custom code ❌
Cross-model benchmarking βœ… Built-in ❌ ❌
Composable optimization βœ… Pipeline ❌ ⚠️ Limited
Knowledge distillation βœ… Single-cell adapted ❌ ❌
Hardware-aware scheduling βœ… Automatic GPU detection ❌ ⚠️ Basic
Million-cell support βœ… Optimized batching ❌ OOM βœ…

Roadmap

  • Phase 1 β€” Inference profiling and bottleneck analysis (4 models)
  • Phase 2 β€” Quantization engine (INT8/INT4) + biological fidelity tracking
  • Phase 3 β€” FlashAttention integration (v1/v2/v3)
  • Phase 4 β€” Knowledge distillation + torch.compile optimization
  • Phase 5 β€” Combined optimization + biological validation
  • Phase 6 β€” Production-grade inference serving (dynamic batch scheduling, REST API)
  • Phase 7 β€” Additional single-cell model support (scBERT, scToken, ...)

Citation

@software{scinfer2025,
  title  = {scInfer: Systematic Inference Optimization for Single-Cell Foundation Models},
  author = {scInfer Team},
  year   = {2025},
  url    = {[GitHub URL β€” TODO: update before release]},  <!-- TODO: update before release -->
}

License

Apache License 2.0. See LICENSE for details.

About

Accelerating single-cell foundation model inference through biology-preserving optimization

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages