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

Skip graph export for newly added TF MLIR functions if backend_compiler is not specified. #66567

Merged
merged 1 commit into from Apr 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 30 additions & 28 deletions tensorflow/compiler/mlir/tfrt/transforms/mlrt/import_model.cc
Expand Up @@ -59,37 +59,39 @@ absl::StatusOr<mlrt::bc::Buffer> ConvertTfMlirToBytecode(
mlrt::bc::Buffer bytecode_buffer;
TF_RETURN_IF_ERROR(ConvertTfMlirToRuntimeExecutable(
options, module,
[&bytecode_buffer, &fallback_state, &model_context, module_with_op_keys](
mlir::PassManager& pm, mlir::ModuleOp module,
const TfrtPipelineOptions& options) {
if (auto* flib_def = model_context.function_library_definition()) {
// Copy the module before exporting as exporting to graph will
// transform the MLIR to TFG dialect.
mlir::OwningOpRef<mlir::ModuleOp> copy(module.clone());
TF_RETURN_IF_ERROR(
ExportFunctionDefs(*copy, [flib_def](FunctionDef function_def) {
VLOG(1) << absl::StrCat(
"Exporting MLIR function as function_def: ",
// clang-tidy off
function_def.DebugString()
// clang-tidy on
);
[&bytecode_buffer, &fallback_state, &model_context,
backend_compiler = options.backend_compiler,
module_with_op_keys](mlir::PassManager& pm, mlir::ModuleOp module,
const TfrtPipelineOptions& options) {
if (backend_compiler) {
if (auto* flib_def = model_context.function_library_definition()) {
// Copy the module before exporting as exporting to graph will
// transform the MLIR to TFG dialect.
mlir::OwningOpRef<mlir::ModuleOp> copy(module.clone());
TF_RETURN_IF_ERROR(
ExportFunctionDefs(*copy, [flib_def](FunctionDef function_def) {
VLOG(1) << absl::StrCat(
"Exporting MLIR function as function_def: ",
// NOLINTNEXTLINE
function_def.DebugString());

// The TF MLIR compiler may change the function name. Then we
// need to retrieve the original name from the
// _original_func_name attribute.
auto iter = function_def.attr().find("_original_func_name");
if (iter != function_def.attr().end()) {
function_def.mutable_signature()->set_name(iter->second.s());
}
// The TF MLIR compiler may change the function name. Then we
// need to retrieve the original name from the
// _original_func_name attribute.
auto iter = function_def.attr().find("_original_func_name");
if (iter != function_def.attr().end()) {
function_def.mutable_signature()->set_name(
iter->second.s());
}

const auto& name = function_def.signature().name();
if (flib_def->Contains(name)) {
TF_RETURN_IF_ERROR(flib_def->RemoveFunction(name));
}
const auto& name = function_def.signature().name();
if (flib_def->Contains(name)) {
TF_RETURN_IF_ERROR(flib_def->RemoveFunction(name));
}

return flib_def->AddFunctionDef(function_def);
}));
return flib_def->AddFunctionDef(function_def);
}));
}
}

mlir::StatusScopedDiagnosticHandler diag_handler(module.getContext());
Expand Down