Skip to content

How to initialize a Fluid program? #10177

@helinwang

Description

@helinwang

I think we need to address the problem below before merging startup program and main program into a single program:

  1. Init reader when doing inference
    An inference program will run repeatedly, but we may have a reader inside an inference program, it should be initialized only once, not every time when the inference program runs. Merging the startup program and the main program essentially runs the initialization operators on every run.

  2. Load parameters inside the Fluid program when doing inference.
    The V4 API proposal proposes to load parameters outside of the Fluid program:

    infer.py

    x = fluid.Tensor(name='x', shape=[13], dtype='float32')
    y_predict = fluid.layers.fc(name='y_predict', input=x, size=1, act=None)
    return y_predict

    main.py

    program = fluid.compile('./infer.py', params='./params')
    inputs = {
      'x': [2,4,64,36,7,4,3,2,4,6,5,9,8]
    }
    results = program.run(input=inputs)

    It would be more coherent with the Fluid design if the parameter loading is inside the Fluid program:

    infer.py

    fluid.load_parameters("./params.recordio")
    x = fluid.Tensor(name='x', shape=[13], dtype='float32')
    y_predict = fluid.layers.fc(name='y_predict', input=x, size=1, act=None)
    return y_predict

    main.py

    program = fluid.compile('./infer.py')
    program.init()
    inputs = {
      'x': [2,4,64,36,7,4,3,2,4,6,5,9,8]
    }
    results = program.run(input=inputs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions