Skip to content

Add OpProto implementation #2703

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

Merged
merged 3 commits into from
Jul 3, 2017
Merged

Conversation

reyoung
Copy link
Collaborator

@reyoung reyoung commented Jul 3, 2017

OpProto is a proto message help 3rd-party language bindings, e.g.
Python to generate operator creation methods. The operator creation
method is the low-level API for 3rd-party language bindings. Op creation
methods take the user's input in that language, and convert users inputs
into OpDesc message, then passing that OpDesc message to Paddle's
C++ core and create an operator.

  • A separated attr_type.proto is added, because that file wound
    be included by op_desc.proto in future.

@reyoung reyoung force-pushed the feature/op_proto branch 2 times, most recently from fbfdfa1 to 053ab40 Compare July 3, 2017 07:40
@@ -5,3 +5,4 @@ nv_test(dim_test SRCS dim_test.cu DEPS ddim)
cc_test(variable_test SRCS variable_test.cc)
cc_test(scope_test SRCS scope_test.cc)
cc_test(enforce_test SRCS enforce_test.cc)
proto_library(op_proto SRCS op_proto.proto attr_type.proto)
Copy link
Member

Choose a reason for hiding this comment

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

since attr_type.proto is separated and also used by op_desc.proto, if it's better to write like below, I am not sure if proto_library can do this.

proto_library(attr_type SRCS attr_type.proto)
proto_library(op_proto SRCS op_proto.proto DEPS attr_type)
proto_library(op_desc SRCS op_desc.proto DEPS attr_type)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

proto_library doesn't contain DEPS argument. Each protobuf file can compile to the independent library and doesn't depends on other files.

Copy link
Member

Choose a reason for hiding this comment

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

ok

Copy link
Collaborator Author

@reyoung reyoung Jul 3, 2017

Choose a reason for hiding this comment

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

I will give a unit test to demonstrate that.

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. @jacquesqiao I add a unit test also.

required AttrType type = 1;

// Supported attribute name. e.g. `scale` for cosine op.
required string name = 2;
Copy link
Member

@jacquesqiao jacquesqiao Jul 3, 2017

Choose a reason for hiding this comment

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

In my mind, name should always be the first item in a proto.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right! Let me fix them

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.

OpProto is a proto message that helps 3rd-party language bindings, e.g.
`Python`, to generate operator creation methods. The operator creation
method is the low-level API for 3rd-party language bindings. Op creation
methods take the user's input in that language, and convert users inputs
into `OpDesc` message, then passing that `OpDesc` message to Paddle's
C++ core and create an operator.

* A separated `attr_type.proto` is added, because that file wound
  be included by `op_desc.proto` in future.
@reyoung reyoung force-pushed the feature/op_proto branch from 053ab40 to bdd2720 Compare July 3, 2017 08:26
@@ -0,0 +1,28 @@
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Copy link
Member

Choose a reason for hiding this comment

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

Are we going to put our xx.proto file into the dir that need to use it or just in paddle/proto?

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 am not sure.
But tensorflow make protobuf files into sub-directories. Since we are using google code style now, it seems that we should put our protobuf files in sub-directories.

Another advantage that make protobuf file in sub-directories is it make include line pretty like below.

#include <paddle/framework/op_proto.pb.h>

required string name = 1;

// The comment for that input. It helps 3rd-party language generate doc-string.
required string comment = 2;
Copy link
Collaborator

Choose a reason for hiding this comment

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

add required bool is_tensor = 3 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That field will be added when it is needed for generating layer because maybe just a bool flag is not enough. But we do not know what is better.

Maybe an enum type is needed, like

enum VarType {
  LAYER_INPUT = 0;
  LAYER_OUTPUT = 1;
  LAYER_PARAM = 2;
  LAYER_AUX_INPUT = 3;
  LAYER_AUX_OUTPUT = 4;
  RNN_SCOPE = 5;
};

But I can not have a precise design about that field. It should be clearer when we start writing layer methods.

Copy link
Collaborator

@JiayiFeng JiayiFeng left a comment

Choose a reason for hiding this comment

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

LGTM

@reyoung reyoung force-pushed the feature/op_proto branch from e8585e2 to 3f63d96 Compare July 3, 2017 15:16
@reyoung reyoung merged commit 80f8e24 into PaddlePaddle:develop Jul 3, 2017
@dzhwinter
Copy link
Contributor

so fast as you guys! 👍

@reyoung reyoung deleted the feature/op_proto branch July 13, 2017 11:38
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.

4 participants