-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Description
The Requirement of Functions
Motivation 1. Inference Engine Calls Fluid Functions
The inference/production system are not supposed to be created by PaddlePaddle team, and not even PaddlePaddle users. They are often server programs in C++/Java/Go, or mobile inference engines in C/Objective-C. PaddlePaddle project should provide a library, which allows
- The users can use whatever host language to create the production system, and
- they can call Fluid functions that describe the inference algorithms from their host languages.
Motivation 2. Canonicalize IfElse/While Implementations (arguably)
The current implementation of IfElseOp and WhileOp is kind of hacky -- values passing in/out the blocks are in a hacky way, involving some hacky concepts like InLink and OutLink, which should have been arguments and return values and should have been implemented using FuncCallOp, which implements a canonical calling convention which will be explained in the rest of this document.
Technical Viability
An argument is the Fluid is a differenetial langauge, but if the FuncCallOP differentable?
I think the answer is Yes, because the function call is basically insert the sequence of operations of a block (the callee's body) into the caller's body. As long as the sequential execution is differentiable, the function call should be differentiable -- with the help of scope-hierarchy.
Function Definition
A Function
A function is composed of the following staff:
- function signature
- function name
- inputs, or arguments,
- outputs, or return values
- function body
Currently, Fluid has the framework.BlockDesc message that can be used to represent the function body, but not the signature.
A Program
A program (imagine a C program) is composed of one or more functions, where one of them (with the name main) is the default entry-point, which might call other functions.
Other functions might be entry-points too -- consider a C program that is built into an .so file. In the case of Fluid, we need similar feature, e.g., to allow a C++ function (in the inference engine program) to call a Fluid function (which implements the inference algorithm).
Currently, a Fluid program (a ProgramDesc message) cannot have function definitions, so instead, it looks something like a Python script, or a block-hierarchy, where the root block is the entry-point of the "Python script".