Skip to content

Commit fd1875b

Browse files
authored
Merge pull request #12903 from PaddlePaddle/revert-12759
Revert "Add Python Callstacks when Op::Run error (#12759)"
2 parents d82453f + 1f27027 commit fd1875b

File tree

7 files changed

+16
-65
lines changed

7 files changed

+16
-65
lines changed

paddle/fluid/framework/op_proto_maker.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,6 @@ void OpProtoAndCheckerMaker::operator()(proto::OpProto* proto,
129129
"Optimized for variable")
130130
.SetDefault({});
131131

132-
AddAttr<std::vector<std::string>>(OpCreationCallstackAttrName(),
133-
"Callstack for Op Creatation.")
134-
.SetDefault({});
135-
136132
Validate();
137133
}
138134

paddle/fluid/framework/op_proto_maker.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class OpProtoAndCheckerMaker {
3939
public:
4040
static const char *OpRoleAttrName() { return "op_role"; }
4141
static const char *OpRoleVarAttrName() { return "op_role_var"; }
42-
static const char *OpCreationCallstackAttrName() { return "op_callstack"; }
4342

4443
void operator()(proto::OpProto *proto, OpAttrChecker *attr_checker);
4544

paddle/fluid/framework/operator.cc

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@ distributed under the License is distributed on an "AS IS" BASIS,
1111
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License. */
14-
#include "paddle/fluid/framework/operator.h"
14+
#include <gflags/gflags.h>
15+
#include <glog/logging.h>
16+
1517
#include <algorithm>
16-
#include <sstream>
17-
#include <string>
18-
#include <vector>
19-
#include "gflags/gflags.h"
20-
#include "glog/logging.h"
18+
2119
#include "paddle/fluid/framework/data_transform.h"
2220
#include "paddle/fluid/framework/executor.h"
2321
#include "paddle/fluid/framework/lod_tensor.h"
24-
#include "paddle/fluid/framework/op_proto_maker.h"
22+
#include "paddle/fluid/framework/operator.h"
2523
#include "paddle/fluid/framework/shape_inference.h"
2624
#include "paddle/fluid/framework/var_type.h"
2725
#include "paddle/fluid/platform/profiler.h"
@@ -129,48 +127,19 @@ static LoD GetLoD(const Scope& scope, const std::string& name) {
129127
}
130128

131129
void OperatorBase::Run(const Scope& scope, const platform::Place& place) {
132-
try {
133-
if (VLOG_IS_ON(4)) {
134-
VLOG(4) << place << " " << DebugStringEx(&scope);
135-
}
136-
if (platform::is_gpu_place(place)) {
130+
VLOG(4) << place << " " << DebugStringEx(&scope);
131+
if (platform::is_gpu_place(place)) {
137132
#ifndef PADDLE_WITH_CUDA
138-
PADDLE_THROW("Cannot run operator on place %s", place);
133+
PADDLE_THROW("Cannot run operator on place %s", place);
139134
#else
140-
auto dev_id = boost::get<platform::CUDAPlace>(place).device;
141-
platform::SetDeviceId(dev_id);
135+
auto dev_id = boost::get<platform::CUDAPlace>(place).device;
136+
platform::SetDeviceId(dev_id);
142137
#endif
143-
}
144-
platform::DeviceContextPool& pool = platform::DeviceContextPool::Instance();
145-
platform::RecordEvent record_event(Type(), pool.Get(place));
146-
RunImpl(scope, place);
147-
if (VLOG_IS_ON(3)) {
148-
VLOG(3) << place << " " << DebugStringEx(&scope);
149-
}
150-
} catch (platform::EnforceNotMet exception) {
151-
if (Attrs().count("sub_block") != 0) {
152-
throw exception;
153-
}
154-
155-
auto& callstack = Attr<std::vector<std::string>>(
156-
OpProtoAndCheckerMaker::OpCreationCallstackAttrName());
157-
158-
if (callstack.empty()) {
159-
throw exception;
160-
}
161-
std::ostringstream sout;
162-
sout << "Invoke operator " << Type() << " error.\n";
163-
sout << "Python Callstacks: \n";
164-
for (auto& line : callstack) {
165-
sout << line;
166-
}
167-
sout << "C++ Callstacks: \n";
168-
sout << exception.err_str_;
169-
exception.err_str_ = sout.str();
170-
throw exception;
171-
} catch (...) {
172-
std::rethrow_exception(std::current_exception());
173138
}
139+
platform::DeviceContextPool& pool = platform::DeviceContextPool::Instance();
140+
platform::RecordEvent record_event(Type(), pool.Get(place));
141+
RunImpl(scope, place);
142+
VLOG(3) << place << " " << DebugStringEx(&scope);
174143
}
175144

176145
bool OperatorBase::HasInputs(const std::string& name) const {
@@ -198,7 +167,7 @@ const std::vector<std::string>& OperatorBase::Inputs(
198167
}
199168

200169
bool OperatorBase::HasOutputs(const std::string& name) const {
201-
if (outputs_.end() != outputs_.find(name)) {
170+
if (outputs_.find(name) != outputs_.end()) {
202171
return true;
203172
} else {
204173
return false;

paddle/fluid/operators/top_k_op.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class TopkOp : public framework::OperatorWithKernel {
3030
"Output(Indices) of TopkOp should not be null.");
3131

3232
auto input_dims = ctx->GetInputDim("X");
33-
PADDLE_ENFORCE_EQ(input_dims.size(), 2,
34-
"Rank of TopK op's input must be 2.");
3533
const int k = static_cast<int>(ctx->Attrs().Get<int>("k"));
3634

3735
PADDLE_ENFORCE_GE(k, 1, "k must >= 1");

paddle/fluid/pybind/const_value.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ void BindConstValue(pybind11::module* m) {
4343
op_proto_and_checker_maker.def(
4444
"kOpRoleVarAttrName",
4545
framework::OpProtoAndCheckerMaker::OpRoleVarAttrName);
46-
op_proto_and_checker_maker.def(
47-
"kOpCreationCallstackAttrName",
48-
framework::OpProtoAndCheckerMaker::OpCreationCallstackAttrName);
4946
}
5047

5148
} // namespace pybind

python/paddle/fluid/framework.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import contextlib
1919
import re
2020
import six
21-
import traceback
2221

2322
import numpy as np
2423

@@ -506,10 +505,6 @@ def __init__(self,
506505
if role_var_name in op_attrs and len(op_attrs[role_var_name]) == 0:
507506
del op_attrs[role_var_name]
508507

509-
callstack_var_name = op_maker.kOpCreationCallstackAttrName()
510-
op_attrs[callstack_var_name] = list(
511-
reversed(traceback.format_stack()))[1:]
512-
513508
if len(self.desc.type()) != 0:
514509
return
515510
if type is None:

python/paddle/fluid/tests/unittests/test_operator_desc.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ def test_op_desc_creation(self):
6767
self.assertEqual(mul_op.output("Out"), ["mul.out"])
6868
self.assertEqual(
6969
set(mul_op.attr_names),
70-
set([
71-
"x_num_col_dims", "y_num_col_dims", "op_role", "op_role_var",
72-
"op_callstack"
73-
]))
70+
set(["x_num_col_dims", "y_num_col_dims", "op_role", "op_role_var"]))
7471
self.assertEqual(mul_op.has_attr("x_num_col_dims"), True)
7572
self.assertEqual(mul_op.attr_type("x_num_col_dims"), core.AttrType.INT)
7673
self.assertEqual(mul_op.attr("x_num_col_dims"), 1)

0 commit comments

Comments
 (0)