Dali: question about fill_last_batch and last_batch_padded

Created on 25 Sep 2019  路  4Comments  路  Source: NVIDIA/DALI

Hi, thank you very much for your contribution. Could you please help me with the following problems?

I don't understand the fill_last_batch in the DALIClassificationIterator after reading the document.
E.g. I have a data A=[1,2,3,4,5,6,7], and self_num_gpus =1 self.batch_size=2 .
Without shuffle for clarity.

  1. From my understanding, if fill_last_batch = True, the last time returned is on [7] which is a fraction of the full batch;
    If fill_last_batch = False, it the last time returned is [7, x] which is a full batch. But I don't what x is.
  1. For last_batch_padded.
    last_batch_padded=True and fill_last_batch = False, the last batch is [7, 1];
    last_batch_padded=False and fill_last_batch = False, the last batch is [7, ?] ?
    If fill_last_batch=True, the last_batch_padded will be ignored.

Do my understandings right?
Thanks!

question

Most helpful comment

I think it is a typo. It should be the opposite:

 If set to False next epoch will end sooner as data from it was consumed but dropped. If set to True next epoch would be the same length as the first one.

As padding will prevent from premature consuming data from the next epoch.
@awolant - could you post a fix to this typo?

All 4 comments

Hi,
fill_last_batch tells if the last batch should be full-sized or not. In case of MXNet it uses pad field of DataBatch to tell that this data is dummy, in case of PyTorch output tensor is just smaller in size. When last_batch_padded is set to False DALI still internally consumes a full batch of data wrapping up the data set. It means it takes some samples from the next epoch but drops it at the Python level to provide the batch you asked for (with smaller size). If you set last_batch_padded to True, DALI internally will not consume data from the next epoch but pad samples with the cloned value of the last one and then drop it.

So in your case:

  1. fill_last_batch = False, last_batch_padded = True - [7], next iteration will return [1, 2]
  2. fill_last_batch = False, last_batch_padded = False - [7], next iteration will return [2, 3]
  3. fill_last_batch = True, last_batch_padded = True - [7, 7], next iteration will return [1, 2]
  4. fill_last_batch = True, last_batch_padded = False - [7, 1], next iteration will return [2, 3]

If you experiencing something else let us know because it is not expected.

Thank you very much for your help.

In the case 4.
fill_last_batch = True, last_batch_padded = False - [7, 1], next iteration will return [2, 3]
which is the default set of the DALIClassificationIterator, my understanding from the source code is same as your answer.

What confused me is the DALIClassificationIterator docs here, in which the last_batch_padded is explained as If set to false next epoch would be the same length as the first one. However, in the case 4, the next epoch will not be the same length as the first one.

Is there a docs bug or something I understand wrong? @awolant @JanuszL

I think it is a typo. It should be the opposite:

 If set to False next epoch will end sooner as data from it was consumed but dropped. If set to True next epoch would be the same length as the first one.

As padding will prevent from premature consuming data from the next epoch.
@awolant - could you post a fix to this typo?

As issue is reported as https://github.com/NVIDIA/DALI/issues/1311, closing this one.

Was this page helpful?
0 / 5 - 0 ratings