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

Enhance execution error info #18482

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
20 changes: 19 additions & 1 deletion paddle/fluid/platform/init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include <string.h> // for strdup
#include <algorithm>
#include <fstream>
#include <iostream>
#include <memory>
#include <set>
#include <stdexcept>
Expand All @@ -30,7 +32,6 @@ limitations under the License. */
#include "paddle/fluid/platform/init.h"
#include "paddle/fluid/platform/place.h"
#include "paddle/fluid/string/piece.h"

#if defined(PADDLE_WITH_DGC)
#include "dgc/dgc.h"
#endif
Expand Down Expand Up @@ -202,10 +203,27 @@ void InitDevices(bool init_p2p, const std::vector<int> devices) {
#endif
}

#ifndef _WIN32
static void SignalHandle(const char *data, int size) {
auto file_path = string::Sprintf("/tmp/paddle.%d.dump_info", ::getpid());
try {
std::ofstream dump_info;
dump_info.open(file_path, std::ios::app);
dump_info << std::string(data, size);
dump_info.close();
} catch (...) {
}
}
#endif

void InitGLOG(const std::string &prog_name) {
// glog will not hold the ARGV[0] inside.
// Use strdup to alloc a new string.
google::InitGoogleLogging(strdup(prog_name.c_str()));
#ifndef _WIN32
google::InstallFailureSignalHandler();
google::InstallFailureWriter(&SignalHandle);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use InstallFailureWriter to catch the dump info.

#endif
}

#if defined(PADDLE_WITH_DGC)
Expand Down
26 changes: 22 additions & 4 deletions python/paddle/fluid/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import logging
import os
import multiprocessing
import sys
import numpy as np
from .wrapped_decorator import signature_safe_contextmanager
import six
Expand Down Expand Up @@ -626,6 +627,23 @@ def run(self,

list(numpy.array): fetch result according to fetch_list.
"""
try:
return self._run_impl(
program=program,
feed=feed,
fetch_list=fetch_list,
feed_var_name=feed_var_name,
fetch_var_name=fetch_var_name,
scope=scope,
return_numpy=return_numpy,
use_program_cache=use_program_cache)
except Exception as e:
if not isinstance(e, core.EOFException):
print("An exception was thrown!\n {}".format(str(e)))
raise e

def _run_impl(self, program, feed, fetch_list, feed_var_name,
fetch_var_name, scope, return_numpy, use_program_cache):

if self._closed:
raise RuntimeError("Attempted to use a closed Executor")
Expand All @@ -638,7 +656,7 @@ def run(self,
compiled = isinstance(program, compiler.CompiledProgram)
# For backward compatibility, run directly.
if not compiled:
return self._run(
return self._run_program(
program,
self._default_executor,
feed=feed,
Expand Down Expand Up @@ -671,7 +689,7 @@ def run(self,
# TODO(panyx0718): executor should be able to run graph.
assert program._program, "CompiledProgram is compiled from graph, can only run with_data_parallel."
# use_program_cache is not valid with CompiledProgram
return self._run(
return self._run_program(
program._program,
self._default_executor,
feed=feed,
Expand All @@ -682,8 +700,8 @@ def run(self,
return_numpy=return_numpy,
use_program_cache=False)

def _run(self, program, exe, feed, fetch_list, feed_var_name,
fetch_var_name, scope, return_numpy, use_program_cache):
def _run_program(self, program, exe, feed, fetch_list, feed_var_name,
fetch_var_name, scope, return_numpy, use_program_cache):

if feed is None:
feed = {}
Expand Down