Archive checkpoint paper-releases/pbisc-diffusion/updates/20261007T184015Z-scsemi-disk-cleanup/diffusion/dataset/server_2/model8/plans/paired_finetune_intradataset_20260927/scsemi/README.md
Browse files
paper-releases/pbisc-diffusion/updates/20261007T184015Z-scsemi-disk-cleanup/diffusion/dataset/server_2/model8/plans/paired_finetune_intradataset_20260927/scsemi/README.md
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# scSemiProfiler as a paired few-pair baseline (`scsemi5`)
|
| 2 |
+
|
| 3 |
+
Set up 2026-09-28. This is scSemiProfiler run in its own design: single cells for a few representatives, bulk for everyone. It is scored head-to-head with our LoRA-5 arm on the same draws.
|
| 4 |
+
|
| 5 |
+
- **Representatives:** the 5 training donors of each few-pair draw (`data/<ds>/fewshot_n5/draw<j>/train_donors.txt`). Every usable row of those donors is used, with its real single cells and its real bulk.
|
| 6 |
+
- **Targets:** the draw's `test_samples.txt` rows, from their real bulk only.
|
| 7 |
+
|
| 8 |
+
The frozen ImMicro campaign (`plans/immicro_scsemi_comparison_20260927/`) is not modified. Its pinned vendor code, compatibility patch, gene-set translation and `runtime_env` are reused.
|
| 9 |
+
|
| 10 |
+
## What upstream does with real bulk (`bulktype`)
|
| 11 |
+
|
| 12 |
+
Source: `vendor/scSemiProfiler/scSemiProfiler/inference.py::fast_semi`, `initial_setup.py`, `singlecell_process.py`, `representative_selection.py`. The upstream commit is `c2aea02`.
|
| 13 |
+
|
| 14 |
+
**Bulk preprocessing (`initsetup`).** Bulk is library-normalised to 10^4 (`normed=False`), then `log1p`. It is PCA-reduced to `min(100, n_samples-1)` components; the PCA is fitted on all samples, representatives and targets. This matrix is the only bulk the method uses afterwards.
|
| 15 |
+
|
| 16 |
+
**Representative single cells (`scprocess`).**
|
| 17 |
+
- Each cell is library-normalised to 10^4.
|
| 18 |
+
- Background removal zeroes every value ≤ 10 (1e-3 of the library).
|
| 19 |
+
- Gene-set scores are computed from c2.cp and the variable ones are kept (`hvset`).
|
| 20 |
+
- A k=15 cell graph is built and neighbor-smoothed features are added.
|
| 21 |
+
|
| 22 |
+
**Pretraining per representative.**
|
| 23 |
+
- Pretrain 1 reconstructs the representative's cells: VAE 100 epochs, then GAN 100×3.
|
| 24 |
+
- Pretrain 2 adds a bulk loss whose target is the representative's own pseudobulk, i.e. the mean of its processed cells: VAE 50, GAN 50×3.
|
| 25 |
+
- The representative's real bulk is not used in pretraining.
|
| 26 |
+
|
| 27 |
+
**`bulktype='real'` (used here).** The target's bulk-loss vector is
|
| 28 |
+
|
| 29 |
+
`pseudobulk_rep × (bulk_tgt + 0.1) / (bulk_rep + 0.1)`
|
| 30 |
+
|
| 31 |
+
- Both bulks are real CP10K (`expm1` of the processed bulk).
|
| 32 |
+
- The ratio is 1 on the gene-set features.
|
| 33 |
+
- So the real bulk enters only as a gene-wise fold change between the target and its own representative. That cancels the bulk→sc platform bias, and the absolute scale comes from the representative's single cells.
|
| 34 |
+
|
| 35 |
+
**`bulktype='pseudobulk'` (frozen ImMicro campaign).** The target's CP10K bulk replaces the gene part of that vector directly. This is meant for inputs that are already in pseudobulk space.
|
| 36 |
+
|
| 37 |
+
**Inference.**
|
| 38 |
+
- 5 ministages × 150 epochs.
|
| 39 |
+
- The bulk weight rises 8 → 1024 across ministages, with a shrinking upper-bound mask.
|
| 40 |
+
- The encoder input is the representative's cells, so the method outputs one generated cell per representative cell. Composition is inherited from the representative except where cells shift state.
|
| 41 |
+
- Output = ZINB mean, rescaled to each representative cell's library. Values ≤ 10 are zeroed, which leaves about 2 % non-zero in the frozen run.
|
| 42 |
+
|
| 43 |
+
**Assignment.** Each target uses exactly one representative. Upstream's rule is `representative_selection.update_membership`: nearest representative by Euclidean distance in the bulk PCA above. The fixed representatives replace upstream's KMeans / active-learning choice. `assignment.json` records every distance.
|
| 44 |
+
|
| 45 |
+
## Protocol (per split)
|
| 46 |
+
|
| 47 |
+
| item | setting |
|
| 48 |
+
|---|---|
|
| 49 |
+
| upstream | commit `c2aea021…`, frozen compatibility patch; vendor file hashes checked at every call |
|
| 50 |
+
| inputs | raw bulk counts and raw UMI counts on the modeled genes (`normed=False`, `logged=False`) |
|
| 51 |
+
| modeled genes | 6k panel genes with `bulk_valid` in every representative and target row and `sc_valid` in every representative row (no target sc mask) |
|
| 52 |
+
| `initsetup` | `geneselection=False`, `batch=1` (its KMeans output is overwritten) |
|
| 53 |
+
| representatives | every usable row of the 5 training donors (Ji 7–9, Giroux 12–14, Imperial 12–15, sepsis and ImMicro 5 rows per draw) |
|
| 54 |
+
| `scprocess` | `cellfilter=False`, `threshold=1e-3`, `geneset=True`, `k=15` |
|
| 55 |
+
| gene sets | pinned c2.cp v7.4 translated to panel Ensembl IDs with the frozen campaign's own `translate_gmt()`; restricted to the frozen 5,913-gene axis, all 2,922 pathways are identical to the frozen mapped GMT (`genesets/geneset_assets.json`) |
|
| 56 |
+
| budget | upstream defaults: pretrain 1 = VAE100/GAN100 (lr 1e-3); pretrain 2 = VAE50/GAN50 (lr 1e-4); inference = 150 epochs × 5 ministages (lr 2e-4), `bulktype='real'`, `pseudocount=0.1` |
|
| 57 |
+
| seeds | base 20260927; pretrain 1 = base+1000+row, pretrain 2 = base+2000+row, target = base+row (row = index in the bulk file) |
|
| 58 |
+
|
| 59 |
+
## Modeled genes
|
| 60 |
+
|
| 61 |
+
The count equals the scorer's scoring genes in every dataset. The masks do not vary within a dataset's usable rows, so the count is the same in all 5 draws.
|
| 62 |
+
|
| 63 |
+
| dataset | modeled genes |
|
| 64 |
+
|---|---:|
|
| 65 |
+
| ImMicro | 5,508 |
|
| 66 |
+
| Ye 2026 sepsis | 5,975 |
|
| 67 |
+
| Ji 2025 ChILI | 5,752 |
|
| 68 |
+
| Giroux 2022 | 5,563 |
|
| 69 |
+
| Imperial ESKD | 5,927 |
|
| 70 |
+
|
| 71 |
+
Each split's `inputs/inputs_manifest.json` records the count and the equality check.
|
| 72 |
+
|
| 73 |
+
## Output adapter (`tools/export_npz.py` → `generated/<ds>/fewshot_n5/draw<j>/scsemi5__raw.npz` + `.log`)
|
| 74 |
+
|
| 75 |
+
**Cells.** 1,500 per target, taken from its representative's n generated cells:
|
| 76 |
+
- n ≥ 1500: drawn without replacement.
|
| 77 |
+
- n < 1500: whole permutations are concatenated to 1,500, so each cell is used ⌊1500/n⌋ or ⌈1500/n⌉ times. This affects representatives with few cells (Imperial down to 265, Ji 759, ImMicro 1,299).
|
| 78 |
+
- The stream is `default_rng([20260927, uint64(sha256(target)[:8])])`. The kept rows are stored in `source_row`.
|
| 79 |
+
|
| 80 |
+
**Depth.** Each generated cell is rescaled to sum to D.
|
| 81 |
+
- D = the median per-cell UMI, on the modeled genes, of all the representatives' observed cells in the draw.
|
| 82 |
+
- D is a label-free choice from the training pairs; it is recorded in the manifest, the metadata and the receipt.
|
| 83 |
+
- All-zero cells stay zero and are counted.
|
| 84 |
+
- The result is expected counts (Poisson rates); `score_ft.py` reads them out with its fixed Poisson seed.
|
| 85 |
+
|
| 86 |
+
**Genes.** Modeled genes go at their panel columns; every other panel column is 0.
|
| 87 |
+
|
| 88 |
+
**`metadata_json`.** `input_condition_path` = the draw's `test_raw.npz`, with its sha. The receipt carries `output_sha256`, per-target runtime and checks.
|
| 89 |
+
|
| 90 |
+
**Validation.** `tools/validate_export.py` recomputes every row from the lossless shards and checks:
|
| 91 |
+
- the scorer contract (panel gene order, keys, `allow_pickle=False`);
|
| 92 |
+
- finiteness and non-negativity;
|
| 93 |
+
- 1,500 cells per target;
|
| 94 |
+
- the condition samples;
|
| 95 |
+
- the receipt sha.
|
| 96 |
+
|
| 97 |
+
## Deviations from upstream defaults (all deliberate)
|
| 98 |
+
|
| 99 |
+
1. **Fixed representatives, no active learning or KMeans.** Both methods must see the same pairs. Assignment uses upstream's own nearest-representative function.
|
| 100 |
+
2. **`geneselection=False`.** The Python API default is the top-6,000 bulk HVGs. The modeled axis is fixed (5.5–6.0k genes) so both methods are scored on the same genes. With fewer than 6,000 genes, HVG selection would keep nearly all of them anyway.
|
| 101 |
+
3. **`cellfilter=False`.** This is the Python API default; the CLI default is on. The benchmark cells are already QC-retained, and upstream's filter needs `MT-` symbols while our axis uses Ensembl IDs.
|
| 102 |
+
4. **Gene-set GMT translated from symbols to Ensembl IDs.** Same translation as the frozen campaign.
|
| 103 |
+
5. **Frozen compatibility patch.** Three changes: an unused `scvi.nn` import is removed; `use_gpu` is translated to `accelerator`; the `geneset_len=0` slice is fixed (inactive here).
|
| 104 |
+
5b. **Compatibility addition 2026-09-28 (`trailing_size1_batch_20260928`).** When a representative's cell count n satisfies n % 128 == 1, the last pretraining minibatch holds one cell and the encoder's BatchNorm1d crashes (seen in Ji draw 0 at N150_BC, 2,433 cells, and Imperial draw 0 at C141_0202, 1,025 cells).
|
| 105 |
+
- In `vaegan.train()` the scvi `DataSplitter` now gets its supported `drop_last=True` option in that case only. That is the remedy upstream itself left commented out in the same function (a drop-last splitter when `n_obs % batch_size == 1`).
|
| 106 |
+
- Every other cell count takes the byte-identical original call. No cell is removed from the data: each epoch reshuffles all n cells and skips the single leftover one.
|
| 107 |
+
- Tool: `tools/compat_patch_20260928.py`. It updates `vendor/compatibility.patch` and `vendor/source_manifest.json`, and keeps the previous manifest as `source_manifest.before_20260928.json`.
|
| 108 |
+
- CPU evidence (`validation/trailing_batch_fix_*.json`): the crash reproduces on the old code; the new code passes pretrain, inference, export and validation for N150_BC; for an unaffected representative, old and new code give bitwise-identical pretrain checkpoints, per-target models and shards.
|
| 109 |
+
- Scan (`validation/trailing_batch_scan_server{1,2}.json`, all 25 few-pair and 25 CV splits): the few-pair splits hit are Ji 0, 1, 3 (N150_BC), Giroux 0–4 (BAAF62_d7, 7,297 cells) and Imperial 0 (C141_0202). No representative hits the inference condition (n > 9000 and n % 9000 == 1).
|
| 110 |
+
6. **Memory-lean cell graph** (`tools/lean_cellgraph.py`), used in place of upstream `fast_cellgraph` inside `scprocess`.
|
| 111 |
+
- Upstream's version was OOM-killed at the 16 GiB CPU cap on the largest Giroux representative (15,650 cells). It holds dense n×n copies plus an n×14×G gather and two temporaries of that size, and runs an O(n²) Python loop.
|
| 112 |
+
- The lean version does the same arithmetic in the same order: it computes the gather in row chunks and vectorises the neighbor lookup, falling back to upstream's loop when a row doesn't have exactly k−1 neighbors.
|
| 113 |
+
- Its outputs are **bit-identical** to upstream, checked on `selfw`, `adj`, `neighbors`, `neighborx` and the returned tensor (`validation/lean_cellgraph_*.json`, `validation/prepared_*`). It is 5–8× faster.
|
| 114 |
+
- That rep now prepares at 7.1 GiB peak.
|
| 115 |
+
- Its sha256 is part of the run signature.
|
| 116 |
+
7. **Engineering only, with no change to the computation.**
|
| 117 |
+
- The upstream pipeline is run in bounded, resumable chunks: `scinfer`'s loop is re-expressed per representative and per target.
|
| 118 |
+
- The pretrain-2 checkpoint path is passed to `fast_semi`, which upstream supports.
|
| 119 |
+
- Each upstream dense output is re-encoded as CSR, verified bit-equal, and the dense `.npy` is deleted (its sha is kept).
|
| 120 |
+
- `sample_sc/*.h5ad` is deleted after a Giroux draw is exported and validated (its sha is in `prepared.json`).
|
| 121 |
+
8. **Adapter.** 1,500 cells per target and depth D, as above. The normalized output is not called raw counts.
|
| 122 |
+
|
| 123 |
+
## Validation done (CPU only; CUDA hidden throughout)
|
| 124 |
+
|
| 125 |
+
- `tests/test_adapter.py`: 6 unit tests pass (row rule, depth rule).
|
| 126 |
+
- **Ji draw 0 smoke** (2 representatives × 400 cells, 4 targets, epochs cut to 1–2; `smoke/ji2025_chili_draw0/`):
|
| 127 |
+
- inputs → upstream prepare (792 gene-set features) → pretrain and infer in two resumable calls each → export → independent validation (max deviation 1.5e-5) → `score_ft.py`.
|
| 128 |
+
- The scorer accepted the receipt (`receipt_verified=True`) and ran every metric, including the contrast/DEG path.
|
| 129 |
+
- The first export revealed that object-dtype `gene_ids` could not be loaded with `allow_pickle=False`. The exporter was fixed, and the failed output is kept under `generated/_failed_object_dtype_20260928/`.
|
| 130 |
+
- **Queue runner, CPU smoke mode** (`SMOKE_CPU=1`; `smoke/queue_test*.txt`): full control flow, chunked loops, export, validation, `clean_sample_sc`, scoring, and skip-on-rerun.
|
| 131 |
+
- **Memory stress and bit-identity of the prepare step:** see "Memory (measured)" below.
|
| 132 |
+
- **Cross-host equivalence.** The same Imperial smoke was run on server_1 (frozen `runtime_env`) and server_2 (new venv). Every artifact is bit-identical: inputs, prepared project, pretrain checkpoints, target shards, exported NPZ and scores. The run signature is the same.
|
| 133 |
+
|
| 134 |
+
## Code updates on running queues (`compat_migrations.json`)
|
| 135 |
+
|
| 136 |
+
A work dir's identity is the run signature it was created with, and every receipt is signed with it.
|
| 137 |
+
|
| 138 |
+
**Migrating a run to new code.** A later code version may continue a run only if:
|
| 139 |
+
- its binding differs from the run's latest binding only in `source` (the vendor manifest) and/or `wrapper_sha256`; and
|
| 140 |
+
- each change is an approved transition listed in `compat_migrations.json`.
|
| 141 |
+
|
| 142 |
+
The migration is then appended to `run_manifest.json`. New receipts carry `code_signature`, and the export receipt and metadata list the migrations. Any other difference refuses, as before.
|
| 143 |
+
|
| 144 |
+
**Deploy protocol.** Vendor files are replaced only under an exclusive lock on `.code_update.lock`, and the runner holds a shared lock while it verifies vendor hashes and imports the vendor. The 2026-09-28 deploy went in this order on both hosts:
|
| 145 |
+
1. transitions file;
|
| 146 |
+
2. atomic runner swap;
|
| 147 |
+
3. a ≥120 s wait, so calls started on the old runner are past their vendor import;
|
| 148 |
+
4. the vendor patch under the lock.
|
| 149 |
+
|
| 150 |
+
Live production dirs migrated cleanly on both hosts, with their identity kept.
|
| 151 |
+
|
| 152 |
+
## Environments
|
| 153 |
+
|
| 154 |
+
**server_1.** The frozen `plans/immicro_scsemi_comparison_20260927/runtime_env` is reused unmodified: a venv on `miniforge3/envs/scanvi` plus faiss-cpu, gseapy, igraph, texttable, requests and urllib3. It also takes certifi, charset_normalizer, regex and defusedxml from `~/.local`, as the frozen campaign did. `env_server1.json` has the details.
|
| 155 |
+
|
| 156 |
+
**server_2.** `scsemi/runtime_env` is built by `tools/prepare_env_server2.sh`. It uses the same base env path and versions, with every one of those packages pinned inside the venv, and runs with `PYTHONNOUSERSITE=1`. `runtime_env/scsemi_environment.json` has the details.
|
| 157 |
+
|
| 158 |
+
## Launch (coordinating agent only; GPU steps go through `ml-run` after `thermal_guard.sh` + `gpu_usable.sh`)
|
| 159 |
+
|
| 160 |
+
**server_1** (queue order: ji2025_chili, giroux2022, ye2026_sepsis, immicro; 5 draws each):
|
| 161 |
+
```bash
|
| 162 |
+
S=/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/plans/paired_finetune_intradataset_20260927/scsemi
|
| 163 |
+
systemd-run --user --unit=scsemi-queue-s1 --setenv=QUEUE=$S/queues/server1_fewshot.txt --setenv=SCORE=1 \
|
| 164 |
+
/bin/bash $S/tools/run_queue_scsemi.sh
|
| 165 |
+
```
|
| 166 |
+
|
| 167 |
+
**server_2** (Imperial; its data and outputs live there):
|
| 168 |
+
```bash
|
| 169 |
+
ssh spark-0110 'S=/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/plans/paired_finetune_intradataset_20260927/scsemi; \
|
| 170 |
+
systemd-run --user --unit=scsemi-queue-s2 --setenv=QUEUE=$S/queues/server2_fewshot.txt --setenv=SCORE=1 \
|
| 171 |
+
/bin/bash $S/tools/run_queue_scsemi.sh'
|
| 172 |
+
```
|
| 173 |
+
|
| 174 |
+
**Knobs:**
|
| 175 |
+
- `CHUNK_REPS` (2 representatives per GPU call) and `CHUNK_TARGETS` (12 targets per GPU call).
|
| 176 |
+
- `MAX_WAIT_H` (24).
|
| 177 |
+
- `PREP_ONLY=1`: CPU steps only.
|
| 178 |
+
- `PREP_MEM` (16): see the memory note.
|
| 179 |
+
|
| 180 |
+
**How the queue behaves:**
|
| 181 |
+
- It skips splits that are already exported and validated, and resumes partial splits from their receipts.
|
| 182 |
+
- A failure is logged; the split's outputs are kept with no retry, and the queue moves on.
|
| 183 |
+
- An unreceipted upstream artefact stops that split for inspection.
|
| 184 |
+
- Each split runs under `work/.../.split.lock`, so a `PREP_ONLY` CPU queue and the GPU queue can run at the same time safely.
|
| 185 |
+
|
| 186 |
+
**Logs and per-target runtime:**
|
| 187 |
+
- `logs/queue_*.log`
|
| 188 |
+
- `work/<ds>/fewshot_n5/draw<j>/{events.jsonl,gpu.log,shards/<target>.json}` (`elapsed_seconds`)
|
| 189 |
+
- the export receipt (`per_target`, `median_target_seconds`)
|
| 190 |
+
|
| 191 |
+
**Scoring.** With `SCORE=1`, `score_ft.py` runs on the draw's test donors with `contrast_args.sh`, output to `scores/<ds>/fewshot_n5/draw<j>_scsemi5/`. It uses the same donors and reference view as the draw's other arms, so the metrics are directly comparable.
|
| 192 |
+
|
| 193 |
+
## GPU-time estimate
|
| 194 |
+
|
| 195 |
+
Basis: the frozen campaign's measured timings on GB10:
|
| 196 |
+
- **Per target:** 37.1 s with 1,500 representative cells, i.e. 750 full-batch steps.
|
| 197 |
+
- **Pretraining:** 80.2 s for 1,500 cells, i.e. 11.1 ms per 128-cell step over 600 epochs.
|
| 198 |
+
|
| 199 |
+
How they scale:
|
| 200 |
+
- Pretraining scales with representative cells.
|
| 201 |
+
- The per-target range runs from 37 s (overhead-bound) to 37 s × (mean representative cells / 1,500) (data-bound). The inference batch is `min(n, 9000)`.
|
| 202 |
+
|
| 203 |
+
| dataset (5 draws) | targets | pretrain | targets | total GPU |
|
| 204 |
+
|---|---:|---:|---:|---:|
|
| 205 |
+
| ji2025_chili | 126 | 2.2 h | 1.3–3.3 h | 3.5–5.4 h |
|
| 206 |
+
| giroux2022 | 54 | 10.5 h | 0.6–4.1 h | 11.1–14.6 h |
|
| 207 |
+
| ye2026_sepsis | 385 | 2.6 h | 4.0–19.0 h | 6.6–21.6 h |
|
| 208 |
+
| immicro | 510 | 1.4 h | 5.3–13.0 h | 6.6–14.4 h |
|
| 209 |
+
| **server_1 total** | | | | **28–56 h** |
|
| 210 |
+
| imperial_eskd (server_2) | 715 | 3.0 h | 7.4–14.3 h | 10.4–17.3 h |
|
| 211 |
+
|
| 212 |
+
The Ji draw 0 receipts (`median_target_seconds`) will place the real per-target cost inside this range.
|
| 213 |
+
|
| 214 |
+
Load balancing: server_2 can take Giroux or sepsis once `data/<ds>/` and `scoring_cache/<ds>/` are rsynced there. At present it holds only Imperial and ImMicro.
|
| 215 |
+
|
| 216 |
+
## Disk and memory
|
| 217 |
+
|
| 218 |
+
### Memory (measured)
|
| 219 |
+
|
| 220 |
+
Upstream `scprocess`, called once over all representatives, is where memory runs out. It densifies every representative cell, keeps several dense n×n graph copies and an n×14×G gather per representative, and builds a cells×2,922 float64 gene-set matrix.
|
| 221 |
+
|
| 222 |
+
Measured at the 16 GiB CPU-unit cap:
|
| 223 |
+
- The largest Giroux representative (15,650 cells) was OOM-killed inside `fast_cellgraph`.
|
| 224 |
+
- The full Giroux draw 0 (149k representative cells) was OOM-killed at a 14.0 GiB peak in the cohort gene-set stage.
|
| 225 |
+
- The Imperial draws run with pure upstream code peaked at 8.5–13.4 GiB.
|
| 226 |
+
|
| 227 |
+
Two changes fix this:
|
| 228 |
+
- the lean cell graph (deviation 6);
|
| 229 |
+
- per-representative orchestration: the cohort `hvset` is computed first with upstream's own steps and order, then upstream `scprocess` runs once per representative.
|
| 230 |
+
|
| 231 |
+
Both reproduce upstream bit for bit, checked file by file on every prepared file (`validation/`):
|
| 232 |
+
- `prepared_imperial_upstream_vs_final.json`: 5 Imperial draws (70 representatives), final code vs **pure upstream**.
|
| 233 |
+
- `prepared_server1_oneshot_vs_perrep.json`: 15 Ji / sepsis / ImMicro draws, per-representative vs one-shot.
|
| 234 |
+
- `prepared_smoke_ji_upstream_vs_perrep.json`: smoke vs pure upstream.
|
| 235 |
+
- `lean_cellgraph_ji2025_chili_draw0.json`: function-level check on 8 representatives plus a synthetic case.
|
| 236 |
+
|
| 237 |
+
Peak RSS of the final prepare:
|
| 238 |
+
|
| 239 |
+
| dataset | peak RSS |
|
| 240 |
+
|---|---:|
|
| 241 |
+
| Ji | 2.9–4.1 GiB |
|
| 242 |
+
| sepsis | 3.8–6.3 GiB |
|
| 243 |
+
| ImMicro | 2.6–2.9 GiB |
|
| 244 |
+
| Imperial | 3.9–5.9 GiB |
|
| 245 |
+
| Giroux draw 0 | 11.6 GiB |
|
| 246 |
+
|
| 247 |
+
Giroux draws 1–4 have 128–156k representative cells, so a similar peak is expected. `PREP_MEM` (default 16) is the knob if one ever needs more; any value above 16 needs the coordinator's approval.
|
| 248 |
+
|
| 249 |
+
GPU steps (`ml-run`, `ml.slice`) hold a representative's dense graph a few times in host RAM: at most about 7 GB for the 15.6k-cell representative.
|
| 250 |
+
|
| 251 |
+
### Disk
|
| 252 |
+
|
| 253 |
+
**Prepared `scsemi_project/sample_sc/*.h5ad`** (dense n×n graphs):
|
| 254 |
+
|
| 255 |
+
| dataset | per draw |
|
| 256 |
+
|---|---:|
|
| 257 |
+
| Ji | 3 GB |
|
| 258 |
+
| ImMicro | 2 GB |
|
| 259 |
+
| sepsis | 5 GB |
|
| 260 |
+
| Giroux | 24 GB |
|
| 261 |
+
| Imperial | 4.5 GB |
|
| 262 |
+
|
| 263 |
+
Every server_1 queue line sets `clean_sample_sc`, so these are deleted once the draw is exported and validated. Their sha256 stays in `prepared.json`, and the files can be re-derived bit-identically.
|
| 264 |
+
|
| 265 |
+
**Other outputs:**
|
| 266 |
+
- Per-target upstream models: about 20 MB each, so ~22 GB on server_1 and ~14 GB on server_2.
|
| 267 |
+
- Lossless CSR target shards: about 2 % dense.
|
| 268 |
+
- Exported NPZs: compressed.
|
| 269 |
+
|
| 270 |
+
On 2026-09-28 server_1 had 190 GB free, with 73 GB already used by the 15 pre-prepared draws. Giroux draws 1–4 are prepared lazily by the queue, one at a time.
|
| 271 |
+
|
| 272 |
+
### Current state (2026-09-28, CPU only; no GPU step has run)
|
| 273 |
+
|
| 274 |
+
All splits of the few-pair campaign have been CPU-prepared (inputs + upstream prepare) under the final code, except Giroux draws 1–4:
|
| 275 |
+
- server_1: Ji 0–4, sepsis 0–4, ImMicro 0–4, Giroux 0.
|
| 276 |
+
- server_2: Imperial 0–4.
|
| 277 |
+
|
| 278 |
+
The GPU queues therefore start directly at pretraining; the queue prepares Giroux 1–4 on the way.
|
| 279 |
+
|
| 280 |
+
server_2's verified duplicate prepares, `work/_archive_prelean_20260928/` and `work/_archive_oneshot_lean_20260928/`, were removed on 2026-10-08 after validation. The completed Imperial fewshot draws 0–4 also had their re-derivable `sample_sc` files removed after all three exported output variants passed validation; their hashes remain in each draw's `prepared.json`. The active Imperial CV work was retained.
|
| 281 |
+
|
| 282 |
+
## Optional CV variant (`queues/server1_cv.txt`; not started)
|
| 283 |
+
|
| 284 |
+
- Representatives are every training donor of fold k, including inner-validation donors; targets are fold k's rows.
|
| 285 |
+
- The input builder, wrapper, exporter and queue already support `cv|DATASET|FOLD`.
|
| 286 |
+
- Output: `generated/<ds>/fold<k>/scsemi__raw.npz`.
|
| 287 |
+
|
| 288 |
+
**Cost.** Pretraining runs once per training row, so it dominates: the targets are only 1/5 of the rows. Same timing basis as above:
|
| 289 |
+
|
| 290 |
+
| dataset (5 folds) | representatives per fold | pretrain | targets | total GPU | largest prepared fold |
|
| 291 |
+
|---|---:|---:|---:|---:|---:|
|
| 292 |
+
| ji2025_chili | 25–27 | 7.3 h | 0.3–0.9 h | 7.7–8.2 h | 9 GiB |
|
| 293 |
+
| giroux2022 | 18–21 | 14.8 h | 0.2–1.7 h | 15.1–16.6 h | 29 GiB |
|
| 294 |
+
| ye2026_sepsis | 65–66 | 34.5 h | 0.8–4.0 h | 35.4–38.6 h | 53 GiB |
|
| 295 |
+
| immicro | 85–86 | 23.2 h | 1.1–2.7 h | 24.3–25.9 h | 25 GiB |
|
| 296 |
+
| **server_1 total** | | | | **82–89 h** | |
|
| 297 |
+
| imperial_eskd (server_2) | 110–133 | 30.4 h | 1.6–3.6 h | 32–34 h | 39 GiB |
|
| 298 |
+
|
| 299 |
+
That is about 3× the few-pair campaign. The memory note below applies to every fold, because every large training row becomes a representative.
|
| 300 |
+
|
| 301 |
+
## Files
|
| 302 |
+
|
| 303 |
+
- `tools/prepare_draw_inputs.py`: builds the split inputs (bulk.h5ad, rep_sc.h5ad, manifest).
|
| 304 |
+
- `tools/run_scsemi_paired.py`: the upstream wrapper (prepare / pretrain / infer / status).
|
| 305 |
+
- `tools/export_npz.py`: the adapter.
|
| 306 |
+
- `tools/validate_export.py`: independent validation of an exported NPZ.
|
| 307 |
+
- `tools/run_queue_scsemi.sh`: the queue runner.
|
| 308 |
+
- `tools/make_queues.sh`: writes the queue files.
|
| 309 |
+
- `tools/cpu_unit.sh`: CPU systemd unit, ≤ 6 threads, MemoryMax ≤ 16G, 32 GiB floor.
|
| 310 |
+
- `tools/lean_cellgraph.py`: output-identical `fast_cellgraph`.
|
| 311 |
+
- `tools/verify_lean_cellgraph.py`: function-level check of the lean cell graph.
|
| 312 |
+
- `tools/compare_prepared.py`: file-by-file comparison of prepared splits.
|
| 313 |
+
- `tools/compat_patch_20260928.py`: the size-1 trailing batch fix.
|
| 314 |
+
- `tools/scan_trailing_batch.py`: scans every representative for the size-1 batch condition.
|
| 315 |
+
- `tools/compare_runs.py`: bitwise comparison of trained artefacts between two work dirs.
|
| 316 |
+
- `compat_migrations.json`: approved code transitions.
|
| 317 |
+
- `tools/build_geneset_assets.py`: builds the gene-set asset.
|
| 318 |
+
- `tools/prepare_env_server2.sh`: builds the server_2 environment.
|
| 319 |
+
- `genesets/`: the mapped GMT and its manifest.
|
| 320 |
+
- `vendor/`: a copy of the frozen pinned upstream, hash-verified.
|
| 321 |
+
- `work/`: per-split runs.
|
| 322 |
+
- `smoke/`: CPU smoke runs.
|
| 323 |
+
- `validation/`: bit-identity records.
|
| 324 |
+
- `logs/`: logs.
|