Archive 4 checkpoints (1-4)
Browse files- paper-releases/pbisc-diffusion/updates/20261006T033406Z-bulkonly-lora5-k1000/diffusion/dataset/server_1/model8/plans/bulkonly_lora5_20261006/README.md +89 -0
- paper-releases/pbisc-diffusion/updates/20261006T033406Z-bulkonly-lora5-k1000/diffusion/dataset/server_1/model8/plans/bulkonly_lora5_20261006/tools/run_sampling.sh +70 -0
- paper-releases/pbisc-diffusion/updates/20261006T033406Z-bulkonly-lora5-k1000/diffusion/dataset/server_1/model8/plans/bulkonly_lora5_20261006/tools/share_r2.sh +121 -0
- paper-releases/pbisc-diffusion/updates/20261006T033406Z-bulkonly-lora5-k1000/diffusion/dataset/server_1/model8/plans/bulkonly_lora5_20261006/tools/split_conditions.py +75 -0
paper-releases/pbisc-diffusion/updates/20261006T033406Z-bulkonly-lora5-k1000/diffusion/dataset/server_1/model8/plans/bulkonly_lora5_20261006/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# LoRA-5 cells for bulk-only samples: Ye 2026 sepsis and Imperial ESKD COVID (2026-10-06)
|
| 2 |
+
|
| 3 |
+
**Request (user).** Generate cells with our LoRA-5 setting for the bulk samples that have no single-cell partner:
|
| 4 |
+
- Ye 2026 sepsis, 122 samples;
|
| 5 |
+
- Imperial ESKD COVID, 164 samples.
|
| 6 |
+
|
| 7 |
+
Then check whether new cell populations or biological findings can be found. These are the cohorts of the deck's
|
| 8 |
+
section 10 slide.
|
| 9 |
+
|
| 10 |
+
## Design
|
| 11 |
+
|
| 12 |
+
- **Models.** The five few-pair draws of `paired_finetune_intradataset_20260927`, unchanged.
|
| 13 |
+
- Each is the final f01 6k 1x E16 model plus LoRA r16 trained on the pairs of 5 donors for 3,000 steps (merged
|
| 14 |
+
`checkpoint_ft.pt`).
|
| 15 |
+
- The 5 draws use 5 different training donor sets, so every bulk-only sample gets 5 independent generations.
|
| 16 |
+
- Sepsis checkpoints are on server_1.
|
| 17 |
+
- Imperial checkpoints exist only on spark-0110, as archive files. They were copied to `ckpt_tmp/` (sha256 equal to
|
| 18 |
+
each RUN.json) to sample on server_1, because spark-0110's GPU was busy with another user's vLLM. The copies are
|
| 19 |
+
deleted after the Imperial sets.
|
| 20 |
+
- **Conditions** (`tools/build_conditions.py`; `data/<ds>/{bulkonly_raw.npz, bulkonly_meta.csv, BUILD.json}`).
|
| 21 |
+
- The bulk-only samples' raw counts come from the cohort's harmonized bulk h5ad.
|
| 22 |
+
- The arithmetic is the paired benchmark's own: `prepare_dataset.py` and `build_realbulk_conditions.py`, with
|
| 23 |
+
K = 1,000 and the fixed depth anchor.
|
| 24 |
+
- The cohort's sc measured-gene mask is the output availability. It is identical in every paired row.
|
| 25 |
+
- The same extraction applied to every paired row reproduces `features.npz` bulk and its `conditions_raw_fixed.npz`
|
| 26 |
+
byte for byte.
|
| 27 |
+
- Groups:
|
| 28 |
+
- sepsis: 68 adult sepsis, 36 adult HC, 17 adult ICU control, 1 paediatric ICU control;
|
| 29 |
+
- Imperial: 143 COVID+, 19 COVID−, 2 recovery (45 donors without any single cells).
|
| 30 |
+
- Bulk sex call ≠ metadata: HC23, HC30, Res-S34 (sepsis) and C137_positive_2 (Imperial). They are generated but
|
| 31 |
+
flagged.
|
| 32 |
+
- **Generation** (`tools/run_sampling.sh`).
|
| 33 |
+
- `utility_studies_final6k_20260925/tools/sample_queue.sh` with the benchmark's flags: EMA, DDIM 50, Bernoulli
|
| 34 |
+
read-out, batch 256, 1,500 cells per sample, seed 20260927.
|
| 35 |
+
- It runs through `ml-run` with `GATE=thermal`, sharing the GPU lock with the scSemiProfiler queue.
|
| 36 |
+
- Output: `generated/<ds>/draw<j>/lora5_bulkonly.npz` plus a receipt.
|
| 37 |
+
- **Labels and compact files.**
|
| 38 |
+
- `tools/annotate_bulkonly.py` uses the benchmark's Poisson read-out (seed 20260916, whole NPZ) and the frozen
|
| 39 |
+
f01common scANVI labels (six-type gate, AIFI L1/L2), with the cohort's scoring query genes.
|
| 40 |
+
- `tools/extract_paired.py` reduces two calibration sets to the same compact files (`tools/common.py`):
|
| 41 |
+
- each draw's paired TEST cells: the benchmark's own read-out and labels, checked cell by cell;
|
| 42 |
+
- the observed cells of every usable paired sample.
|
| 43 |
+
- Output: `work/<ds>/{bulkonly,paired_gen}/draw<j>/` and `work/<ds>/observed/`.
|
| 44 |
+
- **Features and trust layer** (`tools/features.py` → `analysis/features/<ds>/`).
|
| 45 |
+
- Per-sample cell-type composition (six types, AIFI L2) and rare-state fractions. The rules are those of
|
| 46 |
+
`rare_states_screen_20261004/tools/states.json`; observed marker states are thinned to the generated depth.
|
| 47 |
+
- A calibration table: on each draw's paired test samples, generated vs observed means, ratio, Spearman, and
|
| 48 |
+
whether every cohort contrast keeps its sign.
|
| 49 |
+
- A five-draw summary per bulk-only sample.
|
| 50 |
+
- **Analysis.** A multi-agent workflow (`analysis/wf/`, guide `analysis/DATA_GUIDE.md`).
|
| 51 |
+
- Lenses: clinical associations, within-type programs and candidate populations for each cohort, plus Imperial
|
| 52 |
+
trajectories.
|
| 53 |
+
- Two adversarial verifiers per finding: recompute + confounders, and calibration + biology + novelty.
|
| 54 |
+
- Then a synthesis report and a completeness review.
|
| 55 |
+
|
| 56 |
+
## Status (2026-10-06)
|
| 57 |
+
|
| 58 |
+
- **Generation and labelling: complete.**
|
| 59 |
+
- Sepsis: 5 draws × 183,000 cells. Imperial: 5 draws × 246,000 cells, each as two seed-equivalent row parts
|
| 60 |
+
(`tools/split_conditions.py`, after the single-file run was stopped for memory; `_archive/`).
|
| 61 |
+
- Calibration sets: paired-test generated cells of every draw and every usable paired sample's observed cells.
|
| 62 |
+
- Features: `analysis/features/<ds>/`.
|
| 63 |
+
- Sharing files: `share/` (10 h5ad, 1.31 GB; `MANIFEST.json`).
|
| 64 |
+
- **Imperial checkpoint copies** in `ckpt_tmp/` were deleted after the sampling. The spark-0110 originals were
|
| 65 |
+
re-verified by sha256 first (`ckpt_tmp/imperial_eskd/draw<j>/SOURCE.txt`).
|
| 66 |
+
- **Sepsis analysis** (`analysis/wf/REPORT_ye2026_sepsis.md`, `findings_ye2026_sepsis.json`; 41 agents).
|
| 67 |
+
- 18 candidate findings: 0 confirmed, 17 qualified, 1 refuted. No new population survived verification.
|
| 68 |
+
- The report ends with the completeness review. Its main cross-cutting points:
|
| 69 |
+
- shared per-cell noise across draws (one seed for all draws);
|
| 70 |
+
- the trust layer includes children while the analyses are adults-only;
|
| 71 |
+
- paired and bulk-only samples differ within groups in bulk (calibration transfer);
|
| 72 |
+
- a statsmodels quasi-binomial dispersion bug in some verifier p-values.
|
| 73 |
+
- These lessons were added to `analysis/DATA_GUIDE.md` before the Imperial run.
|
| 74 |
+
- **Imperial analysis** (`analysis/wf/REPORT_imperial_eskd.md`, `findings_imperial_eskd.json`; 48 agents).
|
| 75 |
+
- 21 candidate findings: 0 confirmed, 19 qualified, 2 refuted (CD8aa with severity; memory-B trajectory). No new
|
| 76 |
+
population survived.
|
| 77 |
+
- The traps it identified:
|
| 78 |
+
- wave imbalance between the bulk-only samples (88 % wave 1) and the paired truth;
|
| 79 |
+
- fresh-bulk granulocyte RNA turned into CD14 monocytes;
|
| 80 |
+
- interferon-linked labelling errors;
|
| 81 |
+
- a bug in `calibration.csv`: the severity contrast puts the 10 paired recovery samples in the severe arm
|
| 82 |
+
(corrected tables in `synthesis_imperial_eskd/i01_*`).
|
| 83 |
+
- The report ends with a completeness review. It lists 5 gated associations the report did not examine, e.g.
|
| 84 |
+
proliferating T cells rising in COVID+, which the bulk also carries.
|
| 85 |
+
- **Shared on Cloudflare R2** (`tools/share_r2.sh`; bucket `pbisc-data-private`, prefix
|
| 86 |
+
`shares/bulkonly_lora5_20261006/`; 52 objects, size-checked; presigned links valid until 2026-10-13 08:00 KST).
|
| 87 |
+
- Index: `share/INDEX_LINK.txt`; per-file links: `share/SHARE_LINKS.md`; sha256: `share/SHA256SUMS`.
|
| 88 |
+
- A three-file download test matched sha256. `LINKS_ONLY=1 bash tools/share_r2.sh` refreshes expired links.
|
| 89 |
+
- **K = 4,000 follow-up:** `plans/bulkonly_lora5_k4000_20261006` (user request, 2026-10-06).
|
paper-releases/pbisc-diffusion/updates/20261006T033406Z-bulkonly-lora5-k1000/diffusion/dataset/server_1/model8/plans/bulkonly_lora5_20261006/tools/run_sampling.sh
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# LoRA-5 generation for the bulk-only samples (2026-10-06, user request). One set = one cohort x one few-pair draw:
|
| 3 |
+
# the draw's LoRA r16 model (5 training donors, 3,000 steps; merged weights, the benchmark's checkpoint_ft.pt) samples
|
| 4 |
+
# 1,500 cells for every bulk-only sample from data/<ds>/bulkonly_raw.npz, with exactly the benchmark's sampler flags
|
| 5 |
+
# (utility_studies_final6k_20260925/tools/sample_queue.sh: EMA weights, DDIM 50, batch 256, Bernoulli support read-out,
|
| 6 |
+
# threshold 0, conditioner embedded) and the few-pair arm's seed 20260927.
|
| 7 |
+
# checkpoints: ye2026_sepsis paired_finetune_intradataset_20260927/runs/ye2026_sepsis/fewshot_n5/draw<j>/lora/
|
| 8 |
+
# imperial_eskd ckpt_tmp/imperial_eskd/draw<j>/ (sha-checked copies of spark-0110's archive files;
|
| 9 |
+
# deleted after the last Imperial set, see SOURCE.txt)
|
| 10 |
+
# every checkpoint's sha256 must equal its RUN.json checkpoint_sha256 (sample_queue.sh checks CKPT_SHA again)
|
| 11 |
+
# GPU: sample_queue.sh -> ml-run (ml.slice, shared lock), GATE=thermal: waits in the lock flock and interleaves with
|
| 12 |
+
# the scSemiProfiler queue; no two CUDA jobs overlap.
|
| 13 |
+
# out: generated/<ds>/draw<j>/lora5_bulkonly.npz + .log (receipt) + .err
|
| 14 |
+
# A set whose NPZ and receipt exist is skipped (rerun resumes). No retry of a failed set.
|
| 15 |
+
# usage: bash run_sampling.sh (run as a systemd user unit; it waits for the GPU)
|
| 16 |
+
set -uo pipefail
|
| 17 |
+
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
|
| 18 |
+
M8=/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion
|
| 19 |
+
P=$M8/plans/bulkonly_lora5_20261006
|
| 20 |
+
FT=$M8/plans/paired_finetune_intradataset_20260927
|
| 21 |
+
SQ=$M8/plans/utility_studies_final6k_20260925/tools/sample_queue.sh
|
| 22 |
+
SEED=20260927
|
| 23 |
+
LOG=$P/logs/run_sampling_$(date +%Y%m%dT%H%M%S).log
|
| 24 |
+
mkdir -p "$P/logs" "$P/queues"
|
| 25 |
+
log() { echo "$(date +%FT%T) $*" | tee -a "$LOG"; }
|
| 26 |
+
start=$(date +%s)
|
| 27 |
+
n_fail=0
|
| 28 |
+
for ds in ye2026_sepsis imperial_eskd; do
|
| 29 |
+
cond=$P/data/$ds/bulkonly_raw.npz
|
| 30 |
+
[[ -s $cond ]] || { log "ABORT: $cond missing"; exit 1; }
|
| 31 |
+
for j in 0 1 2 3 4; do
|
| 32 |
+
if [[ $ds == imperial_eskd ]]; then d=$P/ckpt_tmp/imperial_eskd/draw$j; else d=$FT/runs/$ds/fewshot_n5/draw$j/lora; fi
|
| 33 |
+
ck=$d/checkpoint_ft.pt
|
| 34 |
+
want=$(python3 -c "import json,sys;print(json.load(open(sys.argv[1]))['checkpoint_sha256'])" "$d/RUN.json")
|
| 35 |
+
out=$P/generated/$ds/draw$j/lora5_bulkonly.npz
|
| 36 |
+
q=$P/queues/${ds}_draw$j.txt
|
| 37 |
+
parts=$P/data/$ds/PARTS.json
|
| 38 |
+
if [[ -s $parts ]]; then
|
| 39 |
+
# row parts (tools/split_conditions.py): one queue line per part, seed shifted so every cell keeps its seed
|
| 40 |
+
python3 -c "
|
| 41 |
+
import json,sys
|
| 42 |
+
m=json.load(open(sys.argv[1]))
|
| 43 |
+
for p in m['parts']:
|
| 44 |
+
print('%s_bulkonly_d%s_part%d|%s/%s|%d|%s/lora5_bulkonly_part%d.npz' % (sys.argv[2], sys.argv[3], p['part'], sys.argv[4], p['file'], p['seed'], sys.argv[5], p['part']))
|
| 45 |
+
" "$parts" "$ds" "$j" "$P/data/$ds" "$P/generated/$ds/draw$j" > "$q"
|
| 46 |
+
done_all=1
|
| 47 |
+
while IFS='|' read -r _ _ _ o; do [[ -s $o && -s ${o%.npz}.log ]] || done_all=0; done < "$q"
|
| 48 |
+
if (( done_all )); then log "$ds draw$j: all parts done already; skipped"; continue; fi
|
| 49 |
+
out=$(tail -1 "$q" | cut -d'|' -f4)
|
| 50 |
+
else
|
| 51 |
+
echo "${ds}_bulkonly_d${j}|$cond|$SEED|$out" > "$q"
|
| 52 |
+
if [[ -s $out && -s ${out%.npz}.log ]]; then log "$ds draw$j: done already; skipped"; continue; fi
|
| 53 |
+
fi
|
| 54 |
+
systemctl --user is-active --quiet ml-memory-guard.service || { log "ABORT: memory guard inactive"; exit 1; }
|
| 55 |
+
log "$ds draw$j: sampling with $ck (sha ${want:0:12})"
|
| 56 |
+
if CKPT=$ck CKPT_SHA=$want QUEUE=$q GATE=thermal MAX_WAIT_H=48 bash "$SQ" >> "$LOG" 2>&1 && [[ -s ${out%.npz}.log ]]; then
|
| 57 |
+
while IFS='|' read -r _ _ _ o; do
|
| 58 |
+
log "$ds draw$j: $(basename "$o") $(python3 -c "import json,sys;d=json.load(open(sys.argv[1]));print('bulks', d.get('bulks'), 'zero_frac %.4f' % d.get('generated_zero_fraction', -1), 'sha', d.get('output_sha256','')[:12])" "${o%.npz}.log")"
|
| 59 |
+
done < "$q"
|
| 60 |
+
else
|
| 61 |
+
n_fail=$((n_fail+1)); log "WARN: $ds draw$j failed (see ${out%.npz}.err)"
|
| 62 |
+
fi
|
| 63 |
+
# host policy: after a memory-guard stop of ml.slice, inspect before any further GPU step
|
| 64 |
+
if journalctl -t ml-memory-guard --since "@$start" --no-pager 2>/dev/null | grep -q "stopping ml.slice"; then
|
| 65 |
+
log "ABORT: memory guard stopped ml.slice; no further sets"; exit 1
|
| 66 |
+
fi
|
| 67 |
+
done
|
| 68 |
+
done
|
| 69 |
+
log "all sets attempted; failed=$n_fail"
|
| 70 |
+
(( n_fail == 0 ))
|
paper-releases/pbisc-diffusion/updates/20261006T033406Z-bulkonly-lora5-k1000/diffusion/dataset/server_1/model8/plans/bulkonly_lora5_20261006/tools/share_r2.sh
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# Share one version of the bulk-only LoRA-5 cells through Cloudflare R2 links (2026-10-06, user request).
|
| 3 |
+
# bucket pbisc-data-private (private; existing bucket-scoped object read/write key, rclone remote pbisc_r2 in
|
| 4 |
+
# /home/sj_server_1/PBISC/r2-staging/rclone-r2.conf -- the key is never printed)
|
| 5 |
+
# prefix shares/<plan directory name>/
|
| 6 |
+
# README.md, MANIFEST.json, <ds>/*.h5ad, <ds>/samples.csv share/ of the plan (tools/package_share.py)
|
| 7 |
+
# analysis/REPORT_<ds>.md, findings_<ds>.json, DATA_GUIDE.md, features/<ds>/calibration.csv
|
| 8 |
+
# analysis/analysis_bundle.tar.gz the whole analysis tree (features, every agent's scripts and tables)
|
| 9 |
+
# raw_npz/<ds>/draw<j>/*.npz + .log the sampler's outputs and receipts (RAW=1 only)
|
| 10 |
+
# SHA256SUMS sha256 of every shared object (computed locally before upload)
|
| 11 |
+
# links presigned GET URLs (S3 SigV4, at most 7 days), one per object, written to share/SHARE_LINKS.md and an
|
| 12 |
+
# index.html that is uploaded and linked itself. LINKS_ONLY=1 refreshes expired links without uploading.
|
| 13 |
+
# Upload check: rclone check --one-way --size-only of every uploaded tree; links are made only after it passes.
|
| 14 |
+
# env: PLAN (default: this plan), RAW (1), EXPIRE (168h), TITLE, BUNDLE_EXCLUDE (extra tar excludes)
|
| 15 |
+
set -Eeuo pipefail
|
| 16 |
+
P=${PLAN:-/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/plans/bulkonly_lora5_20261006}
|
| 17 |
+
NAME=$(basename "$P")
|
| 18 |
+
RC=/home/sj_server_1/.local/bin/rclone
|
| 19 |
+
CF=/home/sj_server_1/PBISC/r2-staging/rclone-r2.conf
|
| 20 |
+
R=pbisc_r2:pbisc-data-private/shares/$NAME
|
| 21 |
+
RAW=${RAW:-1}
|
| 22 |
+
EXPIRE=${EXPIRE:-168h}
|
| 23 |
+
TITLE=${TITLE:-Bulk-only LoRA-5 cells: Ye 2026 sepsis and Imperial ESKD COVID}
|
| 24 |
+
mkdir -p "$P/logs"
|
| 25 |
+
LOG=$P/logs/share_r2_$(date +%Y%m%dT%H%M%S).log
|
| 26 |
+
log() { echo "$(date +%FT%T) $*" | tee -a "$LOG"; }
|
| 27 |
+
ARGS=(--config "$CF" --transfers 8 --checkers 16 --s3-upload-cutoff 128Mi --s3-chunk-size 64Mi
|
| 28 |
+
--s3-upload-concurrency 4 --retries 10 --low-level-retries 20 --retries-sleep 10s --stats 60s
|
| 29 |
+
--stats-one-line --log-file "$LOG" --log-level NOTICE)
|
| 30 |
+
EXCL=(--exclude 'SHARE_LINKS.md' --exclude 'index.html' --exclude 'INDEX_LINK.txt')
|
| 31 |
+
STAGE=$P/share_stage
|
| 32 |
+
SUMS=$STAGE/SHA256SUMS
|
| 33 |
+
if [[ "${LINKS_ONLY:-0}" != 1 ]]; then
|
| 34 |
+
rm -rf "$STAGE"; mkdir -p "$STAGE/analysis/features"
|
| 35 |
+
# ---- analysis: key documents one by one, everything else in one bundle (per-cell work products stay local)
|
| 36 |
+
for f in "$P"/analysis/wf/REPORT_*.md "$P"/analysis/wf/findings_*.json "$P"/analysis/DATA_GUIDE.md; do
|
| 37 |
+
[[ -s $f ]] && cp "$f" "$STAGE/analysis/"
|
| 38 |
+
done
|
| 39 |
+
for d in "$P"/analysis/features/*/; do
|
| 40 |
+
ds=$(basename "$d"); mkdir -p "$STAGE/analysis/features/$ds"; cp "$d/calibration.csv" "$STAGE/analysis/features/$ds/"
|
| 41 |
+
done
|
| 42 |
+
# K = 4,000 plan: benchmark against K = 1,000 and the calibration comparison, one file each
|
| 43 |
+
for f in "$P"/analysis/benchmark/*/AGGREGATE.md "$P"/analysis/benchmark/*/per_draw.csv \
|
| 44 |
+
"$P"/analysis/compare_k1000/*/SUMMARY.md "$P"/analysis/compare_k1000/*/per_feature.csv; do
|
| 45 |
+
[[ -s $f ]] || continue
|
| 46 |
+
rel=${f#"$P"/}; mkdir -p "$STAGE/$(dirname "$rel")"; cp "$f" "$STAGE/$rel"
|
| 47 |
+
done
|
| 48 |
+
cp "$P/README.md" "$STAGE/analysis/PLAN_README.md"
|
| 49 |
+
# BUNDLE_EXCLUDE: extra tar --exclude patterns separated by spaces (e.g. an analysis still running); tar exit 1 =
|
| 50 |
+
# a file changed while read (a running analysis), accepted
|
| 51 |
+
read -r -a bex <<< "${BUNDLE_EXCLUDE:-}"
|
| 52 |
+
extra=(); [[ -d $P/scores ]] && extra+=(scores) # benchmark scores (K = 4,000 plan), without per-cell arm files
|
| 53 |
+
tar -czf "$STAGE/analysis/analysis_bundle.tar.gz" -C "$P" --warning=no-file-changed --exclude='__pycache__' \
|
| 54 |
+
--exclude='*.npz' --exclude='*.h5ad' --exclude='scores/*/*/arms' "${bex[@]/#/--exclude=}" \
|
| 55 |
+
analysis README.md tools "${extra[@]}" || [[ $? -eq 1 ]]
|
| 56 |
+
log "staged analysis: $(du -sh "$STAGE/analysis" | cut -f1)"
|
| 57 |
+
# ---- sha256 of every object to share, keyed by its path under the prefix
|
| 58 |
+
: > "$SUMS"
|
| 59 |
+
(cd "$P/share" && find . -type f ! -name SHARE_LINKS.md ! -name index.html ! -name INDEX_LINK.txt -printf '%P\n' \
|
| 60 |
+
| sort | xargs -r -d '\n' sha256sum) >> "$SUMS"
|
| 61 |
+
(cd "$STAGE" && find analysis -type f -printf '%P\n' | sed 's|^|analysis/|' | sort | xargs -r -d '\n' sha256sum) >> "$SUMS"
|
| 62 |
+
if [[ $RAW == 1 ]]; then
|
| 63 |
+
(cd "$P/generated" && find . -path ./_failed -prune -o -type f \( -name '*.npz' -o -name '*.log' \) -printf '%P\n' \
|
| 64 |
+
| sort | xargs -r -d '\n' sha256sum | sed 's| | raw_npz/|') >> "$SUMS"
|
| 65 |
+
fi
|
| 66 |
+
cp "$SUMS" "$P/share/SHA256SUMS"
|
| 67 |
+
log "sha256 of $(wc -l < "$SUMS") objects -> SHA256SUMS"
|
| 68 |
+
# ---- uploads, each checked by size
|
| 69 |
+
log "uploading share/"
|
| 70 |
+
"$RC" copy "$P/share" "$R" "${ARGS[@]}" "${EXCL[@]}"
|
| 71 |
+
"$RC" check "$P/share" "$R" --config "$CF" --one-way --size-only "${EXCL[@]}" >> "$LOG" 2>&1
|
| 72 |
+
log "uploading analysis/"
|
| 73 |
+
"$RC" copy "$STAGE/analysis" "$R/analysis" "${ARGS[@]}"
|
| 74 |
+
"$RC" check "$STAGE/analysis" "$R/analysis" --config "$CF" --one-way --size-only >> "$LOG" 2>&1
|
| 75 |
+
if [[ $RAW == 1 ]]; then
|
| 76 |
+
log "uploading raw NPZs"
|
| 77 |
+
RF=(--filter '- _failed/**' --filter '+ *.npz' --filter '+ *.log' --filter '- *')
|
| 78 |
+
"$RC" copy "$P/generated" "$R/raw_npz" "${ARGS[@]}" "${RF[@]}"
|
| 79 |
+
"$RC" check "$P/generated" "$R/raw_npz" --config "$CF" --one-way --size-only "${RF[@]}" >> "$LOG" 2>&1
|
| 80 |
+
fi
|
| 81 |
+
log "all uploads checked (sizes)"
|
| 82 |
+
fi
|
| 83 |
+
# ---- presigned links for every object under the prefix (sha256 from SHA256SUMS)
|
| 84 |
+
[[ -s $P/share/SHA256SUMS ]] || { log "no SHA256SUMS; run without LINKS_ONLY first"; exit 1; }
|
| 85 |
+
log "making presigned links (expire $EXPIRE)"
|
| 86 |
+
mapfile -t objs < <("$RC" lsf -R --files-only --config "$CF" "$R" | grep -v -x 'index.html' | sort)
|
| 87 |
+
expires_at=$(date -d "+${EXPIRE%h} hours" '+%Y-%m-%d %H:%M %Z')
|
| 88 |
+
sizes=$("$RC" lsjson -R --files-only --config "$CF" "$R")
|
| 89 |
+
md=$P/share/SHARE_LINKS.md
|
| 90 |
+
html=$P/share/index.html
|
| 91 |
+
{
|
| 92 |
+
echo "# $TITLE: share links"
|
| 93 |
+
echo
|
| 94 |
+
echo "Presigned Cloudflare R2 links, valid until **$expires_at** (7 days). Start with README.md."
|
| 95 |
+
echo
|
| 96 |
+
echo "| file | size | sha256 (first 16) | link |"
|
| 97 |
+
echo "|---|---:|---|---|"
|
| 98 |
+
} > "$md"
|
| 99 |
+
{
|
| 100 |
+
echo '<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">'
|
| 101 |
+
echo "<title>$TITLE</title><style>body{font-family:system-ui,sans-serif;margin:24px auto;max-width:1000px;padding:0 16px}"
|
| 102 |
+
echo 'table{border-collapse:collapse;width:100%}td,th{padding:4px 8px;border-bottom:1px solid #ddd;text-align:left;font-size:14px}'
|
| 103 |
+
echo 'td.s{text-align:right;white-space:nowrap}td.h{font-family:monospace;font-size:12px;color:#555}</style></head><body>'
|
| 104 |
+
echo "<h1>$TITLE</h1>"
|
| 105 |
+
echo "<p>Presigned Cloudflare R2 links, valid until <b>$expires_at</b>. Start with <code>README.md</code>. Full sha256 of every file: <code>SHA256SUMS</code>.</p>"
|
| 106 |
+
echo "<table><tr><th>file</th><th>size</th><th>sha256 (first 16)</th></tr>"
|
| 107 |
+
} > "$html"
|
| 108 |
+
for o in "${objs[@]}"; do
|
| 109 |
+
url=$("$RC" link --expire "$EXPIRE" --config "$CF" "$R/$o")
|
| 110 |
+
sz=$(python3 -c "import json,sys;d={x['Path']:x['Size'] for x in json.loads(sys.stdin.read())};s=d.get(sys.argv[1],0);print(f'{s/1e9:.2f} GB' if s>=1e8 else f'{s/1e6:.1f} MB' if s>=1e5 else f'{s/1e3:.0f} kB')" "$o" <<< "$sizes")
|
| 111 |
+
h=$(awk -v o="$o" '$2 == o {print substr($1, 1, 16)}' "$P/share/SHA256SUMS")
|
| 112 |
+
echo "| \`$o\` | $sz | \`${h:-–}\` | [download]($url) |" >> "$md"
|
| 113 |
+
echo "<tr><td><a href=\"$url\">$o</a></td><td class=s>$sz</td><td class=h>${h:-–}</td></tr>" >> "$html"
|
| 114 |
+
done
|
| 115 |
+
echo "</table></body></html>" >> "$html"
|
| 116 |
+
"$RC" copyto "$html" "$R/index.html" --config "$CF" --header-upload "Content-Type: text/html; charset=utf-8"
|
| 117 |
+
index_url=$("$RC" link --expire "$EXPIRE" --config "$CF" "$R/index.html")
|
| 118 |
+
echo "$index_url" > "$P/share/INDEX_LINK.txt"
|
| 119 |
+
chmod 600 "$P/share/INDEX_LINK.txt" "$md" "$html"
|
| 120 |
+
code=$(curl -s -o /dev/null -w '%{http_code}' "$index_url")
|
| 121 |
+
log "index uploaded; HTTP $code; ${#objs[@]} files linked; links valid until $expires_at"
|
paper-releases/pbisc-diffusion/updates/20261006T033406Z-bulkonly-lora5-k1000/diffusion/dataset/server_1/model8/plans/bulkonly_lora5_20261006/tools/split_conditions.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Split a bulk-only condition NPZ into parts so one sampler call fits in memory (CPU only; 2026-10-06).
|
| 3 |
+
|
| 4 |
+
Why: sample_sdd_standalone.py keeps five full output arrays (log1p, counts, logits, two masks) and then checks them in
|
| 5 |
+
float64; for Imperial (164 samples x 1,500 cells x 6,000 genes) that peaked near 70 GB before the check and would have
|
| 6 |
+
crossed the memory guard during it, so the first Imperial set was stopped (by the coordinator) before its check.
|
| 7 |
+
Each part is the same NPZ restricted to a contiguous row range; every per-row key is sliced, the rest is copied.
|
| 8 |
+
Seeds: the sampler draws cell c of bulk row i with seed + i * 10,000,019 + c (support draw: + 7,919). A part that
|
| 9 |
+
starts at row r0 is therefore sampled with seed + r0 * 10,000,019, which gives every cell exactly the seed it gets in
|
| 10 |
+
the unsplit file: the split output equals the unsplit run up to GPU kernel non-determinism.
|
| 11 |
+
Writes data/<ds>/bulkonly_raw_part<k>.npz and data/<ds>/PARTS.json (row ranges, seeds, sha256).
|
| 12 |
+
usage: CUDA_VISIBLE_DEVICES='' split_conditions.py DATASET N_PARTS [--seed 20260927]
|
| 13 |
+
"""
|
| 14 |
+
from __future__ import annotations
|
| 15 |
+
|
| 16 |
+
import argparse
|
| 17 |
+
import hashlib
|
| 18 |
+
import json
|
| 19 |
+
import os
|
| 20 |
+
import sys
|
| 21 |
+
from pathlib import Path
|
| 22 |
+
|
| 23 |
+
if os.environ.get("CUDA_VISIBLE_DEVICES") != "":
|
| 24 |
+
raise SystemExit("run with CUDA_VISIBLE_DEVICES=''")
|
| 25 |
+
|
| 26 |
+
import numpy as np
|
| 27 |
+
|
| 28 |
+
PLAN = Path(__file__).resolve().parents[1]
|
| 29 |
+
ROW_STRIDE = 10_000_019 # sample_sdd_standalone.py: cell_seed = seed + index * 10_000_019 + cell
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def sha(p: Path) -> str:
|
| 33 |
+
h = hashlib.sha256()
|
| 34 |
+
with open(p, "rb") as f:
|
| 35 |
+
for b in iter(lambda: f.read(1 << 24), b""):
|
| 36 |
+
h.update(b)
|
| 37 |
+
return h.hexdigest()
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def main(argv=None) -> int:
|
| 41 |
+
ap = argparse.ArgumentParser()
|
| 42 |
+
ap.add_argument("dataset")
|
| 43 |
+
ap.add_argument("n_parts", type=int)
|
| 44 |
+
ap.add_argument("--seed", type=int, default=20260927)
|
| 45 |
+
a = ap.parse_args(argv)
|
| 46 |
+
src = PLAN / "data" / a.dataset / "bulkonly_raw.npz"
|
| 47 |
+
# our own file, written by build_conditions.py through prepare_dataset.write_npz: donor_ids / groups are object
|
| 48 |
+
# arrays there, exactly as in the benchmark's conditions_raw_fixed.npz (the sampler never reads them)
|
| 49 |
+
d = np.load(src, allow_pickle=True)
|
| 50 |
+
n = int(d["sample_ids"].shape[0])
|
| 51 |
+
per_row = [k for k in d.files if d[k].ndim >= 1 and d[k].shape[0] == n and k != "gene_ids"]
|
| 52 |
+
edges = np.linspace(0, n, a.n_parts + 1).round().astype(int)
|
| 53 |
+
parts = []
|
| 54 |
+
for k in range(a.n_parts):
|
| 55 |
+
r0, r1 = int(edges[k]), int(edges[k + 1])
|
| 56 |
+
out = src.with_name(f"bulkonly_raw_part{k}.npz")
|
| 57 |
+
arrs = {key: (d[key][r0:r1] if key in per_row else d[key]) for key in d.files}
|
| 58 |
+
np.savez(out, **arrs)
|
| 59 |
+
chk = np.load(out, allow_pickle=True)
|
| 60 |
+
for key in d.files:
|
| 61 |
+
want = d[key][r0:r1] if key in per_row else d[key]
|
| 62 |
+
if not np.array_equal(chk[key], want):
|
| 63 |
+
raise SystemExit(f"{out.name}: {key} differs after writing")
|
| 64 |
+
parts.append({"part": k, "rows": [r0, r1], "n_samples": r1 - r0, "file": out.name, "sha256": sha(out),
|
| 65 |
+
"seed": int(a.seed + r0 * ROW_STRIDE),
|
| 66 |
+
"first_sample": str(d["sample_ids"][r0]), "last_sample": str(d["sample_ids"][r1 - 1])})
|
| 67 |
+
man = {"source": str(src), "source_sha256": sha(src), "n_rows": n, "per_row_keys": per_row,
|
| 68 |
+
"row_stride": ROW_STRIDE, "base_seed": a.seed, "tool_sha256": sha(Path(__file__)), "parts": parts}
|
| 69 |
+
(src.parent / "PARTS.json").write_text(json.dumps(man, indent=1) + "\n")
|
| 70 |
+
print(json.dumps(parts, indent=1))
|
| 71 |
+
return 0
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
if __name__ == "__main__":
|
| 75 |
+
sys.exit(main())
|