Skip to content
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

Add inferencer infer #10445

Merged
merged 14 commits into from
May 11, 2018
Merged

Conversation

jacquesqiao
Copy link
Member

@jacquesqiao jacquesqiao commented May 7, 2018

fix: #10364


if param_path:
self.exe = executor.Executor(place)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The place could be None.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

# 3. run the default_startup program.

# 4. load params from param_path into scope
self.param_path = param_path
self.scope = core.Scope()
self.place = place
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.place is never used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

self.fetch_targets] = io.load_inference_model(
executor=self.exe, dirname=param_path)
else:
self.inference_program = framework.Program()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are parameter values from if param_path is None?

raise ValueError(
"program_func should return tuple(loss, predict_vars)")

loss = out[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a problem I also encounter in my trainer.test(). The program_func() may returns more than one element. But only one of them('loss') will be used to build the backward part. In the current design, we have no method to point out which one is the loss.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I create a issue for this problem #10474.

predict_var = self.infer_func()
predict_var = self.train_program.block(0).var(predict_var.name)
exe = executor.Executor(self.place)
io.save_inference_model(model_path, [], [predict_var], exe)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the predict_var is in the train_program, so we are using the train_program to build the inference model. Why not use inference_program directly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because save_inference_model will do some other thing to inference_program, we need to rewrite it, but currently, I think rewrite this function do not influence the interface and may introduce bugs.

if isinstance(event, fluid.EndEpochEvent):
avg_cost = trainer.test(reader=paddle.dataset.imikolov.test(
word_dict, N))

if avg_cost < 5.0:
trainer.save_params(save_path)
Copy link
Contributor

@jetfuel jetfuel May 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we use the save_params method?
The function is already implemented. Is it because we need the model to be saved? I thought the save_persistible will do the same thing

def __init__(self, program_func, optimizer, param_path=None, place=None):
def __init__(self,
train_func,
infer_func,
Copy link
Contributor

@jetfuel jetfuel May 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern seems new to me. Did we decide that the Trainer needs to take both train_func and infer_func. Sorry if I missed the conversation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because Trainer.save_inference_model need to know the inference program. infer_func is used to get the inference program.

# 3. run the default_startup program.

# 4. load params from param_path into scope
def __init__(self, param_path, place=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So Inferencer doesn't need to take the Infer_program anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it can load everything from the saved inference model

jetfuel
jetfuel previously approved these changes May 11, 2018
Copy link
Contributor

@jetfuel jetfuel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

daming-lu
daming-lu previously approved these changes May 11, 2018
Copy link
Contributor

@daming-lu daming-lu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tiny comments that can be fixed later

if not (bool(feeded_var_names) and all(
isinstance(name, basestring) for name in feeded_var_names)):
raise ValueError("'feed_var_names' should be a list of str.")
if len(feeded_var_names) > 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we throw error if feeded_var_names is not an array? Also I found the correct spell is fed_var_names, not feeded_. And it is being used in many places.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, feeded is wrong, can you help to correct it. I think feed_var_names is ok.

fluid.optimizer.SGD(learning_rate=0.001),
place=place)
trainer.train(
reader=train_reader, num_epochs=100, event_handler=event_handler)
reader=train_reader, num_epochs=1, event_handler=event_handler)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the default num_epochs is 1?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is for test, I can change it back to 100

@jacquesqiao jacquesqiao dismissed stale reviews from daming-lu and jetfuel via 41a9e36 May 11, 2018 05:54
@jetfuel jetfuel merged commit 2a971f3 into PaddlePaddle:develop May 11, 2018
@daming-lu daming-lu mentioned this pull request May 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

inferencer.infer
4 participants