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

capi预测出core,当样本是dense_vector_sequence类型时,请教正确的调用方式 #3969

Closed
fsfszongming256 opened this issue Sep 8, 2017 · 3 comments

Comments

@fsfszongming256
Copy link

fsfszongming256 commented Sep 8, 2017

问题:当输入样本是sequence,sequence中每一个元素是定长向量时,输入参数如何构造?sequence_start_pos如何构造? 看capi的样例代码没有找到摸索到答案

输入样本类型:
dense_vector_sequence(64)

相关代码:

        paddle_gradient_machine thread_local_machine;
        CHECK(paddle_gradient_machine_create_shared_param(_machine, _config_bin, _size, &thread_local_machine));
        gettimeofday(&tv_begin, NULL);
        paddle_arguments in_args = paddle_arguments_create_none();
        CHECK(paddle_arguments_resize(in_args, 1));
        //paddle_matrix sentence = paddle_matrix_create(count, 64, useGPU);
        paddle_matrix sentence = paddle_matrix_create(1, count * 64, useGPU);
        for (int i = 0; i < count; ++i) {
            CHECK(paddle_matrix_set_row(sentence, i, sep[i]));
        }    
        CHECK(paddle_arguments_set_value(in_args, 0, sentence));
        uint64_t h = 0;
        uint64_t w = 0;
        CHECK(paddle_matrix_get_shape(sentence, &h, &w));
        fprintf(stderr, "shape[%lu,%lu]\n", h, w);
        // paddle input matrix end

        int seq_pos_array[] = {0, count};
        paddle_ivector seq_pos = paddle_ivector_create(seq_pos_array, count, false, false);
        CHECK(paddle_arguments_set_sequence_start_pos(in_args, 0, 0, seq_pos));
        // paddle sequence pos info end

        paddle_arguments out_args = paddle_arguments_create_none();
        CHECK(paddle_gradient_machine_forward(thread_local_machine, in_args, out_args, false)); //predict end

出core日志:
I0908 11:01:07.981760 22947 Util.cpp:166] commandline:
I0908 11:01:07.983686 22947 GradientMachine.cpp:74] Loading parameters from ./model/param
shape[9,64]
F0908 11:01:07.984719 22947 Matrix.h:262] Check failed: startRow + numRows <= getHeight() (10 vs. 9)
*** Check failure stack trace: ***
@ 0x7f3a3041287d google::LogMessage::Fail()
@ 0x7f3a3041632c google::LogMessage::SendToLog()
@ 0x7f3a304123a3 google::LogMessage::Flush()
@ 0x7f3a3041783e google::LogMessageFatal::~LogMessageFatal()
@ 0x7f3a302ad461 paddle::Matrix::subMatrix()
@ 0x7f3a30297746 paddle::ContextProjectionForward<>()
@ 0x7f3a3029b642 paddle::ContextProjectionForwardFunc<>::calc()
@ 0x7f3a30157c0e paddle::ContextProjection::forward()
@ 0x7f3a301ed41e paddle::MixedLayer::forward()
@ 0x7f3a30289530 paddle::NeuralNetwork::forward()
@ 0x7f3a301404e6 paddle_gradient_machine_forward
@ 0x40321d main
@ 0x7f3a2f16dbd5 __libc_start_main
@ 0x403e99 (unknown)
@ (nil) (unknown)
Aborted (core dumped)

gdb信息:

#0  0x00007f3a2f1813f7 in raise () from /home/opt/gcc-4.8.2.bpkg-r2/gcc-4.8.2.bpkg-r2/lib64/libc-2.18.so
#1  0x00007f3a2f1827d8 in abort () from /home/opt/gcc-4.8.2.bpkg-r2/gcc-4.8.2.bpkg-r2/lib64/libc-2.18.so
#2  0x00007f3a3041b715 in google::DumpStackTraceAndExit() () from /home/img/zongming/rs/dump_embdding_capi/libpaddle_capi_shared.so
#3  0x00007f3a3041287d in google::LogMessage::Fail() () from /home/img/zongming/rs/dump_embdding_capi/libpaddle_capi_shared.so
#4  0x00007f3a3041632c in google::LogMessage::SendToLog() () from /home/img/zongming/rs/dump_embdding_capi/libpaddle_capi_shared.so
#5  0x00007f3a304123a3 in google::LogMessage::Flush() () from /home/img/zongming/rs/dump_embdding_capi/libpaddle_capi_shared.so
#6  0x00007f3a3041783e in google::LogMessageFatal::~LogMessageFatal() ()
   from /home/img/zongming/rs/dump_embdding_capi/libpaddle_capi_shared.so
