diff --git a/paddle/contrib/CMakeLists.txt b/paddle/contrib/CMakeLists.txt index 75d01705679c669123882b1a5fdbbdb55a70a4ff..70e3a0583d8ecf9db19a85c0978aae0ce0625570 100644 --- a/paddle/contrib/CMakeLists.txt +++ b/paddle/contrib/CMakeLists.txt @@ -14,4 +14,4 @@ # add_subdirectory(inference) -add_subdirectory(dynamic) +add_subdirectory(tape) diff --git a/paddle/contrib/dynamic/CMakeLists.txt b/paddle/contrib/tape/CMakeLists.txt similarity index 100% rename from paddle/contrib/dynamic/CMakeLists.txt rename to paddle/contrib/tape/CMakeLists.txt diff --git a/paddle/contrib/dynamic/README.md b/paddle/contrib/tape/README.md similarity index 90% rename from paddle/contrib/dynamic/README.md rename to paddle/contrib/tape/README.md index a056877093ab18500d42225b500bbb890c68dfdb..16c22a45d59664e44c83923371c0f0d957a8ca7f 100644 --- a/paddle/contrib/dynamic/README.md +++ b/paddle/contrib/tape/README.md @@ -1,6 +1,11 @@ # 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 2. C++ API and core from DyNet @@ -8,8 +13,8 @@ PaddlePaddle Fluid is targeting the autodiff without tape, which, however, is ve ## Overview -We can implement Dynet-like Tape(See this survey) by wrapping Paddle Fluid's `Operator` -and `Variable`. +We can implement Dynet-like Tape(See this [survey](https://github.com/PaddlePaddle/Paddle/blob/develop/doc/survey/dynamic_graph.md)) +by wrapping Paddle Fluid's `Operator` and `Variable`. The user API is straight forward since @@ -121,13 +126,14 @@ paddle::tape::SGD sgd(0.001); // Data Feeder paddle::tape::Fill data_feeder(...); VariableHandle input(new paddle::tape::Variable("input")); +VariableHandle label(new paddle::tape::Variable("label")); for (int i = 0; i < 2; ++i) { 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 // Run backward, store gradient of w at w->Grad() @@ -209,7 +215,7 @@ digraph G { } -![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 diff --git a/paddle/contrib/dynamic/computation_graph.png b/paddle/contrib/tape/computation_graph.png similarity index 100% rename from paddle/contrib/dynamic/computation_graph.png rename to paddle/contrib/tape/computation_graph.png diff --git a/paddle/contrib/dynamic/function.h b/paddle/contrib/tape/function.h similarity index 97% rename from paddle/contrib/dynamic/function.h rename to paddle/contrib/tape/function.h index 6434beebf4a46db11893ef6df051c01c73af9fc0..0584f4ec8aaae075dc7519c5fa670b62d8893007 100644 --- a/paddle/contrib/dynamic/function.h +++ b/paddle/contrib/tape/function.h @@ -16,12 +16,12 @@ #include -#include "paddle/contrib/dynamic/tape.h" -#include "paddle/contrib/dynamic/variable.h" +#include "paddle/contrib/tape/tape.h" +#include "paddle/contrib/tape/variable.h" #include "paddle/fluid/framework/type_defs.h" namespace paddle { -namespace dynamic { +namespace tape { class Function {}; diff --git a/paddle/contrib/dynamic/tape.cc b/paddle/contrib/tape/tape.cc similarity index 99% rename from paddle/contrib/dynamic/tape.cc rename to paddle/contrib/tape/tape.cc index fd24eabe9d00f92752cfc17492bd778f80bceb60..531499b6fe02abf200b7d4401494fd6350646622 100644 --- a/paddle/contrib/dynamic/tape.cc +++ b/paddle/contrib/tape/tape.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "paddle/contrib/dynamic/tape.h" +#include "paddle/contrib/tape/tape.h" #include #include @@ -29,7 +29,7 @@ #include "paddle/fluid/pybind/pybind.h" namespace paddle { -namespace dynamic { +namespace tape { // borrowed from // https://stackoverflow.com/questions/874134/find-if-string-ends-with-another-string-in-c diff --git a/paddle/contrib/dynamic/tape.h b/paddle/contrib/tape/tape.h similarity index 96% rename from paddle/contrib/dynamic/tape.h rename to paddle/contrib/tape/tape.h index 9467e9d5434216fd5a5f6e7b3a959e09b11d774f..9938ce9a7f46adb8c4db49c0d847092b1839b6f6 100644 --- a/paddle/contrib/dynamic/tape.h +++ b/paddle/contrib/tape/tape.h @@ -18,10 +18,10 @@ #include #include -#include "paddle/contrib/dynamic/variable.h" +#include "paddle/contrib/tape/variable.h" namespace paddle { -namespace dynamic { +namespace tape { using VariableHandleMap = std::map>; diff --git a/paddle/contrib/dynamic/test_tape.cc b/paddle/contrib/tape/test_tape.cc similarity index 95% rename from paddle/contrib/dynamic/test_tape.cc rename to paddle/contrib/tape/test_tape.cc index ad8ee8c756133d05f0b4a0d158f3139c48c7b82c..e9bfd21a7189c5867a52d2b25db09a462d5c7ba7 100644 --- a/paddle/contrib/dynamic/test_tape.cc +++ b/paddle/contrib/tape/test_tape.cc @@ -13,9 +13,9 @@ // limitations under the License. #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) { LOG(INFO) << "TestMLP"; diff --git a/paddle/contrib/dynamic/variable.cc b/paddle/contrib/tape/variable.cc similarity index 94% rename from paddle/contrib/dynamic/variable.cc rename to paddle/contrib/tape/variable.cc index 8eede414f52e5b7ae4555e0b7978168700adf5c8..5ec1612909503f666bca0fce3246002879854156 100644 --- a/paddle/contrib/dynamic/variable.cc +++ b/paddle/contrib/tape/variable.cc @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "paddle/contrib/dynamic/variable.h" +#include "paddle/contrib/tape/variable.h" namespace paddle { -namespace dynamic { +namespace tape { void Variable::InitializeVariable() { LOG(INFO) << "Initialzing " << desc_.Name() << " as " << desc_.GetType(); diff --git a/paddle/contrib/dynamic/variable.h b/paddle/contrib/tape/variable.h similarity index 99% rename from paddle/contrib/dynamic/variable.h rename to paddle/contrib/tape/variable.h index 55b5f1fda9a358cdde25f9beb99abe8006da36a5..7e63aa38a7a632b1e5a0a46c1d1306a28e902962 100644 --- a/paddle/contrib/dynamic/variable.h +++ b/paddle/contrib/tape/variable.h @@ -20,7 +20,7 @@ #include "paddle/fluid/framework/variable.h" namespace paddle { -namespace dynamic { +namespace tape { class Variable; using VariableHandle = std::shared_ptr;