Skip to content

Commit 0a0174d

Browse files
authored
make novel_predict actually use the gpu it asks for (#54)
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.
1 parent 0659ffa commit 0a0174d

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333
## BUG FIXES
3434

35-
* `cellmapper_scvi`: Bump the base image from `openproblems/base_pytorch_nvidia:1.0.0` to `:1`. (PR #53).
36-
3735
* `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).
3836

3937
* 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).
@@ -58,6 +56,10 @@
5856

5957
* `simple_mlp`: Drop the `input_transform` key from the `simple_mlp_predict` call, which is not an argument of that component (PR #44).
6058

59+
* `cellmapper_scvi`: Bump the base image from `openproblems/base_pytorch_nvidia:1.0.0` to `:1`. (PR #53).
60+
61+
* `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).
62+
6163
# task_predict_modality 0.1.1
6264

6365
## NEW FUNCTIONALITY

src/methods/novel/novel_predict/script.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,13 @@
9595
dataloader_test = DataLoader(dataset_test, 32, shuffle = False, num_workers = 4)
9696

9797
outputs = []
98+
# the weights are loaded with map_location='cpu', so move the model onto the device
99+
# we selected above -- otherwise this component requests a GPU and never uses it
100+
model = model.to(device)
98101
model.eval()
99102
with torch.no_grad():
100103
for x in dataloader_test:
101-
output = model(x.float())
104+
output = model(x.float().to(device))
102105
outputs.append(output.detach().cpu().numpy())
103106

104107
outputs = np.concatenate(outputs)

0 commit comments

Comments
 (0)