Skip to content

Commit

Permalink
Fix minibatch size problem in SOLO
Browse files Browse the repository at this point in the history
  • Loading branch information
nictru committed Jan 30, 2024
1 parent e0b8d3f commit 67cf364
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions modules/solo.nf
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,21 @@ process SOLO {
results = []
batch_sizes = adata.obs["batch"].value_counts()
batches = "${batches.join(" ")}".split(" ")
for batch in batches:
# If only one cell is assigned to a minibatch, solo will crash
# https://discuss.pytorch.org/t/error-expected-more-than-1-value-per-channel-when-training/26274
batch_size = batch_sizes[batch]
default_minibatch_size = 128
minibatch_size_correction = -1 if batch_size % default_minibatch_size == 1 else 0
solo = scvi.external.SOLO.from_scvi_model(scvi_model, restrict_to_batch=batch)
solo.train(batch_size=default_minibatch_size + minibatch_size_correction)
minibatch_size = 128
worked = False
while not worked and minibatch_size > 100:
try:
solo.train(batch_size=minibatch_size)
worked = True
except ValueError:
print("Minibatch size did not work, trying again with smaller minibatch size")
minibatch_size -= 1
pass
batch_res = solo.predict()
batch_res["doublet_label"] = solo.predict(False)
Expand Down

0 comments on commit 67cf364

Please sign in to comment.