Repository navigation
Conversation
## What `run_inference_flash.py` can now shard each store over several GPUs with Lightning DDP (`--devices N`, `--num-nodes M`; one SLURM task per GPU). Each rank predicts every N-th cell; rank 0 gathers the rows, restores table order and writes the `pred_table` with the existing code, so the table format is the same for 1 and N GPUs. Each rank seeds with `seed + rank`. The Rich progress bar is replaced by tqdm, which writes lines to a log file. `FlowPipeline.__call__` is split into `sample_batch` and `denormalize` so the Lightning path reuses the sampling code. `__call__` itself is unchanged. A new test pins `__call__` to those two. ## Why A store with ~800k cells takes more than 24 h on one GPU, past the QoS wall clock. The per-store queue cannot help with a single slide. **With N > 1 values are not bitwise equal to 1 GPU**: each cell gets different noise and batches contain different cells. The difference is the size of a seed change (see below). With one device the output is bitwise identical to the previous script. With several devices a failed store aborts the job instead of being skipped. ## Tested - `pytest tests`: 47 passed, 2 failed (`test_models.py` `llama3_forward`, `mixer_autoencoder_roundtrip`, CUDA errors on the GPU-less login node; not re-run on a GPU). - `prek` hooks on the changed files: all pass. - H100 node, 243-cell store, batch size 16: `--devices 1` is bitwise equal to the old script (default and `--fast`); 4 GPUs vs 1 GPU gives mean |d| 0.183 / 0.182 (seed 0 / 1), against 0.188 for seed 1 vs 0 on 1 GPU; table format identical. - 56,510-cell store, 4 x H100: 1838 s vs 7191 s on 1 GPU (3.9x), format identical, mean |d| 0.153.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #28 +/- ##
==========================================
+ Coverage 48.20% 48.25% +0.05%
==========================================
Files 10 10
Lines 1029 1030 +1
==========================================
+ Hits 496 497 +1
Misses 533 533
🚀 New features to boost your workflow:
|
Three self-contained sbatch scripts in slurm_scripts/, each one job on a 4-GPU dc-hwai node, replacing the per-node bash helpers: - run_inference.sbatch / run_inference_flash.sbatch: one store per GPU, 4 at a time, one `srun` step per store (1 GPU, 16 cores, 120G). When a step ends, the next store (largest first) takes its GPU. - run_inference_flash_ddp.sbatch: stores run one after another, each split over all 4 GPUs with `--devices 4`. All three write one log per store, list failed stores in failed.txt and exit non-zero if any failed. A failed DDP store no longer aborts the job. `.gitignore` now only ignores the local bash helpers; run_inference.py docstrings point at the new location. Tested on H100 with 4-8 small stores: 8 stores refill 4 GPUs in both per-GPU scripts, DDP steps run sequentially on 4 GPUs, all exit 0. The failure path (failed.txt, non-zero exit) was not exercised.
The progress-bar comment said the tqdm bar appends a line per update. Under `srun` that is only true with `srun -u`: tqdm redraws one line with '\r' and ends it when the bar closes, and srun holds output back until a newline. Document that and how to read such a log. Comment only; no code change.
…t the DDP sbatch `SpatialDataset.native_mpp` now reads `source_he_mpp` for stores whose `spatialdata_io_reader` is `visium`, as for `he`: both sit on the H&E pixel grid with identity transforms. Previously a visium store fell through to the shape-scale fallback and got the wrong pixel size. A visium store without `source_he_mpp` raises, like the other readers. `run_inference_flash_ddp.sbatch` is now a SLURM array (default `--array=0-3%4`). Stores are sorted by size and dealt round-robin to the tasks, and SDATA_DIR may be a glob. Tests: added a visium case to test_datasets.py (pixel size and the missing-attribute error). Not run before committing.
…erence_flash.py The Lightning DDP version of run_inference_flash.py now lives in scripts/run_inference_flash_ddp.py, and run_inference_flash.py is back to the main version (#24) apart from a docstring fix. The one-store- per-GPU path stays a plain script without Lightning, which is easier to read, and DDP is opt-in for slides too large for one GPU. The code is copied, not shared; only the docstring, logger name and CLI description of the DDP script changed. run_inference_flash_ddp.sbatch calls the new script. The docstring of run_inference_flash.py pointed at the removed inference_node.sh; it now points at slurm_scripts/run_inference_flash.sbatch and the DDP script. Tested: prek hooks pass; `hatch test tests/test_inference.py tests/test_datasets.py` 31 passed on CPU (login node), including the visium cases from the previous commit. Neither sbatch has been rerun on a GPU node since the split; run_inference_flash.sbatch now drives the Rich progress bar of the main script, whose output under `srun -u` into a log file has not been checked.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
scripts/run_inference_flash_ddp.pysplits a single store across several GPUs with Lightning DDP.run_inference.pyandrun_inference_flash.pystay the simple one-store-per-process scripts from #24 (only a docstring changes), so the multi-GPU path is opt-in and the single-GPU path has no Lightning dependency.--devices N/--num-nodes M, launched with one SLURM task per GPU (srun --ntasks-per-node=N).pred_tablein the same format asrun_inference_flash.py.seed + rank, so ranks do not share noise.FlowPipeline.__call__is split intosample_batchanddenormalizeso the Lightning path reuses the sampling code instead of copying it.__call__is unchanged; a new test pins it to those two.The DDP script is a copy of
run_inference_flash.pywith the Lightning parts added, rather than importing from it, so each script reads on its own.SpatialDataset.native_mppnow readssource_he_mppfor stores whosespatialdata_io_readerisvisium, as forhe(both are on the H&E pixel grid with identity transforms). Before, a visium store fell through to the shape-scale fallback and got the wrong pixel size; a visium store withoutsource_he_mppnow raises like the other readers.slurm_scripts/adds three self-contained sbatch scripts for 4-GPUdc-hwainodes. Each writes one log per store, lists failed stores infailed.txtand exits non-zero if any failed.run_inference.sbatchrun_inference.pyrun_inference_flash.sbatchrun_inference_flash.pyrun_inference_flash_ddp.sbatchrun_inference_flash_ddp.py --devices 4--array=0-3%4); stores sorted by size and dealt round-robin to the tasks, each task runs its stores one after another, each split over all 4 GPUsThe per-GPU scripts launch one
srunstep per store (1 GPU, 16 cores, 120G), so no bash helper is needed. The DDP script needs--gpu-bind=noneso each task sees all four GPUs, and accepts a glob forSDATA_DIR..gitignorenow ignores only the localslurm_scripts/*.shhelpers.Why
A store with ~800k cells takes more than 24 h on one GPU, past the QoS wall clock, and the per-store queue cannot help with a single slide.
Heads-up
--devices 1the output is bitwise identical torun_inference_flash.py.native_mppfix changes predictions for visium stores (their patches are now cut at the correct pixel size). Outputs forxeniumandhestores are unchanged.srunstep, so the store is logged infailed.txtand the job moves on. Stores that already have apred_tableare skipped, so a rerun resumes.account=hai_1240,partition=dc-hwaiand defaultREPO/VENVpaths; overrideREPO/VENVwith--export.Tested
pytest tests(before the split): 47 passed, 2 failed (test_models.py:llama3_forward,mixer_autoencoder_roundtrip; CUDA errors on the GPU-less login node, not re-run on a GPU).hatch test tests/test_inference.py tests/test_datasets.pyafter the split, CPU: 31 passed, including the visium cases.prekhooks on the changed files: all pass.H100, 243 cells, batch size 16, mean |Δ| (measured with the DDP code before it moved to its own file; the code is unchanged):
--devices 1vsrun_inference_flash.py--fast)Table format (dtype, shape,
obs,var,obsm["spatial"],uns["spatialdata_attrs"]) is identical.56,510 cells, 4 × H100: 1838 s vs 7191 s on 1 GPU (3.9×). Format identical, mean |Δ| 0.153.
sbatch scripts, 4-8 small stores (210-243 cells) on one H100 node: with 8 stores both per-GPU scripts run 4 at a time and refill a GPU as each step ends; the DDP script runs its stores one after another on 4 GPUs. All jobs exit 0 and every store gets a
pred_table.Not yet run: the sbatch scripts since the split into
run_inference_flash_ddp.py, the DDP sbatch as an array, and the failure path (failed.txt, non-zero exit).🤖 Generated with Claude Code