-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
change net to operator #2846
Merged
Merged
change net to operator #2846
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
1cd208a
change net to operator
jacquesqiao 843ca37
update dependency
jacquesqiao b4241da
fix typo
jacquesqiao 5e34298
tmp
jacquesqiao c12cf1d
use OpPtr
jacquesqiao f96d7c0
use ScopePtr
jacquesqiao bf5197d
Merge branch 'optimize-ptr' of https://github.com/jacquesqiao/Paddle …
jacquesqiao a57f20e
use shared_ptr<OperatorBase> in net op
jacquesqiao fc85e6a
add AddOP(OpPtr op) to net op
jacquesqiao fea4359
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
jacquesqiao bb8ab09
fix conflict
jacquesqiao 6879eb2
change OpPtr to OperatorPtr
jacquesqiao 994ca58
Merge branch 'optimize-ptr' of https://github.com/jacquesqiao/Paddle …
jacquesqiao 01f7963
tmp
jacquesqiao 58bfcec
refine net_op
jacquesqiao ca10db7
Complete NetOp
reyoung 796b763
Merge pull request #1 from reyoung/net-op
jacquesqiao 467bdba
add add_op_done_ and test
jacquesqiao e235d08
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
jacquesqiao c62986f
fix style
jacquesqiao 1429d96
optimize operator_test
jacquesqiao b605ce6
optimize operator_test
jacquesqiao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include <gtest/gtest.h> | ||
#include <paddle/framework/net.h> | ||
#include <paddle/framework/op_registry.h> | ||
#include <paddle/framework/operator.h> | ||
|
||
namespace pd = paddle::framework; | ||
|
||
static int infer_shape_cnt = 0; | ||
static int run_cnt = 0; | ||
|
||
class TestOp : public pd::OperatorBase { | ||
public: | ||
void InferShape(const paddle::framework::ScopePtr& scope) const override { | ||
++infer_shape_cnt; | ||
} | ||
void Run(const paddle::framework::ScopePtr& scope, | ||
const paddle::platform::DeviceContext& dev_ctx) const override { | ||
++run_cnt; | ||
} | ||
}; | ||
|
||
template <typename T> | ||
void AssertSameVectorWithoutOrder(const std::vector<T>& expected, | ||
const std::vector<T>& actual) { | ||
ASSERT_EQ(expected.size(), actual.size()); | ||
std::unordered_set<T> expected_set; | ||
for (auto& tmp : expected) { | ||
expected_set.insert(tmp); | ||
} | ||
for (auto& act : actual) { | ||
ASSERT_NE(expected_set.end(), expected_set.find(act)); | ||
} | ||
} | ||
|
||
TEST(OpKernel, all) { | ||
auto net = std::make_shared<paddle::framework::PlainNet>(); | ||
ASSERT_NE(net, nullptr); | ||
|
||
auto op1 = std::make_shared<TestOp>(); | ||
op1->inputs_ = {"x", "w1", "b1"}; | ||
op1->outputs_ = {"y"}; | ||
net->AddOp(op1); | ||
|
||
auto op2 = std::make_shared<TestOp>(); | ||
op2->inputs_ = {"y", "w2", "b2"}; | ||
op2->outputs_ = {"z"}; | ||
net->AddOp(op2); | ||
|
||
net->CompleteAddOp(); | ||
AssertSameVectorWithoutOrder({"x", "w1", "b1", "w2", "b2"}, net->inputs_); | ||
AssertSameVectorWithoutOrder({"y", "z"}, net->outputs_); | ||
auto tmp_idx_iter = net->attrs_.find("temporary_index"); | ||
ASSERT_NE(net->attrs_.end(), tmp_idx_iter); | ||
auto& tmp_idx = boost::get<std::vector<int>>(tmp_idx_iter->second); | ||
ASSERT_EQ(1UL, tmp_idx.size()); | ||
ASSERT_EQ("y", net->outputs_[tmp_idx[0]]); | ||
|
||
auto scope = std::make_shared<pd::Scope>(); | ||
paddle::platform::CPUDeviceContext dev_ctx; | ||
|
||
net->InferShape(scope); | ||
net->Run(scope, dev_ctx); | ||
ASSERT_EQ(2, infer_shape_cnt); | ||
ASSERT_EQ(2, run_cnt); | ||
|
||
ASSERT_THROW(net->AddOp(op2), paddle::framework::EnforceNotMet); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
since we have reached an agreement in treating net as a composed Op, seems we do not need a
PlainNet
anymore. We can have two types of Net,Net
,DAGNet
.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.
I think net will have a common interface
AddOp
, so I add the net base interface with only AddOp