未验证 提交 a59c3b73 编写于 作者: Y Yang Yang(Tony) 提交者: GitHub

change dynamic graph folder (#11451)

* change dynamic to tape

* update readme link
上级 d827c6e8
...@@ -14,4 +14,4 @@ ...@@ -14,4 +14,4 @@
# #
add_subdirectory(inference) add_subdirectory(inference)
add_subdirectory(dynamic) add_subdirectory(tape)
# Dynamic Graph on Fluid # Dynamic Graph on Fluid
PaddlePaddle Fluid is targeting the autodiff without tape, which, however, is very challenging and we are still way from there. DyNet and PyTorch provide a good design idea, the *tape*, that significantly eases the challenge. Also, DyNet provides a C++ API that is as convenient as Python but with higher efficiency and could conveniently integrate with industrial/production systems. This package, `tape`, combines the good of PaddlePaddle Fluid is targeting the autodiff without tape, which, however, is very
challenging and we are still way from there. DyNet and PyTorch provide a good design
idea, the *tape*, that significantly eases the challenge. Also, DyNet provides
a C++ API that is as convenient as Python but with higher efficiency and could
conveniently integrate with industrial/production systems. This package, `tape`,
combines the good of
1. tape from PyTorch and DyNet 1. tape from PyTorch and DyNet
2. C++ API and core from DyNet 2. C++ API and core from DyNet
...@@ -8,8 +13,8 @@ PaddlePaddle Fluid is targeting the autodiff without tape, which, however, is ve ...@@ -8,8 +13,8 @@ PaddlePaddle Fluid is targeting the autodiff without tape, which, however, is ve
## Overview ## Overview
We can implement Dynet-like Tape(See this survey) by wrapping Paddle Fluid's `Operator` We can implement Dynet-like Tape(See this [survey](https://github.com/PaddlePaddle/Paddle/blob/develop/doc/survey/dynamic_graph.md))
and `Variable`. by wrapping Paddle Fluid's `Operator` and `Variable`.
The user API is straight forward since The user API is straight forward since
...@@ -121,13 +126,14 @@ paddle::tape::SGD sgd(0.001); ...@@ -121,13 +126,14 @@ paddle::tape::SGD sgd(0.001);
// Data Feeder // Data Feeder
paddle::tape::Fill data_feeder(...); paddle::tape::Fill data_feeder(...);
VariableHandle input(new paddle::tape::Variable("input")); VariableHandle input(new paddle::tape::Variable("input"));
VariableHandle label(new paddle::tape::Variable("label"));
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
reset_global_tape(); reset_global_tape();
data_feeder(input); data_feeder(input, label);
auto loss = mean(linear2(linear1(input))); // compile time InferShape & InferVarType auto loss = softmax(linear2(linear1(input)), label); // compile time InferShape & InferVarType
LOG(INFO) << loss.value(); // Run forward up to loss LOG(INFO) << loss.value(); // Run forward up to loss
// Run backward, store gradient of w at w->Grad() // Run backward, store gradient of w at w->Grad()
...@@ -209,7 +215,7 @@ digraph G { ...@@ -209,7 +215,7 @@ digraph G {
} }
</details> </details>
![Image](https://github.com/tonyyang-svail/Paddle/blob/cpp_tap/paddle/contrib/dynamic/computation_graph.png) ![Image](https://github.com/tonyyang-svail/Paddle/blob/cpp_tap/paddle/contrib/tape/computation_graph.png)
## Code Reuse ## Code Reuse
......
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
#include <string> #include <string>
#include "paddle/contrib/dynamic/tape.h" #include "paddle/contrib/tape/tape.h"
#include "paddle/contrib/dynamic/variable.h" #include "paddle/contrib/tape/variable.h"
#include "paddle/fluid/framework/type_defs.h" #include "paddle/fluid/framework/type_defs.h"
namespace paddle { namespace paddle {
namespace dynamic { namespace tape {
class Function {}; class Function {};
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "paddle/contrib/dynamic/tape.h" #include "paddle/contrib/tape/tape.h"
#include <list> #include <list>
#include <map> #include <map>
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "paddle/fluid/pybind/pybind.h" #include "paddle/fluid/pybind/pybind.h"
namespace paddle { namespace paddle {
namespace dynamic { namespace tape {
// borrowed from // borrowed from
// https://stackoverflow.com/questions/874134/find-if-string-ends-with-another-string-in-c // https://stackoverflow.com/questions/874134/find-if-string-ends-with-another-string-in-c
......
...@@ -18,10 +18,10 @@ ...@@ -18,10 +18,10 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "paddle/contrib/dynamic/variable.h" #include "paddle/contrib/tape/variable.h"
namespace paddle { namespace paddle {
namespace dynamic { namespace tape {
using VariableHandleMap = std::map<std::string, std::vector<VariableHandle>>; using VariableHandleMap = std::map<std::string, std::vector<VariableHandle>>;
......
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
// limitations under the License. // limitations under the License.
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "paddle/contrib/dynamic/function.h" #include "paddle/contrib/tape/function.h"
using namespace paddle::dynamic; using namespace paddle::tape;
TEST(Tape, TestMLP) { TEST(Tape, TestMLP) {
LOG(INFO) << "TestMLP"; LOG(INFO) << "TestMLP";
......
...@@ -12,10 +12,10 @@ ...@@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "paddle/contrib/dynamic/variable.h" #include "paddle/contrib/tape/variable.h"
namespace paddle { namespace paddle {
namespace dynamic { namespace tape {
void Variable::InitializeVariable() { void Variable::InitializeVariable() {
LOG(INFO) << "Initialzing " << desc_.Name() << " as " << desc_.GetType(); LOG(INFO) << "Initialzing " << desc_.Name() << " as " << desc_.GetType();
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "paddle/fluid/framework/variable.h" #include "paddle/fluid/framework/variable.h"
namespace paddle { namespace paddle {
namespace dynamic { namespace tape {
class Variable; class Variable;
using VariableHandle = std::shared_ptr<Variable>; using VariableHandle = std::shared_ptr<Variable>;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册