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

[PIR] translate newir in python #58390

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions paddle/fluid/framework/new_executor/standalone_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ StandaloneExecutor::StandaloneExecutor(const platform::Place& place,
const std::string& job_type = job->Type();
std::shared_ptr<ProgramDesc> program = nullptr;
std::shared_ptr<::pir::Program> ir_program = nullptr;
if (FLAGS_enable_pir_api) {
if (FLAGS_enable_pir_api || FLAGS_enable_new_ir_in_executor) {
ir_program = plan_.IrProgram(job_type);
} else {
program = std::make_shared<ProgramDesc>(*(plan_.Program(job_type)));
Expand All @@ -80,10 +80,6 @@ StandaloneExecutor::StandaloneExecutor(const platform::Place& place,
// TODO(phlrain) we only support cpu for now
if (FLAGS_enable_new_ir_in_executor) {
std::shared_ptr<::pir::Program> base_program = ir_program;
if (!FLAGS_enable_pir_api) {
VLOG(6) << "begin to translate" << std::endl;
base_program = paddle::TranslateLegacyProgramToProgram(*program);
}
auto block = base_program->block();
for (auto it = block->begin(); it != block->end(); ++it) {
if ((*it)->isa<paddle::dialect::FetchOp>()) {
Expand Down
3 changes: 2 additions & 1 deletion paddle/fluid/ir_adaptor/translator/translate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ std::unique_ptr<Program> TranslateLegacyProgramToProgram(
auto program = std::make_unique<Program>(ctx);
translator::ProgramTranslator program_translator(&legacy_program,
program.get());
VLOG(6) << "begin to translate";
program_translator.Translate();

VLOG(6) << "translate done";
return program;
}

Expand Down
11 changes: 9 additions & 2 deletions python/paddle/base/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import numpy as np

from ..pir import OpResult
from ..pir import OpResult, translate_to_new_ir
from . import compiler, core, framework, get_flags, set_flags, unique_name
from .data_feeder import convert_dtype
from .framework import (
Expand Down Expand Up @@ -1006,7 +1006,14 @@ def _get_program_and_executor(self, cached_data):
)
else:
default_job = core.Job("default")
type_to_program = {"default": new_program.desc}
if get_flags("FLAGS_enable_new_ir_in_executor")[
'FLAGS_enable_new_ir_in_executor'
]:
type_to_program = {
"default": translate_to_new_ir(new_program.desc)
}
else:
type_to_program = {"default": new_program.desc}
plan = core.Plan([default_job], type_to_program)

new_exe = _StandaloneExecutor(place, plan, scope)
Expand Down