-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
feature/print op #6799
Conversation
paddle/operators/CMakeLists.txt
Outdated
@@ -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) |
There was a problem hiding this comment.
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 "", |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
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
这个注释不是特别明白~
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
paddle/operators/print_op.cc
Outdated
|
||
template <typename T> | ||
void Display() { | ||
auto* d = (T*)data; |
There was a problem hiding this comment.
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>(); |
There was a problem hiding this comment.
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()))
paddle/operators/print_op.cc
Outdated
auto& tensor = input_var->Get<framework::LoDTensor>(); | ||
|
||
// TODO(ChunweiYan) support GPU | ||
PADDLE_ENFORCE(framework::is_cpu_place(tensor.place())); |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestSumOp --> TestPrintOp
There was a problem hiding this 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
fixes: #6788