Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ReorderLoDTensorByRank #6789

Merged
merged 5 commits into from
Dec 22, 2017

Conversation

reyoung
Copy link
Collaborator

@reyoung reyoung commented Dec 20, 2017

It is useful to reorder RNN memory block.

@reyoung reyoung added this to the Release 0.11.1 milestone Dec 20, 2017
@reyoung reyoung force-pushed the feature/add_reorder_lod_tensor branch from fe473f9 to 70236b6 Compare December 20, 2017 10:30
AddInput("RankTable",
"(LoDRankTable) the rank table that input need follow");
AddOutput("Out", "(LoDTensor) reordered lod tensor");
AddComment(R"DOC(ReorderLoDTensorLoDRankTable
Copy link
Contributor

Choose a reason for hiding this comment

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

ReorderLoDTensorLoDRankTable --> ReorderLoDTensorByRankTable

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

index [3, 0, 2, 1]. Input X will reorder its sequence, the third sequence of
X will be the first sequence of Output.

NOTE: The RankTable does not need to be calculated by X.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please give a specific example to make things easier to understand.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

namespace paddle {
namespace operators {

class ReorderLoDTensorProtoMaker : public framework::OpProtoAndCheckerMaker {
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to change to ReorderLoDTensorByRankTableProtoMaker ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.



def reorder_lod_tensor_by_rank(x, rank_table):
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Please refine the doc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we could use python to generate the docstring.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

size_t out_offset = 0;
out->mutable_lod()->clear();
for (auto &item : rank_table.items()) {
out_offset = this->CopyTensorAndLod(dev_ctx, absolute_table[item.index],
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add some assert to make sure absolute_table[item.index] valid

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done


out.Resize(x.dims());
out.mutable_data(x.place(), x.type());
this->process(dev_ctx, x, rank_table, &out);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please make sure the size of rank_table and size of x' lod is match.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It will be checked during Tensor::Slice.



class TestReorderLoDTensor(unittest.TestCase):
def test_reorder(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add Gradient test

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It has been tested, since IG.sum() == 1 and LoD can be restored.

It is useful to reorder RNN memory block.
@reyoung reyoung force-pushed the feature/add_reorder_lod_tensor branch from 70236b6 to b23982a Compare December 21, 2017 04:27
pkuyym
pkuyym previously approved these changes Dec 22, 2017
Copy link
Contributor

@pkuyym pkuyym left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@pkuyym pkuyym left a comment

Choose a reason for hiding this comment

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

Great Job, Thx.

@reyoung reyoung merged commit ca82fd2 into PaddlePaddle:develop Dec 22, 2017
@reyoung reyoung deleted the feature/add_reorder_lod_tensor branch December 26, 2017 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants