EnforceNotMet: holder_ should not be null
模型在cpu模式下运行没有错误,在gpu模式下不加optimizer也能跑,但是加上optimizer minimize loss就报错。
log信息如下:
W0906 09:39:19.449245 93695 device_context.cc:259] Please NOTE: device: 0, CUDA Capability: 70, Driver API Version: 10.1, Runtime API Version: 9.2
W0906 09:39:19.453294 93695 device_context.cc:267] device: 0, cuDNN Version: 7.3.
Traceback (most recent call last):
File "/home/slurm/job/tmp/job-71826/knowledgebase/knowledgebase/tasks/open_language_learning/logician_paddle/interface/run_model.py", line 267, in
训练前有使用 startup_program进行初始化么?
有,执行了exe.run(framework.default_startup_program())。CPU模式没问题,GPU模式会碰到这个错误。改了几行源码,自己编译的release1.5版本的paddle。
改了哪些地方呢?
可能还是代码的问题,我再检查后再请教下。
发现去掉optimizer minimize loss能跑,估计还是反向传播过程中有问题。 改了下scatter_op.cu
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/fluid/operators/gather.cu.h"
#include "paddle/fluid/operators/gather_op.h"
#include "paddle/fluid/operators/scatter.cu.h"
#include "paddle/fluid/operators/scatter_op.h"
namespace paddle {
namespace operators {
template <typename T>
class ScatterOpCUDAKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext &ctx) const override {
PADDLE_ENFORCE(platform::is_gpu_place(ctx.GetPlace()),
"This kernel only runs on GPU device.");
auto *X = ctx.Input<Tensor>("X");
auto *Ids = ctx.Input<Tensor>("Ids");
auto *Updates = ctx.Input<Tensor>("Updates");
auto *Out = ctx.Output<Tensor>("Out");
bool overwrite = ctx.Attr<bool>("overwrite");
Out->ShareDataWith(*X);
const auto &index_type = Ids->type();
if (index_type == framework::proto::VarType::INT32) {
GPUScatterAssign<T, int>(ctx, *Updates, *Ids, Out, overwrite);
}
else{
GPUScatterAssign<T, int64_t>(ctx, *Updates, *Ids, Out, overwrite);
}
}
};
template <typename T>
class ScatterGradOpCUDAKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext &ctx) const override {
PADDLE_ENFORCE(platform::is_gpu_place(ctx.GetPlace()),
"This kernel only runs on GPU device.");
auto *dX = ctx.Output<Tensor>(framework::GradVarName("X"));
auto *dUpdates = ctx.Output<Tensor>(framework::GradVarName("Updates"));
auto *Ids = ctx.Input<Tensor>("Ids");
auto *dOut = ctx.Input<Tensor>(framework::GradVarName("Out"));
if (dX) {
// In place gradient: dX = dO
framework::TensorCopy(*dOut, ctx.GetPlace(), dX);
}
if (dUpdates) {
dUpdates->mutable_data<T>(ctx.GetPlace());
// Gradient by Gather: dUpdates = dO[Ids]
const auto &index_type = Ids->type();
if (index_type == framework::proto::VarType::INT32) {
GPUGather<T, int>(ctx.device_context(), *dOut, *Ids, dUpdates);
}
else{
GPUGather<T, int64_t>(ctx.device_context(), *dOut, *Ids, dUpdates);
}
}
}
};
} // namespace operators
} // namespace paddle
namespace ops = paddle::operators;
REGISTER_OP_CUDA_KERNEL(scatter, ops::ScatterOpCUDAKernel<float>);
REGISTER_OP_CUDA_KERNEL(scatter_grad, ops::ScatterGradOpCUDAKernel<float>);
把grad op改回去看看还出问题么? 目前没有看出问题
不改的话会报scatter的index类型错误。用pip安装的官方paddle的运行错误信息如下:
Traceback (most recent call last):
File "interface/run_model.py", line 269, in <module>
train()
File "interface/run_model.py", line 246, in train
return_numpy=False)
File "/home/yujinxing/pyenv/v1/gcc53/python3.6/lib/python3.6/site-packages/paddle/fluid/executor.py", line 651, in run
use_program_cache=use_program_cache)
File "/home/yujinxing/pyenv/v1/gcc53/python3.6/lib/python3.6/site-packages/paddle/fluid/executor.py", line 749, in _run
exe.run(program.desc, scope, 0, True, True, fetch_var_name)
paddle.fluid.core_avx.EnforceNotMet: Invoke operator scatter error.
C++ Callstacks:
Tensor holds the wrong type, it holds int64_t, but desires to be int at [/paddle/paddle/fluid/framework/tensor_impl.h:30]
PaddlePaddle Call Stacks:
0 0x7f88ca692760p void paddle::platform::EnforceNotMet::Init<char const*>(char const*, char const*, int) + 352
1 0x7f88ca692ad9p paddle::platform::EnforceNotMet::EnforceNotMet(std::__exception_ptr::exception_ptr, char const*, int) + 137
2 0x7f88ca69d469p int const* paddle::framework::Tensor::data<int>() const + 233
3 0x7f88cad9207ap void paddle::operators::GPUScatterAssign<float, int>(paddle::framework::ExecutionContext const&, paddle::framework::Tensor const&, paddle::framework::Tensor const&, paddle::framework::Tensor*, bool) + 282
4 0x7f88cb39aed5p paddle::operators::ScatterOpCUDAKernel<float>::Compute(paddle::framework::ExecutionContext const&) const + 565
5 0x7f88cb39b133p std::_Function_handler<void (paddle::framework::ExecutionContext const&), paddle::framework::OpKernelRegistrarFunctor<paddle::platform::CUDAPlace, false, 0ul, paddle::operators::ScatterOpCUDAKernel<float> >::operator()(char const*, char const*, int) const::{lambda(paddle::framework::ExecutionContext const&)#1}>::_M_invoke(std::_Any_data const&, paddle::framework::ExecutionContext const&) + 35
6 0x7f88cc5f8e07p paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&, paddle::framework::RuntimeContext*) const + 375
7 0x7f88cc5f91e1p paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&) const + 529
8 0x7f88cc5f67dcp paddle::framework::OperatorBase::Run(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&) + 332
9 0x7f88ca81d55ep paddle::framework::Executor::RunPreparedContext(paddle::framework::ExecutorPrepareContext*, paddle::framework::Scope*, bool, bool, bool) + 382
10 0x7f88cc093847p paddle::operators::WhileOp::RunImpl(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&) const + 935
11 0x7f88cc5f67dcp paddle::framework::OperatorBase::Run(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&) + 332
12 0x7f88ca81d55ep paddle::framework::Executor::RunPreparedContext(paddle::framework::ExecutorPrepareContext*, paddle::framework::Scope*, bool, bool, bool) + 382
13 0x7f88ca8205ffp paddle::framework::Executor::Run(paddle::framework::ProgramDesc const&, paddle::framework::Scope*, int, bool, bool, std::vector<std::string, std::allocator<std::string> > const&, bool) + 143
14 0x7f88ca683dedp
15 0x7f88ca6c5076p
16 0x7f8936344a02p _PyCFunction_FastCallDict + 386
17 0x7f89363d5cb8p
18 0x7f89363d8607p _PyEval_EvalFrameDefault + 8023
19 0x7f89363d5b54p
20 0x7f89363d5e07p
21 0x7f89363d93d9p _PyEval_EvalFrameDefault + 11561
22 0x7f89363d5b54p
23 0x7f89363d5e07p
24 0x7f89363d93d9p _PyEval_EvalFrameDefault + 11561
25 0x7f89363d5b54p
26 0x7f89363d5e07p
27 0x7f89363d8607p _PyEval_EvalFrameDefault + 8023
28 0x7f89363d5b54p
29 0x7f89363d612fp PyEval_EvalCodeEx + 47
30 0x7f89363d615bp PyEval_EvalCode + 27
31 0x7f89364095b2p PyRun_FileExFlags + 178
32 0x7f8936409726p PyRun_SimpleFileExFlags + 230
33 0x7f8936425d02p Py_Main + 3730
34 0x400ae2p main + 370
35 0x38bfc21b45p __libc_start_main + 245
36 0x400b9dp
看报错是你input输入的类型不对? 你input定义成int64的可以么
用的就是int64的,但是scatter op bp默认用的int, 上面的代码改动就是让它都支持。目前就是有的op实现只支持一种类型,比如embedding只支持int64。把scatter op的cpu代码改成int, int64都支持,整个代码用cpu能跑。
另外,试过cast成不同的类型,以适应不同的op, 也会报错。
感觉这个错误信息和scatter没有关系,更新了下完整的log, 请帮忙再看看。
嗯, 发一下把
为了描述更清楚,重新弄了个issue, 请看下https://github.com/PaddlePaddle/Paddle/issues/19679