未验证 提交 857cd9f8 编写于 作者: P Pei Yang 提交者: GitHub

make config option DisableGlogInfo() able to mute all inference logs (#21544)

make config option DisableGlogInfo() able to mute all inference logs
上级 87a8caa8
...@@ -12,7 +12,9 @@ ...@@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include <memory>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#include "paddle/fluid/framework/feed_fetch_method.h" #include "paddle/fluid/framework/feed_fetch_method.h"
...@@ -100,9 +102,8 @@ void NaiveExecutor::CreateOps(const ProgramDesc &desc, int block_id, ...@@ -100,9 +102,8 @@ void NaiveExecutor::CreateOps(const ProgramDesc &desc, int block_id,
for (const auto &op_desc : desc.Block(block_id).AllOps()) { for (const auto &op_desc : desc.Block(block_id).AllOps()) {
if (!with_feed_fetch_ops && if (!with_feed_fetch_ops &&
(op_desc->Type() == "feed" || op_desc->Type() == "fetch")) { (op_desc->Type() == "feed" || op_desc->Type() == "fetch")) {
string::PrettyLogEndl(string::Style::detail(), "--- skip [%s], %s -> %s", LOG(INFO) << "--- skip [" << op_desc->Input("X")[0] << "], "
op_desc->Input("X")[0], op_desc->Type(), << op_desc->Type() << " -> " << op_desc->Output("Out")[0];
op_desc->Output("Out")[0]);
continue; continue;
} }
ops_.emplace_back(OpRegistry::CreateOp(*op_desc)); ops_.emplace_back(OpRegistry::CreateOp(*op_desc));
......
...@@ -29,8 +29,11 @@ void Analyzer::Run(Argument *argument) { RunAnalysis(argument); } ...@@ -29,8 +29,11 @@ void Analyzer::Run(Argument *argument) { RunAnalysis(argument); }
void Analyzer::RunAnalysis(Argument *argument) { void Analyzer::RunAnalysis(Argument *argument) {
PADDLE_ENFORCE(argument->analysis_passes_valid(), PADDLE_ENFORCE(argument->analysis_passes_valid(),
"analsis_passes is not valid in the argument."); "analsis_passes is not valid in the argument.");
const bool disable_logs = argument->disable_logs();
for (auto &pass : argument->analysis_passes()) { for (auto &pass : argument->analysis_passes()) {
string::PrettyLogH1("--- Running analysis [%s]", pass); if (!disable_logs) {
string::PrettyLogH1("--- Running analysis [%s]", pass);
}
if (!argument->enable_analysis_optim() && pass == "ir_analysis_pass") if (!argument->enable_analysis_optim() && pass == "ir_analysis_pass")
continue; continue;
......
...@@ -29,6 +29,7 @@ using namespace framework; // NOLINT ...@@ -29,6 +29,7 @@ using namespace framework; // NOLINT
TEST(Analyzer, analysis_without_tensorrt) { TEST(Analyzer, analysis_without_tensorrt) {
Argument argument; Argument argument;
argument.SetDisableLogs(false);
argument.SetModelDir(FLAGS_inference_model_dir); argument.SetModelDir(FLAGS_inference_model_dir);
argument.SetEnableAnalysisOptim(false); argument.SetEnableAnalysisOptim(false);
argument.SetUseGPU(false); argument.SetUseGPU(false);
...@@ -41,6 +42,7 @@ TEST(Analyzer, analysis_without_tensorrt) { ...@@ -41,6 +42,7 @@ TEST(Analyzer, analysis_without_tensorrt) {
TEST(Analyzer, analysis_with_tensorrt) { TEST(Analyzer, analysis_with_tensorrt) {
Argument argument; Argument argument;
argument.SetDisableLogs(false);
argument.SetEnableAnalysisOptim(false); argument.SetEnableAnalysisOptim(false);
argument.SetTensorRtMaxBatchSize(3); argument.SetTensorRtMaxBatchSize(3);
argument.SetTensorRtWorkspaceSize(1 << 20); argument.SetTensorRtWorkspaceSize(1 << 20);
......
...@@ -149,6 +149,9 @@ struct Argument { ...@@ -149,6 +149,9 @@ struct Argument {
DECL_ARGUMENT_FIELD(analysis_passes, AnalysisPasses, DECL_ARGUMENT_FIELD(analysis_passes, AnalysisPasses,
std::vector<std::string>); std::vector<std::string>);
// whether to mute all logs in inference.
DECL_ARGUMENT_FIELD(disable_logs, DisableLogs, bool);
// Pass a set of op types to enable its mkldnn kernel // Pass a set of op types to enable its mkldnn kernel
DECL_ARGUMENT_FIELD(mkldnn_enabled_op_types, MKLDNNEnabledOpTypes, DECL_ARGUMENT_FIELD(mkldnn_enabled_op_types, MKLDNNEnabledOpTypes,
std::unordered_set<std::string>); std::unordered_set<std::string>);
......
...@@ -147,6 +147,10 @@ void IRPassManager::CreatePasses(Argument *argument, ...@@ -147,6 +147,10 @@ void IRPassManager::CreatePasses(Argument *argument,
pass->Set("auto_config_layout", pass->Set("auto_config_layout",
new bool(argument->anakin_auto_config_layout())); new bool(argument->anakin_auto_config_layout()));
} }
disable_logs_ = argument->disable_logs();
if (pass_name == "fc_fuse_pass") {
pass->Set("use_gpu", new bool(argument->use_gpu()));
}
pre_pass = pass_name; pre_pass = pass_name;
...@@ -161,7 +165,7 @@ std::unique_ptr<Graph> IRPassManager::Apply(std::unique_ptr<Graph> graph) { ...@@ -161,7 +165,7 @@ std::unique_ptr<Graph> IRPassManager::Apply(std::unique_ptr<Graph> graph) {
PADDLE_ENFORCE(graph.get()); PADDLE_ENFORCE(graph.get());
// Apply all the passes // Apply all the passes
for (const auto &pass : passes_) { for (const auto &pass : passes_) {
if (pass->Type() != "graph_viz_pass") { if (pass->Type() != "graph_viz_pass" && !disable_logs_) {
PrettyLogEndl(Style::H2(), "--- Running IR pass [%s]", pass->Type()); PrettyLogEndl(Style::H2(), "--- Running IR pass [%s]", pass->Type());
} }
graph.reset(pass->Apply(graph.release())); graph.reset(pass->Apply(graph.release()));
......
...@@ -56,6 +56,7 @@ class IRPassManager final { ...@@ -56,6 +56,7 @@ class IRPassManager final {
std::unique_ptr<Graph> graph_; std::unique_ptr<Graph> graph_;
std::vector<std::unique_ptr<framework::ir::Pass>> passes_; std::vector<std::unique_ptr<framework::ir::Pass>> passes_;
bool disable_logs_{false};
}; };
} // namespace analysis } // namespace analysis
......
...@@ -108,8 +108,7 @@ void TensorRtSubgraphPass::CreateTensorRTOp( ...@@ -108,8 +108,7 @@ void TensorRtSubgraphPass::CreateTensorRTOp(
framework::BlockDesc block_desc(nullptr, &block_proto); framework::BlockDesc block_desc(nullptr, &block_proto);
block_desc.Proto()->set_parent_idx(-1); block_desc.Proto()->set_parent_idx(-1);
block_desc.Proto()->set_idx(0); block_desc.Proto()->set_idx(0);
string::PrettyLogDetail("--- detect a sub-graph with %d nodes", LOG(INFO) << "--- detect a sub-graph with " << subgraph.size() << " nodes";
subgraph.size());
for (auto *node : subgraph) { for (auto *node : subgraph) {
auto *new_block_op = new_block->AppendOp(); auto *new_block_op = new_block->AppendOp();
......
...@@ -451,6 +451,7 @@ void AnalysisPredictor::PrepareArgument() { ...@@ -451,6 +451,7 @@ void AnalysisPredictor::PrepareArgument() {
passes.clear(); passes.clear();
LOG(INFO) << "ir_optim is turned off, no IR pass will be executed"; LOG(INFO) << "ir_optim is turned off, no IR pass will be executed";
} }
argument_.SetDisableLogs(config_.glog_info_disabled());
argument_.SetIrAnalysisPasses(passes); argument_.SetIrAnalysisPasses(passes);
argument_.SetAnalysisPasses(config_.pass_builder()->AnalysisPasses()); argument_.SetAnalysisPasses(config_.pass_builder()->AnalysisPasses());
argument_.SetScopeNotOwned(scope_.get()); argument_.SetScopeNotOwned(scope_.get());
...@@ -507,10 +508,10 @@ std::unique_ptr<PaddlePredictor> CreatePaddlePredictor< ...@@ -507,10 +508,10 @@ std::unique_ptr<PaddlePredictor> CreatePaddlePredictor<
framework::InitGflags(flags); framework::InitGflags(flags);
} }
} }
framework::InitGLOG("");
if (config.glog_info_disabled()) { if (config.glog_info_disabled()) {
FLAGS_logtostderr = 1; FLAGS_logtostderr = 1;
FLAGS_minloglevel = google::WARNING; FLAGS_minloglevel = 2; // GLOG_ERROR
LOG(WARNING) << " - GLOG's LOG(INFO) is disabled.";
} }
std::unique_ptr<PaddlePredictor> predictor(new AnalysisPredictor(config)); std::unique_ptr<PaddlePredictor> predictor(new AnalysisPredictor(config));
......
...@@ -46,6 +46,7 @@ namespace framework { ...@@ -46,6 +46,7 @@ namespace framework {
#endif #endif
std::once_flag gflags_init_flag; std::once_flag gflags_init_flag;
std::once_flag glog_init_flag;
std::once_flag p2p_init_flag; std::once_flag p2p_init_flag;
void InitGflags(std::vector<std::string> argv) { void InitGflags(std::vector<std::string> argv) {
...@@ -213,13 +214,15 @@ void SignalHandle(const char *data, int size) { ...@@ -213,13 +214,15 @@ void SignalHandle(const char *data, int size) {
#endif #endif
void InitGLOG(const std::string &prog_name) { void InitGLOG(const std::string &prog_name) {
// glog will not hold the ARGV[0] inside. std::call_once(glog_init_flag, [&]() {
// Use strdup to alloc a new string. // glog will not hold the ARGV[0] inside.
google::InitGoogleLogging(strdup(prog_name.c_str())); // Use strdup to alloc a new string.
google::InitGoogleLogging(strdup(prog_name.c_str()));
#ifndef _WIN32 #ifndef _WIN32
google::InstallFailureSignalHandler(); google::InstallFailureSignalHandler();
google::InstallFailureWriter(&SignalHandle); google::InstallFailureWriter(&SignalHandle);
#endif #endif
});
} }
} // namespace framework } // namespace framework
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册