-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Complete Fluid -- Function Definition and Invocation #10244
Comments
Agree. I want to point out that the new API design is fully compatible with the solution of this issue: class Word2Vec(fluid.Program):
@network("firstw", "secondw", "thirdw", "forthw", "nextw")
def train_step(self):
# ...
@network("firstw", "secondw", "thirdw", "forthw")
def infer(self):
# ...
word2vec = Word2Vec().Compile()
avg_cost = word2vec.train_step(data[0], data[1], data[2], data[3], data[4])
next_word = word2vec.infer(1,2,3,4) The |
Fluid Programs and FunctionsBasing on the following facts:
An Introductory But Not-Good-Enough ApproachAn intuitive reaction to this is to describe functions by adding a
Please be aware that:
The problem with this approach is that each function definition (body) has a hierarchy of blocks, and blocks in different hierarchies (functions) do not overlap, which implies that the An Alternative Approach with Unique Block HierarchyTo make sure that all blocks are in a unique hierarchy, we need function definitions refering to blocks as their bodies.
RestrictionsThis proposal takes C as a reference, thus is a minimalist proposal; it
|
Agree. and Inline Function CompilationIn C++, there is a keyword To make the explanation comprehensive, let us imagine that users write three Python functions class Word2Vec(fluid.Program):
def _predict():
# ...
@fluid("firstw", "secondw", "thirdw", "forthw", "nextw")
def train_step(self):
predict = self._predict()
label = ...
loss = fluid.mse(predict, label)
# minimize loss
@fluid("firstw", "secondw", "thirdw", "forthw")
def infer(self):
return self._predict() where both The Python function decorator Because the compilation process is exactly the execution of the above Python program, while |
does that mean function caller is tightly bind with function definition? |
您好,此issue在近一个月内暂无更新,我们将于今天内关闭。若在关闭后您仍需跟进提问,可重新开启此问题,我们将在24小时内回复您。因关闭带来的不便我们深表歉意,请您谅解~感谢您对PaddlePaddle的支持! |
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
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:
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".The text was updated successfully, but these errors were encountered: