Skip to content

Commit

Permalink
[Paddle Inference] clean unused code (PaddlePaddle#48392)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanlehome committed Dec 14, 2022
1 parent 0063af1 commit eaec6e1
Show file tree
Hide file tree
Showing 22 changed files with 42 additions and 193 deletions.
1 change: 1 addition & 0 deletions paddle/fluid/framework/naive_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,6 @@ void NaiveExecutor::ResetTrtOps(int num) {
}
#endif
}

} // namespace framework
} // namespace paddle
3 changes: 1 addition & 2 deletions paddle/fluid/inference/analysis/analyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ void Analyzer::RunAnalysis(Argument *argument) {
if (!disable_logs) {
string::PrettyLogH1("--- Running analysis [%s]", pass);
}
if (!argument->enable_analysis_optim() && pass == "ir_analysis_pass")
continue;
if (!argument->enable_ir_optim() && pass == "ir_analysis_pass") continue;

auto *ptr = PassRegistry::Global().Retreive(pass);
PADDLE_ENFORCE_NOT_NULL(ptr,
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/inference/analysis/analyzer_tester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TEST(Analyzer, analysis_without_tensorrt) {
Argument argument;
argument.SetDisableLogs(false);
argument.SetModelDir(FLAGS_inference_model_dir);
argument.SetEnableAnalysisOptim(false);
argument.SetEnableIrOptim(false);
argument.SetUseGPU(false);
argument.SetAnalysisPasses({"ir_graph_build_pass",
"ir_analysis_pass",
Expand All @@ -44,7 +44,7 @@ TEST(Analyzer, analysis_without_tensorrt) {
TEST(Analyzer, analysis_with_tensorrt) {
Argument argument;
argument.SetDisableLogs(false);
argument.SetEnableAnalysisOptim(false);
argument.SetEnableIrOptim(false);
argument.SetTensorRtMaxBatchSize(3);
argument.SetTensorRtWorkspaceSize(1 << 20);
argument.SetModelDir(FLAGS_inference_model_dir);
Expand Down
4 changes: 1 addition & 3 deletions paddle/fluid/inference/analysis/argument.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ namespace paddle {
namespace inference {
namespace analysis {

using framework::ir::Graph;

#ifdef PADDLE_WITH_MKLDNN
using VarQuantScale =
std::unordered_map<std::string, std::pair<bool, framework::LoDTensor>>;
Expand Down Expand Up @@ -148,7 +146,7 @@ struct Argument {
DECL_ARGUMENT_FIELD(model_params_path, ModelParamsPath, std::string);
DECL_ARGUMENT_FIELD(model_from_memory, ModelFromMemory, bool);
DECL_ARGUMENT_FIELD(optim_cache_dir, OptimCacheDir, std::string);
DECL_ARGUMENT_FIELD(enable_analysis_optim, EnableAnalysisOptim, bool);
DECL_ARGUMENT_FIELD(enable_ir_optim, EnableIrOptim, bool);

// For JITLayer
DECL_ARGUMENT_FIELD(skip_load_params, SkipLoadParams, bool);
Expand Down
19 changes: 0 additions & 19 deletions paddle/fluid/inference/analysis/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,6 @@ T &GetFromScope(const framework::Scope &scope, const std::string &name) {
return *var->GetMutable<T>();
}

static framework::proto::ProgramDesc LoadProgramDesc(
const std::string &model_path) {
std::ifstream fin(model_path, std::ios::in | std::ios::binary);
PADDLE_ENFORCE_EQ(
fin.is_open(),
true,
platform::errors::NotFound(
"Cannot open file %s, please confirm whether the file exists",
model_path));
fin.seekg(0, std::ios::end);
std::string buffer(fin.tellg(), ' ');
fin.seekg(0, std::ios::beg);
fin.read(&buffer[0], buffer.size());
fin.close();
framework::proto::ProgramDesc program_desc;
program_desc.ParseFromString(buffer);
return program_desc;
}

static bool FileExists(const std::string &filepath) {
std::ifstream file(filepath);
bool exists = file.is_open();
Expand Down
9 changes: 0 additions & 9 deletions paddle/fluid/inference/analysis/ir_pass_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ using string::PrettyLogEndl;
using string::Style;

IRPassManager::IRPassManager(Argument *argument) {
ARGUMENT_CHECK_FIELD(argument, main_program);
graph_ = std::unique_ptr<Graph>(new Graph(argument->main_program()));
if (argument->Has("scope")) {
auto *scope_ptr = argument->scope_ptr();
PADDLE_ENFORCE_NOT_NULL(scope_ptr,
platform::errors::PreconditionNotMet(
"The scope ptr should not be nullptr."));
graph_->SetNotOwned(framework::ir::kParamScopeAttr, scope_ptr);
}
disable_logs_ = argument->disable_logs();

ARGUMENT_CHECK_FIELD(argument, ir_analysis_passes);
Expand Down
14 changes: 1 addition & 13 deletions paddle/fluid/inference/analysis/passes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@ cc_library(
inference_op_replace_pass
SRCS inference_op_replace_pass.cc
DEPS analysis_pass graph_to_program_pass)
if(WITH_TESTING)
cc_library(
ir_graph_clean_pass
SRCS ir_graph_clean_pass.cc
DEPS analysis_pass gtest)
else()
cc_library(
ir_graph_clean_pass
SRCS ir_graph_clean_pass.cc
DEPS analysis_pass)
endif()

cc_library(
analysis_passes
Expand All @@ -52,8 +41,7 @@ cc_library(
memory_optim_pass
convert_to_mixed_precision
inference_op_replace_pass
ir_graph_to_program_pass
ir_graph_clean_pass)
ir_graph_to_program_pass)

set(analysis_deps
${analysis_deps} analysis_passes subgraph_detector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
#include "paddle/fluid/framework/program_desc.h"
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/framework/var_desc.h"
#include "paddle/fluid/inference/analysis/argument.h"
#include "paddle/fluid/inference/analysis/passes/ir_graph_clean_pass.h"
#include "paddle/fluid/inference/io.h"
#include "paddle/phi/common/bfloat16.h"
#include "paddle/phi/common/data_type.h"
Expand Down Expand Up @@ -406,14 +404,21 @@ void ConvertToMixedPrecisionPass::LoadAndPrepare() {
main_graph_ = std::unique_ptr<framework::ir::Graph>(
new framework::ir::Graph(*program_desc_));

// Remove all control var
IrInferCleanGraphPass pass;
Argument arg;
arg.SetMainGraphNotOwned(main_graph_.get());
pass.Run(&arg);

vars_appear_multi_in_one_block_.resize(program_desc_->Size());
FindVarsInMultiBlock();
for (size_t i = 0; i < main_graph_->SubGraphsSize(); ++i) {
auto* graph = main_graph_->GetSubGraph(i);
graphes_.push_back(graph);

for (auto* node : graph->Nodes()) {
if (!node->IsVar()) continue;
if (!name2node_.count(node->Name())) {
name2node_[node->Name()] = node;
}
}
}

ProcessCircleCases();
}

void ConvertToMixedPrecisionPass::FindVarsInMultiBlock() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void InferenceOpReplacePass::RunImpl(Argument* argument) {
}

std::string InferenceOpReplacePass::repr() const {
return "inference-op-replace-pass";
return "inference_op_replace_pass";
}

} // namespace analysis
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/inference/analysis/passes/ir_analysis_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void IrAnalysisPass::CollectFusionStatis(Argument* argument) {
framework::ir::kFuseStatisAttr));
}

std::string IrAnalysisPass::repr() const { return "ir-analysis-pass"; }
std::string IrAnalysisPass::repr() const { return "ir_analysis_pass"; }

} // namespace analysis
} // namespace inference
Expand Down
5 changes: 3 additions & 2 deletions paddle/fluid/inference/analysis/passes/ir_graph_build_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ void IrGraphBuildPass::RunImpl(Argument *argument) {
"set."));
}

auto graph = std::unique_ptr<Graph>(new Graph(argument->main_program()));
auto graph = std::unique_ptr<framework::ir::Graph>(
new framework::ir::Graph(argument->main_program()));
argument->SetMainGraph(graph.release());
auto *scope_ptr = argument->scope_ptr();
PADDLE_ENFORCE_NOT_NULL(scope_ptr,
Expand Down Expand Up @@ -125,7 +126,7 @@ std::unique_ptr<framework::ProgramDesc> IrGraphBuildPass::LoadModel(
}
}

std::string IrGraphBuildPass::repr() const { return "ir-graph-build-pass"; }
std::string IrGraphBuildPass::repr() const { return "ir_graph_build_pass"; }

} // namespace analysis
} // namespace inference
Expand Down
49 changes: 0 additions & 49 deletions paddle/fluid/inference/analysis/passes/ir_graph_clean_pass.cc

This file was deleted.

37 changes: 0 additions & 37 deletions paddle/fluid/inference/analysis/passes/ir_graph_clean_pass.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void IrGraphToProgramPass::RunImpl(Argument *argument) {
new int(argument->memory_optim_sort_kind()));
}

std::unique_ptr<Graph> graph(argument->main_graph_ptr());
std::unique_ptr<framework::ir::Graph> graph(argument->main_graph_ptr());

// Direct using ProgramDesc desc(argument->main_program()) may cause
// incomplete copies of information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class IrGraphToProgramPass : public AnalysisPass {
public:
void RunImpl(Argument *argument) override;

std::string repr() const override { return "ir-graph-to-param-pass"; }
std::string repr() const override { return "ir_graph_to_param_pass"; }
};

} // namespace analysis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void IrParamsSyncAmongDevicesPass::RunImpl(Argument *argument) {
}

std::string IrParamsSyncAmongDevicesPass::repr() const {
return "ir-params-sync-among-devices-pass";
return "ir_params_sync_among_devices_pass";
}

} // namespace analysis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ void UpdateOpDescsByReuse(
}
}

std::string MemoryOptimizePass::repr() const { return "memory optimize pass"; }
std::string MemoryOptimizePass::repr() const { return "memory_optimize_pass"; }

void MemoryOptimizePass::RunImpl(Argument* argument) {
// Memory optimization.
Expand Down
3 changes: 0 additions & 3 deletions paddle/fluid/inference/analysis/passes/passes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "paddle/fluid/inference/analysis/passes/inference_op_replace_pass.h"
#include "paddle/fluid/inference/analysis/passes/ir_analysis_pass.h"
#include "paddle/fluid/inference/analysis/passes/ir_graph_build_pass.h"
#include "paddle/fluid/inference/analysis/passes/ir_graph_clean_pass.h"
#include "paddle/fluid/inference/analysis/passes/ir_graph_to_program_pass.h"
#include "paddle/fluid/inference/analysis/passes/ir_params_sync_among_devices_pass.h"
#include "paddle/fluid/inference/analysis/passes/memory_optimize_pass.h"
Expand All @@ -34,8 +33,6 @@ PassRegistry::PassRegistry() {
std::unique_ptr<AnalysisPass>(new IrAnalysisPass));
passes_.emplace("ir_graph_build_pass",
std::unique_ptr<AnalysisPass>(new IrGraphBuildPass));
passes_.emplace("ir_graph_clean_pass",
std::unique_ptr<AnalysisPass>(new IrInferCleanGraphPass));
passes_.emplace("memory_optimize_pass",
std::unique_ptr<AnalysisPass>(new MemoryOptimizePass));
passes_.emplace(
Expand Down
9 changes: 0 additions & 9 deletions paddle/fluid/inference/api/analysis_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -758,13 +758,7 @@ void AnalysisConfig::Update() {
((use_custom_device() ^ pass_builder_->use_custom_device()))) {
if (use_gpu()) {
pass_builder_.reset(new GpuPassStrategy);

if (use_tensorrt_) {
// Append after the Affine_channel_conv_fuse pass.
pass_builder()->InsertPass(3, "tensorrt_subgraph_pass");
}
} else if (use_ipu()) {
VLOG(1) << "IpuPassStrategy has been used for new.";
pass_builder_.reset(new IpuPassStrategy);
} else if (use_xpu()) {
PADDLE_ENFORCE_EQ(
Expand Down Expand Up @@ -964,9 +958,6 @@ void AnalysisConfig::Update() {
"but did not have the option -DWITH_CUSTOM_DEVICE compiled."));
#endif
}
if (ir_debug_) {
pass_builder()->TurnOnDebug();
}
}

std::string AnalysisConfig::SerializeInfoCache() {
Expand Down
Loading

0 comments on commit eaec6e1

Please sign in to comment.