Batch grouping

I was wondering, is there are way to use some kind of grouping to organize batches. Specifically, I have some training data that for different training data sets have slightly different number of samples, but there tends be be just a few different groups of these, so I would like the data loader to put together batches with data from only one group. Not sure if that is possible with fastai?

It should be possible to do, but can you explain your reasoning for grouping similar datasets together? As a rule of thumb models tend to train better when there is a nice amount of randomness in the examples it is trained on.

Yes, would definitely prefer not to group them together. But in this case my data is a bunch of multi-dimensional arrays (you can think of them as images) but depending on the dataset they are not exactly the same dimensions. Unlike an image qualification problem though, they cannot be cropped. So I need to work with all the data for each training set. When looking at the data, they do tend to group together, i.e. there is a limited set of common sizes, so let’s say I have some that are [132, 132], some are [134,134], etc. I want to make batches only from the ones that have the same dimensions so that the tensors stack up. Does that make sense?