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

Initialize large table value randomly #9787

Merged
merged 10 commits into from
Apr 13, 2018

Conversation

Yancey1989
Copy link
Contributor

@Yancey1989 Yancey1989 commented Apr 9, 2018

Fixed #9777
issue: #9211

@Yancey1989 Yancey1989 changed the title Random selected rows value Initialize large table value randomly Apr 10, 2018
// Only allocate the memory of large table on CPU
auto cpu = platform::CPUPlace();
float *data = tensor->mutable_data<float>(cpu);
VLOG(3) << "generate seed";
Copy link
Contributor

Choose a reason for hiding this comment

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

VLOGs not needed.

auto tensor = out->mutable_value();
tensor->Resize(framework::make_ddim(shape));
// Only allocate the memory of large table on CPU
auto cpu = platform::CPUPlace();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to enforce that dev_place is on CPU?

for (int64_t idx = 1; idx < rows_size; ++idx) {
(*rows)[idx] = (*rows)[idx - 1] + shard_cnt;
}
out->set_height(max_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed offline, with @Yancey1989 @jacquesqiao , need to implement this using an auto-growth SelectedRows, and init it randomly with a startup init buffer size, like 128M. This feature may also need to implement operations that when "Prefetch" runs.

Copy link
Member

@jacquesqiao jacquesqiao Apr 11, 2018

Choose a reason for hiding this comment

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

When lookup table op find that some id is not in the rows of the table, it should push this new id to the table.rows to init it.

Copy link
Contributor Author

@Yancey1989 Yancey1989 Apr 11, 2018

Choose a reason for hiding this comment

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

@jacquesqiao Yes, and I have an offline discussion with @typhoonzero, maybe we need a new class to represent the Table, and I create an issue #9841 for the details if you also agree with that, I will create a new PR to implement it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FROM @typhoonzero

and init it randomly with a startup init buffer size, like 128M

We have already had an attribute shape to represent the shape of the SelectedRows.value(), maybe we can only use the shape to determinate the memory size, use shape and memory size at the same time may be confused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And maybe we resue uniform_random_op, they have the same computing logic.

tensor->Resize(framework::make_ddim(shape));
// Only allocate the memory of large table on CPU
auto cpu = platform::CPUPlace();
float *data = tensor->mutable_data<float>(cpu);
Copy link
Member

Choose a reason for hiding this comment

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

This float should be a template

auto shape = Attr<std::vector<int>>("shape");

auto tensor = out->mutable_value();
tensor->Resize(framework::make_ddim(shape));
Copy link
Member

Choose a reason for hiding this comment

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

The first dimension of the tensor is not sure, should be calculated by some attribute, such as id_num / shard_cnt + buffer_size. Do you mean that this calculation is done in Python ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean that this calculation is done in Python

I think so, but as the discussion just now #9787 (comment), I will update this PR according to it.

@Yancey1989
Copy link
Contributor Author

@jacquesqiao @typhoonzero
I updated this PR and allocate an initialize buffer by the attribute shape, and then we need to refine lookup_table_op to re-allocate the Table's memory if new Id was coming and not enough memory.

I created an issue #9841 and will implement it ASAP.

tensor = out_var->GetMutable<framework::SelectedRows>()->mutable_value();
tensor->Resize(framework::make_ddim(shape));
} else {
PADDLE_THROW("Only support SelectedRows and Tensor");
Copy link
Contributor

Choose a reason for hiding this comment

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

uniform_random_op's output only support...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -24,7 +24,17 @@ template <typename T>
class CPUUniformRandomKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext& ctx) const override {
auto* tensor = ctx.Output<framework::Tensor>("Out");
framework::Tensor* tensor(nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

framework::Tensor *tensor = nullptr;

@jacquesqiao jacquesqiao mentioned this pull request Apr 12, 2018
15 tasks
@Yancey1989 Yancey1989 merged commit 41a9146 into PaddlePaddle:develop Apr 13, 2018
@Yancey1989 Yancey1989 deleted the random_selected_rows_value branch April 13, 2018 08:12
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.

3 participants