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

[MXNET-123] Bug fix for sparse batch loader #10124

Merged
merged 1 commit into from
Mar 27, 2018

Conversation

eric-haibin-lin
Copy link
Member

@eric-haibin-lin eric-haibin-lin commented Mar 15, 2018

Description

Reopen #8922

The previous implementation of sparse batch loader waits for the number of data instances reaches batch_size before allocating the buffer for copy (unlike dense batch loader, we don't know the actual buffer size to allocate since the number of non-zeros varies). However, such delayed allocate is buggy when batch size is extremely large, because the DataInst returned by base_ is only a reference to the data. By the time copy happens, the referenced data might already be updated by the parser.

This PR modifies the sparse batch loader to be almost the same as batch loader, except that:

  • data buffer is allocated based on estimation, and adjusted when capacity is not sufficient
  • before returning the output, the shape of tensor has to reflect the actual number of elements in the tensor.

@cjolivier01 @reminisce @anirudh2290 @ZiyueHuang

Checklist

Essentials

  • Passed code style checking (make lint)
  • 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
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

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

@eric-haibin-lin eric-haibin-lin changed the title [WIP][DO NOT MERGE] Bug fix for libsvm iter [MXNET-123] Bug fix for sparse batch loader Mar 22, 2018
@eric-haibin-lin
Copy link
Member Author

@rahul003 @cjolivier01 @reminisce @haojin2 could anyone help review?

int64_t unit_size = 0;
out_.inst_index[top] = inst.index;
for (size_t i = 0; i < inst.data.size(); ++i) {
if (!IsIndPtr(i)) {
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this will be called for every element in each batch. But the isindptr result for each i between different batches should be the same correct ? Does it make sense to cache this ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm good suggestion! I'll cache this

* fix a bug in sparse batch loader

* fix warning

* fix bug when size=0

* cache is indptr
@eric-haibin-lin eric-haibin-lin merged commit e08e1fd into apache:master Mar 27, 2018
jinhuang415 pushed a commit to jinhuang415/incubator-mxnet that referenced this pull request Mar 30, 2018
* fix a bug in sparse batch loader

* fix warning

* fix bug when size=0

* cache is indptr
cjolivier01 pushed a commit to cjolivier01/mxnet that referenced this pull request Mar 30, 2018
@eric-haibin-lin eric-haibin-lin deleted the iter branch May 9, 2018 18:06
rahul003 pushed a commit to rahul003/mxnet that referenced this pull request Jun 4, 2018
* fix a bug in sparse batch loader

* fix warning

* fix bug when size=0

* cache is indptr
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this pull request Jun 28, 2018
* fix a bug in sparse batch loader

* fix warning

* fix bug when size=0

* cache is indptr
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants