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.
- 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
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 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 β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 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]"| 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 |
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"]# 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())# Profile all models
python scripts/profile_models.py --models scgpt geneformer scfoundation uce --output results/profiling/# 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/python scripts/flash_attention_experiment.py --versions v1 v2 v3 --seq-lengths 128 256 512 1024 2048python scripts/distillation_experiment.py --teacher scgpt --student-sizes 12M 6M 3M --epochs 100python scripts/combined_optimization_experiment.py --config configs/optimization/combined.yaml# 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/# 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 300python scripts/million_cell_demo.py --n-cells 1000000 --model scgpt --batch-size 256scInfer/
βββ 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
| Feature | scInfer | Native Model Code | vLLM / TGI |
|---|---|---|---|
| Single-cell model support | β Native | β Per-model adaptation | β LLM only |
| Quantization (INT8/INT4) | β Unified interface | β | |
| FlashAttention | β Automatic selection | β | |
| Biological metrics | β ARI/NMI/F1/PCC | β | |
| Cross-model benchmarking | β Built-in | β | β |
| Composable optimization | β Pipeline | β | |
| Knowledge distillation | β Single-cell adapted | β | β |
| Hardware-aware scheduling | β Automatic GPU detection | β | |
| Million-cell support | β Optimized batching | β OOM | β |
- 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, ...)
@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 -->
}Apache License 2.0. See LICENSE for details.