PaddlePaddle Fluid Source Code Overview

Examples: https://github.com/PaddlePaddle/Paddle/tree/develop/python/paddle/v2/fluid/tests/book

Core: https://github.com/PaddlePaddle/Paddle/tree/develop/paddle/framework

Operator: https://github.com/PaddlePaddle/Paddle/tree/develop/paddle/operators

Optimizer: https://github.com/PaddlePaddle/Paddle/tree/develop/paddle/optimizer

Memory: https://github.com/PaddlePaddle/Paddle/tree/develop/paddle/memory

Compile Time

The following defines the NN. The definition goes into this protocol buffer.

x = fluid.layers.data(name='x', shape=[13], dtype='float32')
y = fluid.layers.data(name='y', shape=[1], dtype='float32')

y_predict = fluid.layers.fc(input=x, size=1, act=None)
cost = fluid.layers.square_error_cost(input=y_predict, label=y)
avg_cost = fluid.layers.mean(x=cost)

sgd_optimizer = fluid.optimizer.SGD(learning_rate=0.001)
sgd_optimizer.minimize(avg_cost)

Run Time

The following evaluates the NN. Instantiates all the variables, operators.

place = fluid.CPUPlace()
feeder = fluid.DataFeeder(place=place, feed_list=[x, y])
exe = fluid.Executor(place)

# Allocate memory. Initialize Parameter.
exe.run(fluid.default_startup_program())

# Allocate memory. Do computation.
exe.run(fluid.default_main_program(),
        feed=feeder.feed(data),
        fetch_list=[avg_cost])