Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[BUG FIX] Always preserve batch dimension in batches returned from dataloader #16233

Merged
merged 7 commits into from
Nov 7, 2019

Conversation

fierceX
Copy link
Contributor

@fierceX fierceX commented Sep 21, 2019

Description

When multi-process is enabled, when the last batch size is 1, there will be no batch size in the shape of the last returned data.

I deleted a line of code and I don't know why there is this line of code.
I have no problem after I delete it.

E.g:

import mxnet as mx
import numpy as np
from mxnet.gluon.data import ArrayDataset,DataLoader

data = np.ones((1,11,12))
print(data.shape)
new_data =  ArrayDataset(data)
dataloader = gluon.data.DataLoader(new_data,batch_size=1024,last_batch='keep',num_workers=2)
for d in dataloader:
    print(d.shape)

output:

(1, 11, 12)
(11, 12)

import mxnet as mx
import numpy as np
from mxnet.gluon.data import ArrayDataset,DataLoader

data = np.ones((1,11,12))
print(data.shape)
new_data =  ArrayDataset(data)
dataloader = gluon.data.DataLoader(new_data,batch_size=1024,last_batch='keep')
for d in dataloader:
    print(d.shape)

output:

(1, 11, 12)
(1, 11, 12)

import mxnet as mx
import numpy as np
from mxnet.gluon.data import ArrayDataset,DataLoader

data = np.ones((1025,11,12))
print(data.shape)
new_data =  ArrayDataset(data)
dataloader = gluon.data.DataLoader(new_data,batch_size=1024,last_batch='keep',num_workers=2)
for d in dataloader:
    print(d.shape)

output:

(1025, 11, 12)
(1024, 11, 12)
(11, 12)

import mxnet as mx
import numpy as np
from mxnet.gluon.data import ArrayDataset,DataLoader

data = np.ones((1,11,12))
print(data.shape)
new_data =  ArrayDataset(data)
dataloader = gluon.data.DataLoader(new_data,batch_size=1024,last_batch='keep')
for d in dataloader:
    print(d.shape)

output:

(1025, 11, 12)
(1024, 11, 12)
(1, 11, 12)

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http:https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

@fierceX fierceX requested a review from szha as a code owner September 21, 2019 09:11
@eric-haibin-lin
Copy link
Member

@zhreshold was this intentional??

Copy link
Member

@zhreshold zhreshold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original intention is to remove list if the output is a single number, i.e., [1] -> 1.
I would like to approve this PR since consistency is more important in this case.

@leezu
Copy link
Contributor

leezu commented Sep 24, 2019

@fierceX please update the PR title to make clearer what bug is fixed by this PR. Then people may discover the change more easily in the changelog. Perhaps clarify that this is backwards incompatible change.
For example, "[BUGFIX] Always preserve batch dimension in batches returned from dataloader" (though you may come up with something better)

@fierceX fierceX changed the title Fix dataloader bug [BUGFIX] Always preserve batch dimension in batches returned from dataloader Sep 24, 2019
Copy link
Member

@eric-haibin-lin eric-haibin-lin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add an unit test for the output shape??

@szha szha changed the title [BUGFIX] Always preserve batch dimension in batches returned from dataloader [BUG FIX] Always preserve batch dimension in batches returned from dataloader Nov 4, 2019
@szha szha merged commit d967be9 into apache:master Nov 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants