From 2cc69b80e7b6b6eb391b769a1411426f60d0b8c0 Mon Sep 17 00:00:00 2001 From: Robrecht Cannoodt Date: Thu, 30 Jul 2026 08:43:19 +0200 Subject: [PATCH] make novel_predict actually use the gpu it asks for It sets device = 'cuda:0' when one is available and then never references it: the weights load with map_location='cpu' and the model is never moved, so inference runs on CPU while holding a GPU node. --- CHANGELOG.md | 2 ++ src/methods/novel/novel_predict/script.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e107b8bb..d2c255ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,8 @@ ## BUG FIXES +* `novel_predict`: Move the model and the input batch onto the selected device. It picked `cuda:0` when a GPU was present but never used it, so the component requested a GPU node and ran inference on CPU (PR #54). + * `process_dataset`: Fall back to holding out a quarter of the batches when the dataset has no `obs["is_train"]`, rather than silently producing four empty h5ads. `obs["is_train"]` carries the NeurIPS 2021 competition split and stays optional; `obs["cell_type"]` is now declared and required (PR #28). * Fix the component paths, build paths and `rename_keys` separator in the helper scripts, which prevented `scripts/create_datasets/test_resources.sh` and both `run_test.sh` scripts from running at all (PR #22). diff --git a/src/methods/novel/novel_predict/script.py b/src/methods/novel/novel_predict/script.py index d5c25dfe..cbc47b77 100644 --- a/src/methods/novel/novel_predict/script.py +++ b/src/methods/novel/novel_predict/script.py @@ -95,10 +95,13 @@ dataloader_test = DataLoader(dataset_test, 32, shuffle = False, num_workers = 4) outputs = [] +# the weights are loaded with map_location='cpu', so move the model onto the device +# we selected above -- otherwise this component requests a GPU and never uses it +model = model.to(device) model.eval() with torch.no_grad(): for x in dataloader_test: - output = model(x.float()) + output = model(x.float().to(device)) outputs.append(output.detach().cpu().numpy()) outputs = np.concatenate(outputs)