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

feature/print op #6799

Merged
merged 11 commits into from
Jan 12, 2018
Merged

feature/print op #6799

merged 11 commits into from
Jan 12, 2018

Conversation

Superjomn
Copy link
Contributor

@Superjomn Superjomn commented Dec 20, 2017

fixes: #6788

@@ -260,6 +261,7 @@ op_library(recurrent_op SRCS recurrent_op.cc DEPS executor)
# FIXME(typhoonzero): save/load depends lodtensor serialization functions
op_library(save_op DEPS lod_tensor)
op_library(load_op DEPS lod_tensor)
op_library(print_op SRCS print_op.cc DEPS lod_tensor)
Copy link
Member

Choose a reason for hiding this comment

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

what kind of operator need to declare in this CMakeLists?

attrs={
'first_n': first_n,
'summarize': summarize,
'message': message if message else "",
Copy link
Member

Choose a reason for hiding this comment

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

can use

'message': message or ""


Args:
input: A Tensor to print.
summarize: Print this number of elements in the tensor.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should tell the user what will be happened when summarize=-1.

print_tensor_name: Print the tensor name.
print_tensor_type: Print the tensor type.
print_tensor_shape: Print the tensor shape.
print_tensor_lod: Print the tensor lod.
Copy link
Contributor

Choose a reason for hiding this comment

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

The format of doc for Python API is here: #6526

Print the tensor name

Whether to print ...

input: A Tensor to print.
summarize: Print this number of elements in the tensor.
message: A string message to print as a prefix.
first_n: Only log `first_n` number of times.
Copy link
Contributor

Choose a reason for hiding this comment

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

Only log first_n number of times

这个注释不是特别明白~

Copy link
Contributor Author

@Superjomn Superjomn Dec 27, 2017

Choose a reason for hiding this comment

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

只有前 frist_n 次forward时会打log @qingqing01

print_tensor_shape=True,
print_tensor_lod=True):
'''
Creates a print op that will print when a tensor is accessed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Make sure that the layer comments are same as the convention defined in #6806

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


template <typename T>
void Display() {
auto* d = (T*)data;
Copy link
Member

Choose a reason for hiding this comment

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

如果是GPU tensor,这里可能会挂

PADDLE_ENFORCE(!Inputs("input").empty(), "input should be set");
auto* input_var = scope.FindVar(Input("input"));
PADDLE_ENFORCE_NOT_NULL(input_var);
auto& tensor = input_var->Get<framework::LoDTensor>();
Copy link
Member

Choose a reason for hiding this comment

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

enforce(is_cpu_place(tensor.place()))

auto& tensor = input_var->Get<framework::LoDTensor>();

// TODO(ChunweiYan) support GPU
PADDLE_ENFORCE(framework::is_cpu_place(tensor.place()));
Copy link
Contributor

Choose a reason for hiding this comment

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

framework --> platform

import paddle.v2.fluid.layers as pd


class TestSumOp(unittest.TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

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

TestSumOp --> TestPrintOp

Copy link
Member

@jacquesqiao jacquesqiao left a comment

Choose a reason for hiding this comment

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

some problem will be fixed in following PR

@Superjomn Superjomn merged commit 3423022 into PaddlePaddle:develop Jan 12, 2018
@Superjomn Superjomn deleted the feature/print_op branch January 12, 2018 07:24
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.

fluid need a Print operator just like TF
5 participants