#7  0x00007f3a302ad461 in paddle::Matrix::subMatrix (this=0x7fff8f1541e0, startRow=9, numRows=1)
    at /home/yuyang/BuildAgent3/work/d55918cf60d51073/paddle/math/Matrix.h:262
#8  0x00007f3a30297746 in paddle::ContextProjectionForward<(paddle::DeviceType)1> (out_mat=..., input_mat=..., weight_mat=..., 
    seq_vec=..., context_length=3, context_start=-1, begin_pad=1)
    at /home/yuyang/BuildAgent3/work/d55918cf60d51073/paddle/function/ContextProjectionOp.cpp:43
#9  0x00007f3a3029b642 in paddle::ContextProjectionForwardFunc<(paddle::DeviceType)1>::calc (this=0x4718f9b0, inputs=..., 
    outputs=...) at /home/yuyang/BuildAgent3/work/d55918cf60d51073/paddle/function/ContextProjectionOp.cpp:140
#10 0x00007f3a30157c0e in paddle::ContextProjection::forward (this=0x47190200)
    at /home/yuyang/BuildAgent3/work/d55918cf60d51073/paddle/gserver/layers/ContextProjection.cpp:130
#11 0x00007f3a301ed41e in forward (passType=paddle::enumeration_wrapper::PASS_TEST, out=0x4718b878, in=<optimized out>, 
    this=<optimized out>) at /home/yuyang/BuildAgent3/work/d55918cf60d51073/paddle/gserver/layers/Projection.h:69
#12 paddle::MixedLayer::forward (this=0x4718b6a0, passType=paddle::enumeration_wrapper::PASS_TEST)
    at /home/yuyang/BuildAgent3/work/d55918cf60d51073/paddle/gserver/layers/MixedLayer.cpp:126
#13 0x00007f3a30289530 in paddle::NeuralNetwork::forward (this=0x47181210, inArgs=..., outArgs=0x61ed98, 
    passType=paddle::enumeration_wrapper::PASS_TEST)
    at /home/yuyang/BuildAgent3/work/d55918cf60d51073/paddle/gserver/gradientmachines/NeuralNetwork.cpp:250
#14 0x00007f3a301404e6 in paddle_gradient_machine_forward (machine=<optimized out>, inArgs=<optimized out>, 
    outArgs=<optimized out>, isTrain=<optimized out>)
@QiJune
Copy link
Member

QiJune commented Sep 8, 2017

请检查一下输入的设置
例如,对于长度为3的dense_vector_sequence [ [1,2,3], [4,5,6], [7 8 9] ],那么就应该设置seq_pos_array为 [0, 3, 6, 9]

@fsfszongming256
Copy link
Author

fsfszongming256 commented Sep 10, 2017

第一个问题已解决,又出现新问题:
cpu版本 预测结果符合预期
gpu版本 出core

I0911 01:17:28.140764 22298 Util.cpp:166] commandline:  
I0911 01:17:28.142509 22298 GradientMachine.cpp:74] Loading parameters from ./model/param
F0911 01:17:28.143321 22298 Allocator.h:83] Check failed: ptr Fail to allocate GPU memory 3072 bytes
*** Check failure stack trace: ***
    @     0x7fe0d31c887d  google::LogMessage::Fail()
    @     0x7fe0d31cc32c  google::LogMessage::SendToLog()
    @     0x7fe0d31c83a3  google::LogMessage::Flush()
    @     0x7fe0d31cd83e  google::LogMessageFatal::~LogMessageFatal()
    @     0x7fe0d313820e  paddle::GpuAllocator::alloc()
    @     0x7fe0d31372e6  paddle::PoolAllocator::alloc()
    @     0x7fe0d31360af  paddle::GpuMemoryHandle::GpuMemoryHandle()
    @     0x7fe0d3117b81  paddle::GpuMatrix::GpuMatrix()
    @     0x7fe0d311842b  paddle::Matrix::create()
    @     0x7fe0d2ef7dd0  paddle_matrix_create
    @           0x40324e  main
    @     0x7fe0d1f23bd5  __libc_start_main
    @           0x404009  (unknown)
    @              (nil)  (unknown)
Aborted (core dumped)

机器上有gpu,python训练 和 预测都正常

@QiJune
Copy link
Member

QiJune commented Sep 11, 2017

如果需要GPU预测,那么capi需要使用GPU版本的paddle,请检查编译的版本是否正确

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants