scVI 21618 problem

I found a strange problem when using scVI to remove batch effects. It report a “ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 128])” when I deal with totally 21618 cells with 3 batches. However, this problem disappears if I just remove any one cells from the whole dataset. I also tried more cells in one dataset and it works well. However, if I just remove some cells and keep 21618 cells left, the problem comes again. It seems the problem just comes with 21618 cells. I also tried both GPU and CPU and just got the same result. I don’t understand this problem

Hi, sorry you’re running into this issue. This is because the batch normalization layer in scVI requires more than one observation in a mini-batch to work properly, and the specific number of observations in your dataset is leading to the last mini-batch having only one cell.

This can be fixed by changing batch_size from the default of 128 to something else, or passing in drop_last=True to the datasplitter.

Thanks for your answer.