commit
9c69fdf5c6
@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
python gen_doc.py layers --submodules control_flow device io nn ops tensor detection learning_rate_scheduler metric > layers.rst
|
||||
|
||||
for module in data_feeder clip metrics executor initializer io nets optimizer param_attr profiler regularizer
|
||||
for module in data_feeder clip metrics executor initializer io nets optimizer param_attr profiler regularizer transpiler
|
||||
do
|
||||
python gen_doc.py ${module} > ${module}.rst
|
||||
done
|
||||
|
@ -0,0 +1,46 @@
|
||||
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
|
||||
!DO NOT EDIT THIS FILE MANUALLY!
|
||||
|
||||
==========
|
||||
transpiler
|
||||
==========
|
||||
|
||||
DistributeTranspiler
|
||||
--------------------
|
||||
|
||||
.. autoclass:: paddle.fluid.transpiler.DistributeTranspiler
|
||||
:members:
|
||||
:noindex:
|
||||
|
||||
InferenceTranspiler
|
||||
-------------------
|
||||
|
||||
.. autoclass:: paddle.fluid.transpiler.InferenceTranspiler
|
||||
:members:
|
||||
:noindex:
|
||||
|
||||
memory_optimize
|
||||
---------------
|
||||
|
||||
.. autofunction:: paddle.fluid.transpiler.memory_optimize
|
||||
:noindex:
|
||||
|
||||
release_memory
|
||||
--------------
|
||||
|
||||
.. autofunction:: paddle.fluid.transpiler.release_memory
|
||||
:noindex:
|
||||
|
||||
HashName
|
||||
--------
|
||||
|
||||
.. autoclass:: paddle.fluid.transpiler.HashName
|
||||
:members:
|
||||
:noindex:
|
||||
|
||||
RoundRobin
|
||||
----------
|
||||
|
||||
.. autoclass:: paddle.fluid.transpiler.RoundRobin
|
||||
:members:
|
||||
:noindex:
|
@ -0,0 +1,59 @@
|
||||
# Inference High-level APIs
|
||||
This document describes the high-level inference APIs one can use to easily deploy a Paddle model for an application.
|
||||
|
||||
The APIs are described in `paddle_inference_api.h`, just one header file, and two libaries `libpaddle_fluid.so` and `libpaddle_fluid_api.so` are needed.
|
||||
|
||||
## PaddleTensor
|
||||
We provide the `PaddleTensor` data structure is to give a general tensor interface.
|
||||
|
||||
The definition is
|
||||
|
||||
```c++
|
||||
struct PaddleTensor {
|
||||
std::string name; // variable name.
|
||||
std::vector<int> shape;
|
||||
PaddleBuf data; // blob of data.
|
||||
PaddleDType dtype;
|
||||
};
|
||||
```
|
||||
|
||||
The data is stored in a continuous memory `PaddleBuf`, and tensor's data type is specified by a `PaddleDType`.
|
||||
The `name` field is used to specify the name of input variable,
|
||||
that is important when there are multiple inputs and need to distiuish which variable to set.
|
||||
|
||||
## engine
|
||||
The inference APIs has two different underlying implementation, currently there are two valid engines:
|
||||
|
||||
- the native engine, which is consists of the native operators and framework,
|
||||
- the Anakin engine, which is a Anakin library embeded.
|
||||
|
||||
The native engine takes a native Paddle model as input, and supports any model that trained by Paddle,
|
||||
but the Anakin engine can only take the Anakin model as input(user need to manully transform the format first) and currently not all Paddle models are supported.
|
||||
|
||||
```c++
|
||||
enum class PaddleEngineKind {
|
||||
kNative = 0, // Use the native Fluid facility.
|
||||
kAnakin, // Use Anakin for inference.
|
||||
};
|
||||
```
|
||||
|
||||
## PaddlePredictor and how to create one
|
||||
The main interface is `PaddlePredictor`, there are following methods
|
||||
|
||||
- `bool Run(const std::vector<PaddleTensor>& inputs, std::vector<PaddleTensor>* output_data)`
|
||||
- take inputs and output `output_data`
|
||||
- `Clone` to clone a predictor from an existing one, with model parameter shared.
|
||||
|
||||
There is a factory method to help create a predictor, and the user takes the ownership of this object.
|
||||
|
||||
```c++
|
||||
template <typename ConfigT, PaddleEngineKind engine = PaddleEngineKind::kNative>
|
||||
std::unique_ptr<PaddlePredictor> CreatePaddlePredictor(const ConfigT& config);
|
||||
```
|
||||
|
||||
By specifying the engine kind and config, one can get an specific implementation.
|
||||
|
||||
## Reference
|
||||
|
||||
- [paddle_inference_api.h](./paddle_inference_api.h)
|
||||
- [demos](./demo)
|
File diff suppressed because it is too large
Load Diff
Before Width: | Height: | Size: 94 KiB |
@ -1,131 +0,0 @@
|
||||
// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "paddle/contrib/tape/tape.h"
|
||||
#include "paddle/contrib/tape/variable.h"
|
||||
#include "paddle/fluid/framework/type_defs.h"
|
||||
|
||||
namespace paddle {
|
||||
namespace tape {
|
||||
|
||||
class Function {};
|
||||
|
||||
class Fill {
|
||||
public:
|
||||
Fill(const std::string &initializer, const framework::AttributeMap &attrs)
|
||||
: initializer_(initializer), attrs_(attrs) {}
|
||||
|
||||
void operator()(VariableHandle var) {
|
||||
get_global_tape().AddOp(initializer_, {}, {{"Out", {var}}}, attrs_);
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string initializer_;
|
||||
const framework::AttributeMap attrs_;
|
||||
};
|
||||
|
||||
class Mean {
|
||||
public:
|
||||
VariableHandle operator()(VariableHandle var) {
|
||||
VariableHandle out(new Variable("mean"));
|
||||
get_global_tape().AddOp("mean", {{"X", {var}}}, {{"Out", {out}}}, {});
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
class Linear {
|
||||
public:
|
||||
Linear(int in_dim, int out_dim, const std::string &act)
|
||||
: w_(new Variable("LinearWeight")),
|
||||
b_(new Variable("LinearBias")),
|
||||
act_(act) {
|
||||
Tape init_tape;
|
||||
|
||||
std::string initializer = "fill_constant";
|
||||
framework::AttributeMap attrs;
|
||||
attrs["dtype"] = paddle::framework::proto::VarType::Type::VarType_Type_FP32;
|
||||
attrs["shape"] = std::vector<int>{in_dim, out_dim};
|
||||
attrs["value"] = 1.0f;
|
||||
init_tape.AddOp(initializer, {}, {{"Out", {w_}}}, attrs);
|
||||
|
||||
attrs["dtype"] = paddle::framework::proto::VarType::Type::VarType_Type_FP32;
|
||||
attrs["shape"] = std::vector<int>{out_dim};
|
||||
attrs["value"] = 1.0f;
|
||||
init_tape.AddOp(initializer, {}, {{"Out", {b_}}}, attrs);
|
||||
|
||||
init_tape.Forward();
|
||||
}
|
||||
|
||||
VariableHandle operator()(VariableHandle input) {
|
||||
VariableHandle pre_bias(new Variable("linear"));
|
||||
get_global_tape().AddOp("mul",
|
||||
{{"X", {input}}, {"Y", {w_}}},
|
||||
{{"Out", {pre_bias}}},
|
||||
{{"x_num_col_dims", 1}, {"y_num_col_dims", 1}});
|
||||
VariableHandle pre_act(new Variable("linear"));
|
||||
get_global_tape().AddOp("elementwise_add",
|
||||
{{"X", {pre_bias}}, {"Y", {b_}}},
|
||||
{{"Out", {pre_act}}},
|
||||
{{"axis", 1}});
|
||||
VariableHandle post_act(new Variable("linear"));
|
||||
get_global_tape().AddOp(
|
||||
act_, {{"X", {pre_act}}}, {{"Out", {post_act}}}, {});
|
||||
return post_act;
|
||||
}
|
||||
|
||||
std::vector<VariableHandle> Params() { return {w_, b_}; }
|
||||
|
||||
private:
|
||||
VariableHandle w_;
|
||||
VariableHandle b_;
|
||||
std::string act_;
|
||||
};
|
||||
|
||||
class SGD {
|
||||
public:
|
||||
SGD(float learning_rate) : learning_rate_(new Variable("sgd")) {
|
||||
Tape init_tape;
|
||||
|
||||
std::string initializer = "fill_constant";
|
||||
framework::AttributeMap attrs;
|
||||
attrs["dtype"] = paddle::framework::proto::VarType::Type::VarType_Type_FP32;
|
||||
attrs["shape"] = std::vector<int>{1};
|
||||
attrs["value"] = learning_rate;
|
||||
init_tape.AddOp(initializer, {}, {{"Out", {learning_rate_}}}, attrs);
|
||||
|
||||
init_tape.Forward();
|
||||
}
|
||||
|
||||
void operator()(VariableHandle input) {
|
||||
PADDLE_ENFORCE(get_global_tape().HasBeenBackwarded(),
|
||||
"optimization must happen after the backward");
|
||||
Tape temp_tape;
|
||||
temp_tape.AddOp("sgd",
|
||||
{{"Param", {input}},
|
||||
{"LearningRate", {learning_rate_}},
|
||||
{"Grad", {input->Grad()}}},
|
||||
{{"ParamOut", {input}}},
|
||||
{});
|
||||
temp_tape.Forward();
|
||||
}
|
||||
|
||||
private:
|
||||
VariableHandle learning_rate_;
|
||||
};
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue