Skip to content

Split one SpatialData store across GPUs in run_inference_flash.py - #28

Open
rushin682 wants to merge 1 commit into
mainfrom
worktree-lightning-sharded-inference
Open

rushin682 wants to merge 1 commit into
mainfrom
worktree-lightning-sharded-inference

Conversation

@rushin682

Copy link
Copy Markdown
Collaborator

What

run_inference_flash.py can now split a single store across several GPUs with Lightning DDP.

  • --devices N / --num-nodes M, launched with one SLURM task per GPU (srun --ntasks-per-node=N).
  • 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, so ranks do not share noise.
  • Progress is a tqdm bar (Lightning's default Rich bar prints nothing to a log file until the store is done).
  • FlowPipeline.__call__ is split into sample_batch and denormalize so the Lightning path reuses the sampling code. __call__ is unchanged; a new test pins it to those two.

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

  • With N > 1 the values are not bitwise equal to a 1-GPU run: each cell gets different noise and batches hold different cells. The difference is the size of a seed change (numbers 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 (the other ranks would hang). Stores that already have a pred_table are skipped, so a rerun resumes.
  • The SLURM script is not in this PR (scripts/*.sbatch is gitignored). It needs --gpu-bind=none so each task sees all four GPUs.

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, 243 cells, batch size 16, mean |Δ|:

    Comparison mean |Δ|
    --devices 1 vs old script 0 (bitwise, default and --fast)
    4 GPUs vs 1 GPU, seed 0 / seed 1 0.183 / 0.182
    seed 1 vs seed 0, 1 GPU 0.188

    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.

## 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-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 48.25%. Comparing base (e96e260) to head (1d93b38).

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              
Files with missing lines Coverage Δ
src/phoenix/helpers/inference.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants