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

[Perl] Sparse feature.#9988

Merged
sergeykolychev merged 9 commits intoapache:masterfrom
sergeykolychev:sparse_feature
Mar 6, 2018
Merged

[Perl] Sparse feature.#9988
sergeykolychev merged 9 commits intoapache:masterfrom
sergeykolychev:sparse_feature

Conversation

@sergeykolychev
Copy link
Contributor

@sergeykolychev sergeykolychev commented Mar 5, 2018

Description

Added support for sparse tensors to Perl API

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)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • 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

  • Sparse tensors support in Perl API

Comments

@eric-haibin-lin
Please check out this for sanity, it all works afaik but I may have missed something really recent.

@sergeykolychev
Copy link
Contributor Author

@tlby Rob, please take a look, thanks!

Copy link
Contributor

@tlby tlby left a comment

Choose a reason for hiding this comment

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

not quite finished reading yet, but I'll wrap up soon. So far, so good though. Nice!

epsilon => $self->epsilon,
rescale_grad => $self->rescale_grad
);
use Data::Dumper;
Copy link
Contributor

Choose a reason for hiding this comment

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

debugging cruft?

Copy link
Contributor Author

@sergeykolychev sergeykolychev Mar 6, 2018

Choose a reason for hiding this comment

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

yes, will remove, thanks for noticing.

(blessed $label and $label->isa('AI::MXNet::NDArray::CSR')))
and
($self->last_batch_handle != 'discard')
)
Copy link
Contributor

Choose a reason for hiding this comment

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

"and" and "or" at the same indent depth?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, wrong indentation, will fix.

$class;
}

sub not_implemented { confess "Not implemented" }
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps "..." is appropriate here? it's kinda standard for declaring abstract functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please elaborate

Copy link
Contributor

Choose a reason for hiding this comment

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

from the perl docs:

When Perl 5.12 or later encounters an ellipsis statement, it parses this without error, but if and when you should actually try to execute it, Perl throws an exception with the text Unimplemented

That seems to be highly aligned the Python source such as https://github.com/apache/incubator-mxnet/blob/0fe04e9d778ac9c55e933ff3f21c4ddf28a4a101/python/mxnet/ndarray/sparse.py#L118 as a pattern for the abstract methods subclasses must provide.

Your code isn't wrong, it's just reimplementing a feature the core language already has.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks man, there's a lot about Perl I still don't know.

}

use B;
sub hash { hex(B::hash(shift)) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Careful with this, remember the hash produced will vary from one run to the next.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I know, it's the same with Python's hash() call, so it's a feature.

svs[i] = newSViv((*$1)[i]);
sv_2mortal(svs[i]);
}
myav = av_make(*arg4, svs);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you can guarantee that "arg4" will be a stable variable name for the other parameter in the function that uses this typemap, so this might blow up at some time in the future, but I'll pester you elsewhere for more details.

Copy link
Contributor Author

@sergeykolychev sergeykolychev Mar 6, 2018

Choose a reason for hiding this comment

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

I went with this solution because I needed to solve a peculiar problem of making a decision dependent on a particular input state.
You helped me in the past to clean up the swig usage, could you please see if you can come up with a solution later in separate pull that is more stable (I used this technique in another place as well in the past).

Copy link
Contributor

Choose a reason for hiding this comment

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

okay, sure. I'll get more details and work out a proposal.

@sergeykolychev sergeykolychev merged commit 2a9c7d9 into apache:master Mar 6, 2018
int delay_alloc,
int dtype,
NDArrayHandle *out);
/*!
Copy link
Member

Choose a reason for hiding this comment

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

Does this file have to be updated when c_api is changed each time? Is this not automated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It may look like it could be automated but it can not.
It's not just a copy/paste from the c_api.h, it's a SWIG interface file and the variables names are changed to denote a way of how they should be treated to make c api to communicate with perl.
Another file called mxnet_typemaps.i in the dir has actual glue code that depends on the vars.
It's just another version of 'ctypes' .

}
}

sub test_row_sparse_pull
Copy link
Member

Choose a reason for hiding this comment

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

Does it include the test case added a few days ago https://github.com/apache/incubator-mxnet/pull/9887/files ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I added that test.


=head2 slice

Returns a sliced view of this array.
Copy link
Member

Choose a reason for hiding this comment

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

The documentation is wrong.. Should be a copy instead of a view. I'll post a PR to fix it (in both perl and python).

Copy link
Member

Choose a reason for hiding this comment

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

See #10034

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks!

jinhuang415 pushed a commit to jinhuang415/incubator-mxnet that referenced this pull request Mar 30, 2018
* sparse feature.

* moved myself to the list of commiters.

* changed ImperativeInvoke to ImperativeInvokeEx.

* updated MNIFEST

* addressed code review

* recent python's kvstore sparse changes.

* using PDL.

* fix docs, trigger tests.
rahul003 pushed a commit to rahul003/mxnet that referenced this pull request Jun 4, 2018
* sparse feature.

* moved myself to the list of commiters.

* changed ImperativeInvoke to ImperativeInvokeEx.

* updated MNIFEST

* addressed code review

* recent python's kvstore sparse changes.

* using PDL.

* fix docs, trigger tests.
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this pull request Jun 28, 2018
* sparse feature.

* moved myself to the list of commiters.

* changed ImperativeInvoke to ImperativeInvokeEx.

* updated MNIFEST

* addressed code review

* recent python's kvstore sparse changes.

* using PDL.

* fix docs, trigger tests.
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.

3 participants