Skip to content

Commit fad21b4

Browse files
committed
Update harmonypy to use PyTorch GPU backend
- Switch Docker image to base_pytorch_nvidia:1.0.0 - Pin harmonypy>=0.2.0 and add torch dependency - Pass device=None to run_harmony for auto GPU detection - Remove epsilon workaround as harmonypy v0.2.0 handles numerical stability internally via clamping and L2 normalisation - Update Nextflow label to lowcpu, gpu - Update CHANGELOG.md
1 parent f9c9cd2 commit fad21b4

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@
8181
* iLISI is now computed per biological group. Groups where batch is fully confounded by group are skipped and return NaN.
8282
* Added `helper.py` with `compute_ilisi_per_group` and `compute_clisi` functions.
8383

84+
* Updated `methods/harmonypy` to use the PyTorch GPU backend (harmonypy>=0.2.0):
85+
* Switched Docker image to `openproblems/base_pytorch_nvidia:1.0.0`.
86+
* Added `device=None` to `run_harmony` for automatic GPU detection (CUDA -> MPS -> CPU).
87+
* Removed epsilon workaround as numerical stability is now handled internally by harmonypy.
88+
* Updated Nextflow label to `lowcpu, gpu`.
89+
8490
* Updated file schema (PR #18):
8591
* Add is_control obs to indicate whether a cell should be used as control when correcting batch effect.
8692
* Removed donor_id obs from unintegrated censored.

src/methods/harmonypy/config.vsh.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ resources:
2222

2323
engines:
2424
- type: docker
25-
image: openproblems/base_python:1
25+
image: openproblems/base_pytorch_nvidia:1.0.0
2626
setup:
2727
- type: python
2828
packages:
29-
- harmonypy
29+
- harmonypy>=0.2.0
30+
- torch
3031

3132
runners:
3233
- type: executable
3334
- type: nextflow
3435
directives:
35-
label: [midtime,midmem,midcpu]
36+
label: [midtime,midmem,lowcpu,gpu]

src/methods/harmonypy/script.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@
3030

3131
print("Run harmony", flush=True)
3232

33-
# TODO numerical instability in kmeans causing problem with harmony.
34-
# so adding a very small value to all entries to make sure there are no zeros
35-
epsilon = 1e-20
36-
33+
# device=None lets harmonypy auto-detect the best available backend:
34+
# CUDA GPU -> Apple MPS -> CPU
3735
out = harmonypy.run_harmony(
38-
data_mat=adata_to_correct.layers["preprocessed"] + epsilon,
36+
data_mat=adata_to_correct.layers["preprocessed"],
3937
meta_data=adata_to_correct.obs,
4038
vars_use="batch_str",
39+
device=None,
4140
)
4241

4342
# have to add in the uncorrected markers as well

0 commit comments

Comments
 (0)