diff --git a/python/paddle/fluid/inferencer.py b/python/paddle/fluid/inferencer.py index 56c008d1af70f4b5f6169ebe5174b08fcf8bc722..8c6dbd3b5ae5d8bcd8d0a136457c20003fd23ded 100644 --- a/python/paddle/fluid/inferencer.py +++ b/python/paddle/fluid/inferencer.py @@ -17,6 +17,7 @@ import core import executor import framework import io +import parallel_executor import unique_name from trainer import check_and_get_place @@ -24,7 +25,7 @@ __all__ = ['Inferencer', ] class Inferencer(object): - def __init__(self, infer_func, param_path, place=None): + def __init__(self, infer_func, param_path, place=None, parallel=False): """ :param infer_func: a function that will return predict Variable :param param_path: the path where the inference model is saved by fluid.io.save_params @@ -32,13 +33,20 @@ class Inferencer(object): """ self.param_path = param_path self.scope = core.Scope() + self.parallel = parallel + self.place = check_and_get_place(place) self.inference_program = framework.Program() with framework.program_guard(self.inference_program): with unique_name.guard(): self.predict_var = infer_func() - self.exe = executor.Executor(check_and_get_place(place)) + if parallel: + self.exe = parallel_executor.ParallelExecutor( + use_cuda=isinstance(self.place, core.CUDAPlace), + loss_name=self.predict_var.name) + else: + self.exe = executor.Executor(self.place) with executor.scope_guard(self.scope): # load params from param_path into scope io.load_params(self.exe, param_path, self.inference_program) diff --git a/python/paddle/fluid/trainer.py b/python/paddle/fluid/trainer.py index d158d586321833fdf046e4e061bfa8460b9a31b5..f4292208c949ea271a7a65267d0a71208e74e75f 100644 --- a/python/paddle/fluid/trainer.py +++ b/python/paddle/fluid/trainer.py @@ -12,18 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. +import contextlib import os + import core -import framework -import executor + import data_feeder -import contextlib +import executor +import framework import io -import unique_name -import parallel_executor - # optimizer is same as the parameter of Trainer.__init__. Rename it to opt_module import optimizer as opt_module +import parallel_executor from transpiler import distribute_transpiler __all__ = [