fairseq icon indicating copy to clipboard operation
fairseq copied to clipboard

Distributed training on tiny debug dataset with n_data < N_GPUs * batch_size fails silently due to unset dummy batch

Open msdejong opened this issue 6 years ago • 1 comments

The EpochBatchIterator uses empty lists as a fill value for the ShardedIterator used for distributed training. Normally this is handled by replacing the empty list by a dummy batch in Trainer.train_step, which in turn is set as the first batch the Trainer ever sees. However, if you're debugging distributed training with a mini dataset of size n_data < N_GPUs * batch_size, some Trainers will receive an empty list as their first ever batch and feed it straight to the model, which then breaks.

The breaking part is of course fine, all that's needed is to reduce batch size or increase dataset size, but if you're not familiar with the FairSeq internals (as was the case for me when this originally happened) this can be rather an opaque problem to debug, especially since distributed training tends to be challenging to debug already.

I'd suggest explicitly raising an exception with a suggestive error message if the dummy batch is none or empty when sample is none in Trainer.train_step.

To Reproduce

Run any distributed training command on data with n_data < N_GPUs * batch_size

msdejong avatar Feb 20 '20 20:02 msdejong

Great idea, this is a known problem but I like your proposed solution

myleott avatar Feb 21 '20 14:02 myleott