ArGoN1 commited on
Commit
299b839
·
verified ·
1 Parent(s): c2513aa

Upload SAVE model card and pretrained bundles

Browse files
Files changed (2) hide show
  1. .gitattributes +6 -32
  2. README.md +176 -0
.gitattributes CHANGED
@@ -1,35 +1,9 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
  *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
  *.pickle filter=lfs diff=lfs merge=lfs -text
21
  *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
1
+ *.pt filter=lfs diff=lfs merge=lfs -text
2
+ *.pth filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
3
  *.npz filter=lfs diff=lfs merge=lfs -text
4
+ *.h5ad filter=lfs diff=lfs merge=lfs -text
 
 
 
5
  *.pickle filter=lfs diff=lfs merge=lfs -text
6
  *.pkl filter=lfs diff=lfs merge=lfs -text
7
+ *.png filter=lfs diff=lfs merge=lfs -text
8
+ *.gif filter=lfs diff=lfs merge=lfs -text
9
+ *.mp4 filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
README.md ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ library_name: sc-save
6
+ tags:
7
+ - single-cell
8
+ - scrna-seq
9
+ - bioinformatics
10
+ - computational-biology
11
+ - ai4science
12
+ - virtual-cell
13
+ - flow-matching
14
+ - optimal-transport
15
+ - vae
16
+ - dit
17
+ - gene-block-attention
18
+ - perturbation-prediction
19
+ - batch-effect-correction
20
+ - pytorch
21
+ - anndata
22
+ - scanpy
23
+ - iclr-2026
24
+ - arxiv:2604.16776
25
+ metrics:
26
+ - wasserstein-distance
27
+ - mmd
28
+ - pearsonr
29
+ - r2
30
+ - scib
31
+ ---
32
+
33
+ # SAVE: Multi-Condition Single-Cell Generation with Gene Block Attention (ICLR 2026)
34
+
35
+ Model hub for **SAVE** (*ICLR 2026*), packaged as **`sc-save`** (`v0.2.0`) on PyPI.
36
+
37
+ - **Project Page & Overview Video:** [save.argonx.dev](https://save.argonx.dev)
38
+ - **GitHub Repository:** [fdu-wangfeilab/sc-save](https://github.com/fdu-wangfeilab/sc-save)
39
+ - **PyPI Package:** [`sc-save`](https://pypi.org/project/sc-save/) (`pip install sc-save`)
40
+ - **Paper:** [OpenReview](https://openreview.net/forum?id=l7QEoK4uDP) · [arXiv:2604.16776](https://arxiv.org/abs/2604.16776)
41
+ - **Interactive Demo Space:** [ArGoN1/sc-save-demo](https://huggingface.co/spaces/ArGoN1/sc-save-demo)
42
+ - **One-Click Colab Reproduction:** [ICLR 2026 Reproduce Notebook](https://colab.research.google.com/github/fdu-wangfeilab/sc-save/blob/main/notebooks/SAVE_ICLR2026_Reproduce_Colab.ipynb) · [Quickstart Tutorial](https://colab.research.google.com/github/fdu-wangfeilab/sc-save/blob/main/notebooks/SAVE_Quickstart_Tutorial.ipynb)
43
+
44
+ ---
45
+
46
+ ## Model Overview
47
+
48
+ Standard Transformer models for single-cell RNA-seq (~20,000 unordered genes per cell) face an $\mathcal{O}(G^2)$ attention bottleneck and lack spatial 2D grids for Vision Transformer (ViT) patchification. **SAVE** introduces:
49
+
50
+ 1. **LLM Biological Knowledge (Semantic Gene Embeddings → OT Gene Blocks):** Encodes curated NCBI Gene functional summaries via GenePT (1,536-dim embeddings) and solves iterative **Optimal Transport** clustering to partition genes into $L$ balanced, pathway-coherent **Gene Blocks** ($K = 3200$ default; $K=400$ for perturbation/BEC), collapsing self-attention complexity from $\mathcal{O}(G^2)$ to $\mathcal{O}(L^2)$ (**191× training speedup** on 1× RTX 3090: `2,391.2 min → 12.5 min`).
51
+ 2. **Gene-Block Attention VAE + DiT Latent OT Flow Matching:** Compresses block-structured profiles into pathway-structured latents $z \in \mathbb{R}^{N \times L \times d}$ and trains a conditional DiT Optimal-Transport Flow Matching denoiser (`AdaLN`, independent condition masking $p=0.6$, multi-condition Classifier-Free Guidance) sampled in **20 ODE steps**.
52
+ 3. **One Unified Framework Across 8 Benchmarks:** Supports 1–5 condition cell generation (including unseen covariate combinations), zero-shot batch effect correction (`scIB`), and leave-one-out counterfactual perturbation prediction.
53
+
54
+ ---
55
+
56
+ ## Bundle Layout (`SAVE.save` / `SAVE.load`)
57
+
58
+ Each pretrained checkpoint subfolder in this repository stores a self-contained `sc-save` bundle produced by `model.save(...)`:
59
+
60
+ ```text
61
+ <dataset_bundle>/
62
+ ├── config.json # SAVEConfig (VAEConfig, FMConfig, TrainConfig, cond_encoding)
63
+ ├── vocab.json # ConditionVocabulary (condition columns, classes, <mask> id)
64
+ ├── metadata.json # Gene count, pad_idx, var_names, training flags
65
+ ├── scaler.npz # Fitted MaxAbsExpressionScaler parameters
66
+ ├── vae.pt # Stage-1 Gene-Block Attention VAE weights
67
+ └── fm.pt # Stage-2 DiT Conditional OT Flow Matching weights (generation bundles)
68
+ ```
69
+
70
+ Planned / hosted benchmark bundles:
71
+ - `heart/` — Dual-condition (`batch`, `cell_type`) Human Heart Atlas (`K=3200`)
72
+ - `pbmc/` — Dual-condition (`batch`, `cell_type`) Human PBMC (`K=3200`)
73
+ - `lung_atlas/` — Dual-condition (`batch`, `cell_type`) Human Lung Atlas (`K=3200`)
74
+ - `lung_cancer/` — 5-covariate (`assay`, `development_stage`, `disease`, `uicc_stage`, `cell_type`) Lung Cancer Atlas (`K=3200`)
75
+ - `pbmc_ifn/` — Perturbation prediction (`condition`, `cell_type`) PBMC IFN-$\beta$ (`K=400`)
76
+
77
+ ---
78
+
79
+ ## Quickstart (`sc-save v0.2.0` + `huggingface_hub`)
80
+
81
+ ```bash
82
+ pip install sc-save huggingface_hub
83
+ ```
84
+
85
+ ```python
86
+ from huggingface_hub import snapshot_download
87
+ from sc_save import SAVE
88
+ import scanpy as sc
89
+
90
+ # 1. Download a pretrained SAVE bundle (e.g., heart)
91
+ bundle_dir = snapshot_download(
92
+ repo_id="ArGoN1/sc-save",
93
+ allow_patterns=["heart/*"],
94
+ )
95
+ model = SAVE.load(f"{bundle_dir}/heart", device="auto")
96
+
97
+ # 2. Conditional cell generation with 20-step OT Flow Matching + CFG
98
+ gen_adata = model.generate(
99
+ {"batch": "D1", "cell_type": "Atrial_Cardiomyocyte"},
100
+ n_cells=500,
101
+ guidance_weight=2.0,
102
+ steps=20,
103
+ )
104
+
105
+ # 3. Inspect condition-modulated Gene Block attention weights
106
+ attn_res = model.generate_with_attention(
107
+ {"batch": "D1", "cell_type": "Atrial_Cardiomyocyte"},
108
+ n_cells=32,
109
+ steps=20,
110
+ )
111
+
112
+ # 4. Zero-shot batch / condition transfer on an external AnnData
113
+ adata = sc.read_h5ad("my_cells.h5ad")
114
+ transferred = model.transfer(
115
+ adata,
116
+ target_cond={"batch": "D1"},
117
+ input_cond="obs",
118
+ inverse_scale=True,
119
+ trim_pad=True,
120
+ )
121
+ ```
122
+
123
+ For training from scratch on your own `.h5ad` file (requires GenePT embeddings from [Zenodo 10833191](https://zenodo.org/records/10833191)):
124
+
125
+ ```python
126
+ import scanpy as sc
127
+ from sc_save import SAVE, SAVEConfig, build_gene_blocks, load_gene_embeddings
128
+
129
+ adata = sc.read_h5ad("heart_raw.h5ad")
130
+ gene_embs = load_gene_embeddings("GenePT_gene_protein_embedding_model_3_text.pickle")
131
+ blocks = build_gene_blocks(adata, gene_embs, block_size=3200)
132
+
133
+ cfg = SAVEConfig.save_b(gene_block_size=3200, cond_encoding="offset")
134
+ model = SAVE(blocks.adata, condition_cols=("batch", "cell_type"), config=cfg, device="auto")
135
+ model.fit()
136
+ model.save("./outputs/save_heart_bundle")
137
+ ```
138
+
139
+ ---
140
+
141
+ ## Verified ICLR 2026 & `v0.2.0` Benchmarks
142
+
143
+ Across Google Colab GPU validation ([`iclr2026_v2_colab_validation.json`](https://github.com/fdu-wangfeilab/sc-save/blob/main/results/iclr2026_v2_colab_validation.json)), `sc-save v0.2.0` passed all **10/10 primary ICLR 2026 benchmarks** with **zero regression gate failures**:
144
+
145
+ | Benchmark | Key Metric(s) | Paper Target | `v1` Colab (Blackwell G4) | **`v0.2.0` Colab (A100 / L4)** |
146
+ | :--- | :--- | :---: | :---: | :---: |
147
+ | **Table 1** (`pbmc3k` / `dentategyrus` / `tabula_muris`) | WD ($\downarrow$) / MMD ($\downarrow$) | `19.14/1.80` · `9.16/0.17` · `10.86/0.04` | `12.76/0.48` · `8.08/0.11` · `10.65/0.04` | **`12.74/0.49` · `8.11/0.11` · `10.21/0.03`** |
148
+ | **Table 2** (`heart` / `pbmc` / `lung_atlas`) | WD ($\downarrow$) / MMD ($\downarrow$) | `8.30/0.63` · `5.37/0.29` · `4.37/1.14` | `8.83/0.64` · `5.39/0.30` · `4.42/1.16` | **`8.20/0.61` · `5.30/0.29` · `4.41/1.15`** |
149
+ | **Table 3** (`lung_cancer` Seen / Unseen) | WD ($\downarrow$) / MMD ($\downarrow$) | `3.10/1.06` · `4.63/2.11` | `3.07/1.08` · `5.39/2.16` | **`3.05/1.07` · `4.42/2.07`** |
150
+ | **Table 4** (`lung_atlas` / `heart` / `pbmc` BEC) | scIB ($\uparrow$) | `0.8128` · `0.7983` · `0.8309` | `0.8097` · `0.8019` · `0.8125` | **`0.8080` · `0.7985` · `0.8238`** |
151
+ | **Table 5** (`pbmc_ifn` 7-fold LOO Average) | PCC ($\uparrow$) / $R^2$ ($\uparrow$) / WD ($\downarrow$) | `0.96` / `0.86` / `5.15` | `0.943` / `0.807` / `5.77` | **`0.940` / `0.792` / `5.86`** |
152
+
153
+ - **Up to 8.43× faster generation** and **2.27×–2.48× faster end-to-end** on dedicated Colab A100 vs. `v1` Blackwell G4.
154
+ - **Atlas-scale memory safety:** `Tabula Muris` (`196,311 × 22,400`) runs end-to-end inside **52 GB host RAM** on Colab L4 via streaming randomized PCA and tiled RBF-MMD ($\le 16\text{ MB}$ tiles).
155
+
156
+ ---
157
+
158
+ ## Intended Use & Limitations
159
+
160
+ - **Intended Use:** Academic and computational research in single-cell transcriptomics, conditional virtual cell synthesis, batch integration, and in-silico perturbation modeling.
161
+ - **Limitations:** Generated expression profiles are statistical approximations learned from training cohorts and require wet-lab or orthogonal biological validation before clinical or therapeutic decisions. Genes absent from the precomputed GenePT vocabulary are excluded or placed into remainder/padded blocks during Gene Block construction.
162
+
163
+ ---
164
+
165
+ ## Citation
166
+
167
+ ```bibtex
168
+ @inproceedings{
169
+ li2026save,
170
+ title={{SAVE}: A Generalizable Framework for Multi-Condition Single-Cell Generation with Gene Block Attention},
171
+ author={Jiahao Li and Jiayi Dong and Peng Ye and Xiaochi Zhou and Haohai Lu and Fei Wang},
172
+ booktitle={The Fourteenth International Conference on Learning Representations},
173
+ year={2026},
174
+ url={https://openreview.net/forum?id=l7QEoK4uDP}
175
+ }
176
+ ```