SOLO/scVI .train() error related to batch_size?

I am getting this error when i run vae.train() ultimately for SOLO

“ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 128])”

I found a few posts on github, but i’m too daft to understand how to apply this to my code

Here’s a snapshot of my code:

    sample = sc.read_10x_mtx(mapped_data_location, cache = True)
    bdata = sample.copy()

    sc.pp.filter_genes(bdata, min_cells = 10)
    sc.pp.filter_cells(bdata, min_genes = 3)
    sc.pp.highly_variable_genes(bdata, n_top_genes = 2000, subset = True, flavor = 'seurat_v3')
    vae = scvi.model.SCVI(bdata)

Ah yes, my guess is that this is occurring because the size of your dataset modulo the default batch size (128) is 1, so the last minibatch during an epoch only has one cell. Thus, the batch norm layer is complaining since it can’t compute normalization statistics on just one observation.

The simplest fix for this would be to be pass in some batch size other than 128 to train. Hope this helps!

That worked, thanks!!

1 Like